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%
6.7 KB · 188 lines cpp
Raw Blame History
1//-------------------------------------------------------------------------------------------------------------------------------------------------------------2//3// Metal/MTL4ArgumentTable.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 "MTLGPUAddress.hpp"26#include "MTLHeaderBridge.hpp"27#include "MTLPrivate.hpp"28#include "MTLTypes.hpp"2930namespace MTL31{32class Device;33}3435namespace MTL436{37class ArgumentTableDescriptor : public NS::Copying<ArgumentTableDescriptor>38{39public:40    static ArgumentTableDescriptor* alloc();4142    ArgumentTableDescriptor*        init();43    bool                            initializeBindings() const;4445    NS::String*                     label() const;4647    NS::UInteger                    maxBufferBindCount() const;4849    NS::UInteger                    maxSamplerStateBindCount() const;5051    NS::UInteger                    maxTextureBindCount() const;5253    void                            setInitializeBindings(bool initializeBindings);5455    void                            setLabel(const NS::String* label);5657    void                            setMaxBufferBindCount(NS::UInteger maxBufferBindCount);5859    void                            setMaxSamplerStateBindCount(NS::UInteger maxSamplerStateBindCount);6061    void                            setMaxTextureBindCount(NS::UInteger maxTextureBindCount);6263    void                            setSupportAttributeStrides(bool supportAttributeStrides);64    bool                            supportAttributeStrides() const;65};66class ArgumentTable : public NS::Referencing<ArgumentTable>67{68public:69    MTL::Device* device() const;7071    NS::String*  label() const;7273    void         setAddress(MTL::GPUAddress gpuAddress, NS::UInteger bindingIndex);74    void         setAddress(MTL::GPUAddress gpuAddress, NS::UInteger stride, NS::UInteger bindingIndex);7576    void         setResource(MTL::ResourceID resourceID, NS::UInteger bindingIndex);7778    void         setSamplerState(MTL::ResourceID resourceID, NS::UInteger bindingIndex);7980    void         setTexture(MTL::ResourceID resourceID, NS::UInteger bindingIndex);81};8283}84_MTL_INLINE MTL4::ArgumentTableDescriptor* MTL4::ArgumentTableDescriptor::alloc()85{86    return NS::Object::alloc<MTL4::ArgumentTableDescriptor>(_MTL_PRIVATE_CLS(MTL4ArgumentTableDescriptor));87}8889_MTL_INLINE MTL4::ArgumentTableDescriptor* MTL4::ArgumentTableDescriptor::init()90{91    return NS::Object::init<MTL4::ArgumentTableDescriptor>();92}9394_MTL_INLINE bool MTL4::ArgumentTableDescriptor::initializeBindings() const95{96    return Object::sendMessage<bool>(this, _MTL_PRIVATE_SEL(initializeBindings));97}9899_MTL_INLINE NS::String* MTL4::ArgumentTableDescriptor::label() const100{101    return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(label));102}103104_MTL_INLINE NS::UInteger MTL4::ArgumentTableDescriptor::maxBufferBindCount() const105{106    return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(maxBufferBindCount));107}108109_MTL_INLINE NS::UInteger MTL4::ArgumentTableDescriptor::maxSamplerStateBindCount() const110{111    return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(maxSamplerStateBindCount));112}113114_MTL_INLINE NS::UInteger MTL4::ArgumentTableDescriptor::maxTextureBindCount() const115{116    return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(maxTextureBindCount));117}118119_MTL_INLINE void MTL4::ArgumentTableDescriptor::setInitializeBindings(bool initializeBindings)120{121    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setInitializeBindings_), initializeBindings);122}123124_MTL_INLINE void MTL4::ArgumentTableDescriptor::setLabel(const NS::String* label)125{126    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setLabel_), label);127}128129_MTL_INLINE void MTL4::ArgumentTableDescriptor::setMaxBufferBindCount(NS::UInteger maxBufferBindCount)130{131    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setMaxBufferBindCount_), maxBufferBindCount);132}133134_MTL_INLINE void MTL4::ArgumentTableDescriptor::setMaxSamplerStateBindCount(NS::UInteger maxSamplerStateBindCount)135{136    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setMaxSamplerStateBindCount_), maxSamplerStateBindCount);137}138139_MTL_INLINE void MTL4::ArgumentTableDescriptor::setMaxTextureBindCount(NS::UInteger maxTextureBindCount)140{141    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setMaxTextureBindCount_), maxTextureBindCount);142}143144_MTL_INLINE void MTL4::ArgumentTableDescriptor::setSupportAttributeStrides(bool supportAttributeStrides)145{146    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setSupportAttributeStrides_), supportAttributeStrides);147}148149_MTL_INLINE bool MTL4::ArgumentTableDescriptor::supportAttributeStrides() const150{151    return Object::sendMessageSafe<bool>(this, _MTL_PRIVATE_SEL(supportAttributeStrides));152}153154_MTL_INLINE MTL::Device* MTL4::ArgumentTable::device() const155{156    return Object::sendMessage<MTL::Device*>(this, _MTL_PRIVATE_SEL(device));157}158159_MTL_INLINE NS::String* MTL4::ArgumentTable::label() const160{161    return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(label));162}163164_MTL_INLINE void MTL4::ArgumentTable::setAddress(MTL::GPUAddress gpuAddress, NS::UInteger bindingIndex)165{166    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setAddress_atIndex_), gpuAddress, bindingIndex);167}168169_MTL_INLINE void MTL4::ArgumentTable::setAddress(MTL::GPUAddress gpuAddress, NS::UInteger stride, NS::UInteger bindingIndex)170{171    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setAddress_attributeStride_atIndex_), gpuAddress, stride, bindingIndex);172}173174_MTL_INLINE void MTL4::ArgumentTable::setResource(MTL::ResourceID resourceID, NS::UInteger bindingIndex)175{176    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setResource_atBufferIndex_), resourceID, bindingIndex);177}178179_MTL_INLINE void MTL4::ArgumentTable::setSamplerState(MTL::ResourceID resourceID, NS::UInteger bindingIndex)180{181    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setSamplerState_atIndex_), resourceID, bindingIndex);182}183184_MTL_INLINE void MTL4::ArgumentTable::setTexture(MTL::ResourceID resourceID, NS::UInteger bindingIndex)185{186    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setTexture_atIndex_), resourceID, bindingIndex);187}188