SPB Git

spb/forge Public MIT

Forge — LLM training from scratch in pure C++20 + Metal on Apple Silicon.

C++ 61.2% C 23% Python 7.6% TeX 7.2% CMake 1.1%
3.6 KB · 105 lines cpp
Raw Blame History
1//-------------------------------------------------------------------------------------------------------------------------------------------------------------2//3// Metal/MTLPipeline.hpp4//5// Copyright 2020-2025 Apple Inc.6//7// Licensed under the Apache License, Version 2.0 (the "License");8// you may not use this file except in compliance with the License.9// You may obtain a copy of the License at10//11//     http://www.apache.org/licenses/LICENSE-2.012//13// Unless required by applicable law or agreed to in writing, software14// distributed under the License is distributed on an "AS IS" BASIS,15// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.16// See the License for the specific language governing permissions and17// limitations under the License.18//19//-------------------------------------------------------------------------------------------------------------------------------------------------------------2021#pragma once2223#include "../Foundation/Foundation.hpp"24#include "MTLDefines.hpp"25#include "MTLHeaderBridge.hpp"26#include "MTLPrivate.hpp"2728namespace MTL29{30class PipelineBufferDescriptor;31class PipelineBufferDescriptorArray;32_MTL_ENUM(NS::UInteger, Mutability) {33    MutabilityDefault = 0,34    MutabilityMutable = 1,35    MutabilityImmutable = 2,36};3738_MTL_ENUM(NS::Integer, ShaderValidation) {39    ShaderValidationDefault = 0,40    ShaderValidationEnabled = 1,41    ShaderValidationDisabled = 2,42};4344class PipelineBufferDescriptor : public NS::Copying<PipelineBufferDescriptor>45{46public:47    static PipelineBufferDescriptor* alloc();4849    PipelineBufferDescriptor*        init();5051    Mutability                       mutability() const;52    void                             setMutability(MTL::Mutability mutability);53};54class PipelineBufferDescriptorArray : public NS::Referencing<PipelineBufferDescriptorArray>55{56public:57    static PipelineBufferDescriptorArray* alloc();5859    PipelineBufferDescriptorArray*        init();6061    PipelineBufferDescriptor*             object(NS::UInteger bufferIndex);62    void                                  setObject(const MTL::PipelineBufferDescriptor* buffer, NS::UInteger bufferIndex);63};6465}66_MTL_INLINE MTL::PipelineBufferDescriptor* MTL::PipelineBufferDescriptor::alloc()67{68    return NS::Object::alloc<MTL::PipelineBufferDescriptor>(_MTL_PRIVATE_CLS(MTLPipelineBufferDescriptor));69}7071_MTL_INLINE MTL::PipelineBufferDescriptor* MTL::PipelineBufferDescriptor::init()72{73    return NS::Object::init<MTL::PipelineBufferDescriptor>();74}7576_MTL_INLINE MTL::Mutability MTL::PipelineBufferDescriptor::mutability() const77{78    return Object::sendMessage<MTL::Mutability>(this, _MTL_PRIVATE_SEL(mutability));79}8081_MTL_INLINE void MTL::PipelineBufferDescriptor::setMutability(MTL::Mutability mutability)82{83    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setMutability_), mutability);84}8586_MTL_INLINE MTL::PipelineBufferDescriptorArray* MTL::PipelineBufferDescriptorArray::alloc()87{88    return NS::Object::alloc<MTL::PipelineBufferDescriptorArray>(_MTL_PRIVATE_CLS(MTLPipelineBufferDescriptorArray));89}9091_MTL_INLINE MTL::PipelineBufferDescriptorArray* MTL::PipelineBufferDescriptorArray::init()92{93    return NS::Object::init<MTL::PipelineBufferDescriptorArray>();94}9596_MTL_INLINE MTL::PipelineBufferDescriptor* MTL::PipelineBufferDescriptorArray::object(NS::UInteger bufferIndex)97{98    return Object::sendMessage<MTL::PipelineBufferDescriptor*>(this, _MTL_PRIVATE_SEL(objectAtIndexedSubscript_), bufferIndex);99}100101_MTL_INLINE void MTL::PipelineBufferDescriptorArray::setObject(const MTL::PipelineBufferDescriptor* buffer, NS::UInteger bufferIndex)102{103    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setObject_atIndexedSubscript_), buffer, bufferIndex);104}105