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%
5.2 KB · 154 lines cpp
Raw Blame History
1//-------------------------------------------------------------------------------------------------------------------------------------------------------------2//3// Metal/MTLFunctionDescriptor.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 FunctionConstantValues;31class FunctionDescriptor;32class IntersectionFunctionDescriptor;3334_MTL_OPTIONS(NS::UInteger, FunctionOptions) {35    FunctionOptionNone = 0,36    FunctionOptionCompileToBinary = 1,37    FunctionOptionStoreFunctionInMetalPipelinesScript = 1 << 1,38    FunctionOptionStoreFunctionInMetalScript = 1 << 1,39    FunctionOptionFailOnBinaryArchiveMiss = 1 << 2,40    FunctionOptionPipelineIndependent = 1 << 3,41};4243class FunctionDescriptor : public NS::Copying<FunctionDescriptor>44{45public:46    static FunctionDescriptor* alloc();4748    NS::Array*                 binaryArchives() const;4950    FunctionConstantValues*    constantValues() const;5152    static FunctionDescriptor* functionDescriptor();5354    FunctionDescriptor*        init();5556    NS::String*                name() const;5758    FunctionOptions            options() const;5960    void                       setBinaryArchives(const NS::Array* binaryArchives);6162    void                       setConstantValues(const MTL::FunctionConstantValues* constantValues);6364    void                       setName(const NS::String* name);6566    void                       setOptions(MTL::FunctionOptions options);6768    void                       setSpecializedName(const NS::String* specializedName);69    NS::String*                specializedName() const;70};71class IntersectionFunctionDescriptor : public NS::Copying<IntersectionFunctionDescriptor, FunctionDescriptor>72{73public:74    static IntersectionFunctionDescriptor* alloc();7576    IntersectionFunctionDescriptor*        init();77};7879}80_MTL_INLINE MTL::FunctionDescriptor* MTL::FunctionDescriptor::alloc()81{82    return NS::Object::alloc<MTL::FunctionDescriptor>(_MTL_PRIVATE_CLS(MTLFunctionDescriptor));83}8485_MTL_INLINE NS::Array* MTL::FunctionDescriptor::binaryArchives() const86{87    return Object::sendMessage<NS::Array*>(this, _MTL_PRIVATE_SEL(binaryArchives));88}8990_MTL_INLINE MTL::FunctionConstantValues* MTL::FunctionDescriptor::constantValues() const91{92    return Object::sendMessage<MTL::FunctionConstantValues*>(this, _MTL_PRIVATE_SEL(constantValues));93}9495_MTL_INLINE MTL::FunctionDescriptor* MTL::FunctionDescriptor::functionDescriptor()96{97    return Object::sendMessage<MTL::FunctionDescriptor*>(_MTL_PRIVATE_CLS(MTLFunctionDescriptor), _MTL_PRIVATE_SEL(functionDescriptor));98}99100_MTL_INLINE MTL::FunctionDescriptor* MTL::FunctionDescriptor::init()101{102    return NS::Object::init<MTL::FunctionDescriptor>();103}104105_MTL_INLINE NS::String* MTL::FunctionDescriptor::name() const106{107    return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(name));108}109110_MTL_INLINE MTL::FunctionOptions MTL::FunctionDescriptor::options() const111{112    return Object::sendMessage<MTL::FunctionOptions>(this, _MTL_PRIVATE_SEL(options));113}114115_MTL_INLINE void MTL::FunctionDescriptor::setBinaryArchives(const NS::Array* binaryArchives)116{117    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setBinaryArchives_), binaryArchives);118}119120_MTL_INLINE void MTL::FunctionDescriptor::setConstantValues(const MTL::FunctionConstantValues* constantValues)121{122    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setConstantValues_), constantValues);123}124125_MTL_INLINE void MTL::FunctionDescriptor::setName(const NS::String* name)126{127    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setName_), name);128}129130_MTL_INLINE void MTL::FunctionDescriptor::setOptions(MTL::FunctionOptions options)131{132    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setOptions_), options);133}134135_MTL_INLINE void MTL::FunctionDescriptor::setSpecializedName(const NS::String* specializedName)136{137    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setSpecializedName_), specializedName);138}139140_MTL_INLINE NS::String* MTL::FunctionDescriptor::specializedName() const141{142    return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(specializedName));143}144145_MTL_INLINE MTL::IntersectionFunctionDescriptor* MTL::IntersectionFunctionDescriptor::alloc()146{147    return NS::Object::alloc<MTL::IntersectionFunctionDescriptor>(_MTL_PRIVATE_CLS(MTLIntersectionFunctionDescriptor));148}149150_MTL_INLINE MTL::IntersectionFunctionDescriptor* MTL::IntersectionFunctionDescriptor::init()151{152    return NS::Object::init<MTL::IntersectionFunctionDescriptor>();153}154