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%
1//-------------------------------------------------------------------------------------------------------------------------------------------------------------2//3// Metal/MTLLibrary.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 "MTLDataType.hpp"25#include "MTLDefines.hpp"26#include "MTLFunctionDescriptor.hpp"27#include "MTLHeaderBridge.hpp"28#include "MTLPrivate.hpp"29#include "MTLTypes.hpp"3031namespace MTL32{33class Argument;34class ArgumentEncoder;35class Attribute;36class CompileOptions;37class Device;38class Function;39class FunctionConstant;40class FunctionConstantValues;41class FunctionDescriptor;42class FunctionReflection;43class IntersectionFunctionDescriptor;44class VertexAttribute;45_MTL_ENUM(NS::UInteger, PatchType) {46 PatchTypeNone = 0,47 PatchTypeTriangle = 1,48 PatchTypeQuad = 2,49};5051_MTL_ENUM(NS::UInteger, FunctionType) {52 FunctionTypeVertex = 1,53 FunctionTypeFragment = 2,54 FunctionTypeKernel = 3,55 FunctionTypeVisible = 5,56 FunctionTypeIntersection = 6,57 FunctionTypeMesh = 7,58 FunctionTypeObject = 8,59};6061_MTL_ENUM(NS::UInteger, LanguageVersion) {62 LanguageVersion1_0 = 65536,63 LanguageVersion1_1 = 65537,64 LanguageVersion1_2 = 65538,65 LanguageVersion2_0 = 131072,66 LanguageVersion2_1 = 131073,67 LanguageVersion2_2 = 131074,68 LanguageVersion2_3 = 131075,69 LanguageVersion2_4 = 131076,70 LanguageVersion3_0 = 196608,71 LanguageVersion3_1 = 196609,72 LanguageVersion3_2 = 196610,73 LanguageVersion4_0 = 262144,74 LanguageVersion4_1 = 262145,75};7677_MTL_ENUM(NS::Integer, LibraryType) {78 LibraryTypeExecutable = 0,79 LibraryTypeDynamic = 1,80};8182_MTL_ENUM(NS::Integer, LibraryOptimizationLevel) {83 LibraryOptimizationLevelDefault = 0,84 LibraryOptimizationLevelSize = 1,85};8687_MTL_ENUM(NS::Integer, CompileSymbolVisibility) {88 CompileSymbolVisibilityDefault = 0,89 CompileSymbolVisibilityHidden = 1,90};9192_MTL_ENUM(NS::Integer, MathMode) {93 MathModeSafe = 0,94 MathModeRelaxed = 1,95 MathModeFast = 2,96};9798_MTL_ENUM(NS::Integer, MathFloatingPointFunctions) {99 MathFloatingPointFunctionsFast = 0,100 MathFloatingPointFunctionsPrecise = 1,101};102103_MTL_ENUM(NS::Integer, FloatingPointConversionRoundingMode) {104 FloatingPointConversionRoundingModeToNearestEven = 0,105 FloatingPointConversionRoundingModeTowardZero = 1,106};107108_MTL_ENUM(NS::UInteger, LibraryError) {109 LibraryErrorUnsupported = 1,110 LibraryErrorInternal = 2,111 LibraryErrorCompileFailure = 3,112 LibraryErrorCompileWarning = 4,113 LibraryErrorFunctionNotFound = 5,114 LibraryErrorFileNotFound = 6,115};116117using AutoreleasedArgument = MTL::Argument*;118using FunctionCompletionHandlerFunction = std::function<void(MTL::Function* pFunction, NS::Error* pError)>;119120class VertexAttribute : public NS::Referencing<VertexAttribute>121{122public:123 [[deprecated("please use isActive instead")]]124 bool active() const;125126 static VertexAttribute* alloc();127128 NS::UInteger attributeIndex() const;129130 DataType attributeType() const;131132 VertexAttribute* init();133134 bool isActive() const;135136 bool isPatchControlPointData() const;137138 bool isPatchData() const;139140 NS::String* name() const;141142 [[deprecated("please use isPatchControlPointData instead")]]143 bool patchControlPointData() const;144145 [[deprecated("please use isPatchData instead")]]146 bool patchData() const;147};148class Attribute : public NS::Referencing<Attribute>149{150public:151 [[deprecated("please use isActive instead")]]152 bool active() const;153154 static Attribute* alloc();155156 NS::UInteger attributeIndex() const;157158 DataType attributeType() const;159160 Attribute* init();161162 bool isActive() const;163164 bool isPatchControlPointData() const;165166 bool isPatchData() const;167168 NS::String* name() const;169170 [[deprecated("please use isPatchControlPointData instead")]]171 bool patchControlPointData() const;172173 [[deprecated("please use isPatchData instead")]]174 bool patchData() const;175};176class FunctionConstant : public NS::Referencing<FunctionConstant>177{178public:179 static FunctionConstant* alloc();180181 NS::UInteger index() const;182183 FunctionConstant* init();184185 NS::String* name() const;186187 bool required() const;188189 DataType type() const;190};191class Function : public NS::Referencing<Function>192{193public:194 Device* device() const;195196 NS::Dictionary* functionConstantsDictionary() const;197198 FunctionType functionType() const;199200 NS::String* label() const;201202 NS::String* name() const;203204 ArgumentEncoder* newArgumentEncoder(NS::UInteger bufferIndex);205 ArgumentEncoder* newArgumentEncoder(NS::UInteger bufferIndex, const MTL::AutoreleasedArgument* reflection);206207 FunctionOptions options() const;208209 NS::Integer patchControlPointCount() const;210211 PatchType patchType() const;212213 void setLabel(const NS::String* label);214215 NS::Array* stageInputAttributes() const;216217 NS::Array* vertexAttributes() const;218};219class CompileOptions : public NS::Copying<CompileOptions>220{221public:222 static CompileOptions* alloc();223224 bool allowReferencingUndefinedSymbols() const;225226 CompileSymbolVisibility compileSymbolVisibility() const;227228 bool enableLogging() const;229230 bool fastMathEnabled() const;231232 FloatingPointConversionRoundingMode floatingPointConversionRoundingMode() const;233234 CompileOptions* init();235236 NS::String* installName() const;237238 LanguageVersion languageVersion() const;239240 NS::Array* libraries() const;241242 LibraryType libraryType() const;243244 MathFloatingPointFunctions mathFloatingPointFunctions() const;245246 MathMode mathMode() const;247248 NS::UInteger maxTotalThreadsPerThreadgroup() const;249250 LibraryOptimizationLevel optimizationLevel() const;251252 NS::Dictionary* preprocessorMacros() const;253254 bool preserveInvariance() const;255256 Size requiredThreadsPerThreadgroup() const;257258 void setAllowReferencingUndefinedSymbols(bool allowReferencingUndefinedSymbols);259260 void setCompileSymbolVisibility(MTL::CompileSymbolVisibility compileSymbolVisibility);261262 void setEnableLogging(bool enableLogging);263264 void setFastMathEnabled(bool fastMathEnabled);265266 void setFloatingPointConversionRoundingMode(MTL::FloatingPointConversionRoundingMode floatingPointConversionRoundingMode);267268 void setInstallName(const NS::String* installName);269270 void setLanguageVersion(MTL::LanguageVersion languageVersion);271272 void setLibraries(const NS::Array* libraries);273274 void setLibraryType(MTL::LibraryType libraryType);275276 void setMathFloatingPointFunctions(MTL::MathFloatingPointFunctions mathFloatingPointFunctions);277278 void setMathMode(MTL::MathMode mathMode);279280 void setMaxTotalThreadsPerThreadgroup(NS::UInteger maxTotalThreadsPerThreadgroup);281282 void setOptimizationLevel(MTL::LibraryOptimizationLevel optimizationLevel);283284 void setPreprocessorMacros(const NS::Dictionary* preprocessorMacros);285286 void setPreserveInvariance(bool preserveInvariance);287288 void setRequiredThreadsPerThreadgroup(MTL::Size requiredThreadsPerThreadgroup);289};290class FunctionReflection : public NS::Referencing<FunctionReflection>291{292public:293 static FunctionReflection* alloc();294295 NS::Array* bindings() const;296297 FunctionReflection* init();298299 NS::String* userAnnotation() const;300};301class Library : public NS::Referencing<Library>302{303public:304 Device* device() const;305306 NS::Array* functionNames() const;307308 NS::String* installName() const;309310 NS::String* label() const;311312 Function* newFunction(const NS::String* functionName);313 Function* newFunction(const NS::String* name, const MTL::FunctionConstantValues* constantValues, NS::Error** error);314 void newFunction(const NS::String* name, const MTL::FunctionConstantValues* constantValues, void (^completionHandler)(MTL::Function*, NS::Error*));315 void newFunction(const MTL::FunctionDescriptor* descriptor, void (^completionHandler)(MTL::Function*, NS::Error*));316 Function* newFunction(const MTL::FunctionDescriptor* descriptor, NS::Error** error);317 void newFunction(const NS::String* pFunctionName, const MTL::FunctionConstantValues* pConstantValues, const MTL::FunctionCompletionHandlerFunction& completionHandler);318 void newFunction(const MTL::FunctionDescriptor* pDescriptor, const MTL::FunctionCompletionHandlerFunction& completionHandler);319320 void newIntersectionFunction(const MTL::IntersectionFunctionDescriptor* descriptor, void (^completionHandler)(MTL::Function*, NS::Error*));321 Function* newIntersectionFunction(const MTL::IntersectionFunctionDescriptor* descriptor, NS::Error** error);322 void newIntersectionFunction(const MTL::IntersectionFunctionDescriptor* pDescriptor, const MTL::FunctionCompletionHandlerFunction& completionHandler);323324 FunctionReflection* reflectionForFunction(const NS::String* functionName);325326 void setLabel(const NS::String* label);327328 LibraryType type() const;329};330331}332_MTL_INLINE bool MTL::VertexAttribute::active() const333{334 return Object::sendMessage<bool>(this, _MTL_PRIVATE_SEL(isActive));335}336337_MTL_INLINE MTL::VertexAttribute* MTL::VertexAttribute::alloc()338{339 return NS::Object::alloc<MTL::VertexAttribute>(_MTL_PRIVATE_CLS(MTLVertexAttribute));340}341342_MTL_INLINE NS::UInteger MTL::VertexAttribute::attributeIndex() const343{344 return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(attributeIndex));345}346347_MTL_INLINE MTL::DataType MTL::VertexAttribute::attributeType() const348{349 return Object::sendMessage<MTL::DataType>(this, _MTL_PRIVATE_SEL(attributeType));350}351352_MTL_INLINE MTL::VertexAttribute* MTL::VertexAttribute::init()353{354 return NS::Object::init<MTL::VertexAttribute>();355}356357_MTL_INLINE bool MTL::VertexAttribute::isActive() const358{359 return Object::sendMessage<bool>(this, _MTL_PRIVATE_SEL(isActive));360}361362_MTL_INLINE bool MTL::VertexAttribute::isPatchControlPointData() const363{364 return Object::sendMessage<bool>(this, _MTL_PRIVATE_SEL(isPatchControlPointData));365}366367_MTL_INLINE bool MTL::VertexAttribute::isPatchData() const368{369 return Object::sendMessage<bool>(this, _MTL_PRIVATE_SEL(isPatchData));370}371372_MTL_INLINE NS::String* MTL::VertexAttribute::name() const373{374 return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(name));375}376377_MTL_INLINE bool MTL::VertexAttribute::patchControlPointData() const378{379 return Object::sendMessage<bool>(this, _MTL_PRIVATE_SEL(isPatchControlPointData));380}381382_MTL_INLINE bool MTL::VertexAttribute::patchData() const383{384 return Object::sendMessage<bool>(this, _MTL_PRIVATE_SEL(isPatchData));385}386387_MTL_INLINE bool MTL::Attribute::active() const388{389 return Object::sendMessage<bool>(this, _MTL_PRIVATE_SEL(isActive));390}391392_MTL_INLINE MTL::Attribute* MTL::Attribute::alloc()393{394 return NS::Object::alloc<MTL::Attribute>(_MTL_PRIVATE_CLS(MTLAttribute));395}396397_MTL_INLINE NS::UInteger MTL::Attribute::attributeIndex() const398{399 return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(attributeIndex));400}401402_MTL_INLINE MTL::DataType MTL::Attribute::attributeType() const403{404 return Object::sendMessage<MTL::DataType>(this, _MTL_PRIVATE_SEL(attributeType));405}406407_MTL_INLINE MTL::Attribute* MTL::Attribute::init()408{409 return NS::Object::init<MTL::Attribute>();410}411412_MTL_INLINE bool MTL::Attribute::isActive() const413{414 return Object::sendMessage<bool>(this, _MTL_PRIVATE_SEL(isActive));415}416417_MTL_INLINE bool MTL::Attribute::isPatchControlPointData() const418{419 return Object::sendMessage<bool>(this, _MTL_PRIVATE_SEL(isPatchControlPointData));420}421422_MTL_INLINE bool MTL::Attribute::isPatchData() const423{424 return Object::sendMessage<bool>(this, _MTL_PRIVATE_SEL(isPatchData));425}426427_MTL_INLINE NS::String* MTL::Attribute::name() const428{429 return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(name));430}431432_MTL_INLINE bool MTL::Attribute::patchControlPointData() const433{434 return Object::sendMessage<bool>(this, _MTL_PRIVATE_SEL(isPatchControlPointData));435}436437_MTL_INLINE bool MTL::Attribute::patchData() const438{439 return Object::sendMessage<bool>(this, _MTL_PRIVATE_SEL(isPatchData));440}441442_MTL_INLINE MTL::FunctionConstant* MTL::FunctionConstant::alloc()443{444 return NS::Object::alloc<MTL::FunctionConstant>(_MTL_PRIVATE_CLS(MTLFunctionConstant));445}446447_MTL_INLINE NS::UInteger MTL::FunctionConstant::index() const448{449 return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(index));450}451452_MTL_INLINE MTL::FunctionConstant* MTL::FunctionConstant::init()453{454 return NS::Object::init<MTL::FunctionConstant>();455}456457_MTL_INLINE NS::String* MTL::FunctionConstant::name() const458{459 return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(name));460}461462_MTL_INLINE bool MTL::FunctionConstant::required() const463{464 return Object::sendMessage<bool>(this, _MTL_PRIVATE_SEL(required));465}466467_MTL_INLINE MTL::DataType MTL::FunctionConstant::type() const468{469 return Object::sendMessage<MTL::DataType>(this, _MTL_PRIVATE_SEL(type));470}471472_MTL_INLINE MTL::Device* MTL::Function::device() const473{474 return Object::sendMessage<MTL::Device*>(this, _MTL_PRIVATE_SEL(device));475}476477_MTL_INLINE NS::Dictionary* MTL::Function::functionConstantsDictionary() const478{479 return Object::sendMessage<NS::Dictionary*>(this, _MTL_PRIVATE_SEL(functionConstantsDictionary));480}481482_MTL_INLINE MTL::FunctionType MTL::Function::functionType() const483{484 return Object::sendMessage<MTL::FunctionType>(this, _MTL_PRIVATE_SEL(functionType));485}486487_MTL_INLINE NS::String* MTL::Function::label() const488{489 return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(label));490}491492_MTL_INLINE NS::String* MTL::Function::name() const493{494 return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(name));495}496497_MTL_INLINE MTL::ArgumentEncoder* MTL::Function::newArgumentEncoder(NS::UInteger bufferIndex)498{499 return Object::sendMessage<MTL::ArgumentEncoder*>(this, _MTL_PRIVATE_SEL(newArgumentEncoderWithBufferIndex_), bufferIndex);500}501502_MTL_INLINE MTL::ArgumentEncoder* MTL::Function::newArgumentEncoder(NS::UInteger bufferIndex, const MTL::AutoreleasedArgument* reflection)503{504 return Object::sendMessage<MTL::ArgumentEncoder*>(this, _MTL_PRIVATE_SEL(newArgumentEncoderWithBufferIndex_reflection_), bufferIndex, reflection);505}506507_MTL_INLINE MTL::FunctionOptions MTL::Function::options() const508{509 return Object::sendMessage<MTL::FunctionOptions>(this, _MTL_PRIVATE_SEL(options));510}511512_MTL_INLINE NS::Integer MTL::Function::patchControlPointCount() const513{514 return Object::sendMessage<NS::Integer>(this, _MTL_PRIVATE_SEL(patchControlPointCount));515}516517_MTL_INLINE MTL::PatchType MTL::Function::patchType() const518{519 return Object::sendMessage<MTL::PatchType>(this, _MTL_PRIVATE_SEL(patchType));520}521522_MTL_INLINE void MTL::Function::setLabel(const NS::String* label)523{524 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setLabel_), label);525}526527_MTL_INLINE NS::Array* MTL::Function::stageInputAttributes() const528{529 return Object::sendMessage<NS::Array*>(this, _MTL_PRIVATE_SEL(stageInputAttributes));530}531532_MTL_INLINE NS::Array* MTL::Function::vertexAttributes() const533{534 return Object::sendMessage<NS::Array*>(this, _MTL_PRIVATE_SEL(vertexAttributes));535}536537_MTL_INLINE MTL::CompileOptions* MTL::CompileOptions::alloc()538{539 return NS::Object::alloc<MTL::CompileOptions>(_MTL_PRIVATE_CLS(MTLCompileOptions));540}541542_MTL_INLINE bool MTL::CompileOptions::allowReferencingUndefinedSymbols() const543{544 return Object::sendMessage<bool>(this, _MTL_PRIVATE_SEL(allowReferencingUndefinedSymbols));545}546547_MTL_INLINE MTL::CompileSymbolVisibility MTL::CompileOptions::compileSymbolVisibility() const548{549 return Object::sendMessage<MTL::CompileSymbolVisibility>(this, _MTL_PRIVATE_SEL(compileSymbolVisibility));550}551552_MTL_INLINE bool MTL::CompileOptions::enableLogging() const553{554 return Object::sendMessage<bool>(this, _MTL_PRIVATE_SEL(enableLogging));555}556557_MTL_INLINE bool MTL::CompileOptions::fastMathEnabled() const558{559 return Object::sendMessage<bool>(this, _MTL_PRIVATE_SEL(fastMathEnabled));560}561562_MTL_INLINE MTL::FloatingPointConversionRoundingMode MTL::CompileOptions::floatingPointConversionRoundingMode() const563{564 return Object::sendMessage<MTL::FloatingPointConversionRoundingMode>(this, _MTL_PRIVATE_SEL(floatingPointConversionRoundingMode));565}566567_MTL_INLINE MTL::CompileOptions* MTL::CompileOptions::init()568{569 return NS::Object::init<MTL::CompileOptions>();570}571572_MTL_INLINE NS::String* MTL::CompileOptions::installName() const573{574 return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(installName));575}576577_MTL_INLINE MTL::LanguageVersion MTL::CompileOptions::languageVersion() const578{579 return Object::sendMessage<MTL::LanguageVersion>(this, _MTL_PRIVATE_SEL(languageVersion));580}581582_MTL_INLINE NS::Array* MTL::CompileOptions::libraries() const583{584 return Object::sendMessage<NS::Array*>(this, _MTL_PRIVATE_SEL(libraries));585}586587_MTL_INLINE MTL::LibraryType MTL::CompileOptions::libraryType() const588{589 return Object::sendMessage<MTL::LibraryType>(this, _MTL_PRIVATE_SEL(libraryType));590}591592_MTL_INLINE MTL::MathFloatingPointFunctions MTL::CompileOptions::mathFloatingPointFunctions() const593{594 return Object::sendMessage<MTL::MathFloatingPointFunctions>(this, _MTL_PRIVATE_SEL(mathFloatingPointFunctions));595}596597_MTL_INLINE MTL::MathMode MTL::CompileOptions::mathMode() const598{599 return Object::sendMessage<MTL::MathMode>(this, _MTL_PRIVATE_SEL(mathMode));600}601602_MTL_INLINE NS::UInteger MTL::CompileOptions::maxTotalThreadsPerThreadgroup() const603{604 return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(maxTotalThreadsPerThreadgroup));605}606607_MTL_INLINE MTL::LibraryOptimizationLevel MTL::CompileOptions::optimizationLevel() const608{609 return Object::sendMessage<MTL::LibraryOptimizationLevel>(this, _MTL_PRIVATE_SEL(optimizationLevel));610}611612_MTL_INLINE NS::Dictionary* MTL::CompileOptions::preprocessorMacros() const613{614 return Object::sendMessage<NS::Dictionary*>(this, _MTL_PRIVATE_SEL(preprocessorMacros));615}616617_MTL_INLINE bool MTL::CompileOptions::preserveInvariance() const618{619 return Object::sendMessage<bool>(this, _MTL_PRIVATE_SEL(preserveInvariance));620}621622_MTL_INLINE MTL::Size MTL::CompileOptions::requiredThreadsPerThreadgroup() const623{624 return Object::sendMessage<MTL::Size>(this, _MTL_PRIVATE_SEL(requiredThreadsPerThreadgroup));625}626627_MTL_INLINE void MTL::CompileOptions::setAllowReferencingUndefinedSymbols(bool allowReferencingUndefinedSymbols)628{629 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setAllowReferencingUndefinedSymbols_), allowReferencingUndefinedSymbols);630}631632_MTL_INLINE void MTL::CompileOptions::setCompileSymbolVisibility(MTL::CompileSymbolVisibility compileSymbolVisibility)633{634 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setCompileSymbolVisibility_), compileSymbolVisibility);635}636637_MTL_INLINE void MTL::CompileOptions::setEnableLogging(bool enableLogging)638{639 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setEnableLogging_), enableLogging);640}641642_MTL_INLINE void MTL::CompileOptions::setFastMathEnabled(bool fastMathEnabled)643{644 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setFastMathEnabled_), fastMathEnabled);645}646647_MTL_INLINE void MTL::CompileOptions::setFloatingPointConversionRoundingMode(MTL::FloatingPointConversionRoundingMode floatingPointConversionRoundingMode)648{649 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setFloatingPointConversionRoundingMode_), floatingPointConversionRoundingMode);650}651652_MTL_INLINE void MTL::CompileOptions::setInstallName(const NS::String* installName)653{654 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setInstallName_), installName);655}656657_MTL_INLINE void MTL::CompileOptions::setLanguageVersion(MTL::LanguageVersion languageVersion)658{659 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setLanguageVersion_), languageVersion);660}661662_MTL_INLINE void MTL::CompileOptions::setLibraries(const NS::Array* libraries)663{664 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setLibraries_), libraries);665}666667_MTL_INLINE void MTL::CompileOptions::setLibraryType(MTL::LibraryType libraryType)668{669 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setLibraryType_), libraryType);670}671672_MTL_INLINE void MTL::CompileOptions::setMathFloatingPointFunctions(MTL::MathFloatingPointFunctions mathFloatingPointFunctions)673{674 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setMathFloatingPointFunctions_), mathFloatingPointFunctions);675}676677_MTL_INLINE void MTL::CompileOptions::setMathMode(MTL::MathMode mathMode)678{679 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setMathMode_), mathMode);680}681682_MTL_INLINE void MTL::CompileOptions::setMaxTotalThreadsPerThreadgroup(NS::UInteger maxTotalThreadsPerThreadgroup)683{684 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setMaxTotalThreadsPerThreadgroup_), maxTotalThreadsPerThreadgroup);685}686687_MTL_INLINE void MTL::CompileOptions::setOptimizationLevel(MTL::LibraryOptimizationLevel optimizationLevel)688{689 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setOptimizationLevel_), optimizationLevel);690}691692_MTL_INLINE void MTL::CompileOptions::setPreprocessorMacros(const NS::Dictionary* preprocessorMacros)693{694 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setPreprocessorMacros_), preprocessorMacros);695}696697_MTL_INLINE void MTL::CompileOptions::setPreserveInvariance(bool preserveInvariance)698{699 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setPreserveInvariance_), preserveInvariance);700}701702_MTL_INLINE void MTL::CompileOptions::setRequiredThreadsPerThreadgroup(MTL::Size requiredThreadsPerThreadgroup)703{704 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setRequiredThreadsPerThreadgroup_), requiredThreadsPerThreadgroup);705}706707_MTL_INLINE MTL::FunctionReflection* MTL::FunctionReflection::alloc()708{709 return NS::Object::alloc<MTL::FunctionReflection>(_MTL_PRIVATE_CLS(MTLFunctionReflection));710}711712_MTL_INLINE NS::Array* MTL::FunctionReflection::bindings() const713{714 return Object::sendMessage<NS::Array*>(this, _MTL_PRIVATE_SEL(bindings));715}716717_MTL_INLINE MTL::FunctionReflection* MTL::FunctionReflection::init()718{719 return NS::Object::init<MTL::FunctionReflection>();720}721722_MTL_INLINE NS::String* MTL::FunctionReflection::userAnnotation() const723{724 return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(userAnnotation));725}726727_MTL_INLINE MTL::Device* MTL::Library::device() const728{729 return Object::sendMessage<MTL::Device*>(this, _MTL_PRIVATE_SEL(device));730}731732_MTL_INLINE NS::Array* MTL::Library::functionNames() const733{734 return Object::sendMessage<NS::Array*>(this, _MTL_PRIVATE_SEL(functionNames));735}736737_MTL_INLINE NS::String* MTL::Library::installName() const738{739 return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(installName));740}741742_MTL_INLINE NS::String* MTL::Library::label() const743{744 return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(label));745}746747_MTL_INLINE MTL::Function* MTL::Library::newFunction(const NS::String* functionName)748{749 return Object::sendMessage<MTL::Function*>(this, _MTL_PRIVATE_SEL(newFunctionWithName_), functionName);750}751752_MTL_INLINE MTL::Function* MTL::Library::newFunction(const NS::String* name, const MTL::FunctionConstantValues* constantValues, NS::Error** error)753{754 return Object::sendMessage<MTL::Function*>(this, _MTL_PRIVATE_SEL(newFunctionWithName_constantValues_error_), name, constantValues, error);755}756757_MTL_INLINE void MTL::Library::newFunction(const NS::String* name, const MTL::FunctionConstantValues* constantValues, void (^completionHandler)(MTL::Function*, NS::Error*))758{759 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(newFunctionWithName_constantValues_completionHandler_), name, constantValues, completionHandler);760}761762_MTL_INLINE void MTL::Library::newFunction(const MTL::FunctionDescriptor* descriptor, void (^completionHandler)(MTL::Function*, NS::Error*))763{764 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(newFunctionWithDescriptor_completionHandler_), descriptor, completionHandler);765}766767_MTL_INLINE MTL::Function* MTL::Library::newFunction(const MTL::FunctionDescriptor* descriptor, NS::Error** error)768{769 return Object::sendMessage<MTL::Function*>(this, _MTL_PRIVATE_SEL(newFunctionWithDescriptor_error_), descriptor, error);770}771772_MTL_INLINE void MTL::Library::newFunction(const NS::String* pFunctionName, const MTL::FunctionConstantValues* pConstantValues, const MTL::FunctionCompletionHandlerFunction& completionHandler)773{774 __block MTL::FunctionCompletionHandlerFunction blockCompletionHandler = completionHandler;775 newFunction(pFunctionName, pConstantValues, ^(MTL::Function* pFunction, NS::Error* pError) { blockCompletionHandler(pFunction, pError); });776}777778_MTL_INLINE void MTL::Library::newFunction(const MTL::FunctionDescriptor* pDescriptor, const MTL::FunctionCompletionHandlerFunction& completionHandler)779{780 __block MTL::FunctionCompletionHandlerFunction blockCompletionHandler = completionHandler;781 newFunction(pDescriptor, ^(MTL::Function* pFunction, NS::Error* pError) { blockCompletionHandler(pFunction, pError); });782}783784_MTL_INLINE void MTL::Library::newIntersectionFunction(const MTL::IntersectionFunctionDescriptor* descriptor, void (^completionHandler)(MTL::Function*, NS::Error*))785{786 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(newIntersectionFunctionWithDescriptor_completionHandler_), descriptor, completionHandler);787}788789_MTL_INLINE MTL::Function* MTL::Library::newIntersectionFunction(const MTL::IntersectionFunctionDescriptor* descriptor, NS::Error** error)790{791 return Object::sendMessage<MTL::Function*>(this, _MTL_PRIVATE_SEL(newIntersectionFunctionWithDescriptor_error_), descriptor, error);792}793794_MTL_INLINE void MTL::Library::newIntersectionFunction(const MTL::IntersectionFunctionDescriptor* pDescriptor, const MTL::FunctionCompletionHandlerFunction& completionHandler)795{796 __block MTL::FunctionCompletionHandlerFunction blockCompletionHandler = completionHandler;797 newIntersectionFunction(pDescriptor, ^(MTL::Function* pFunction, NS::Error* pError) { blockCompletionHandler(pFunction, pError); });798}799800_MTL_INLINE MTL::FunctionReflection* MTL::Library::reflectionForFunction(const NS::String* functionName)801{802 return Object::sendMessage<MTL::FunctionReflection*>(this, _MTL_PRIVATE_SEL(reflectionForFunctionWithName_), functionName);803}804805_MTL_INLINE void MTL::Library::setLabel(const NS::String* label)806{807 Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setLabel_), label);808}809810_MTL_INLINE MTL::LibraryType MTL::Library::type() const811{812 return Object::sendMessage<MTL::LibraryType>(this, _MTL_PRIVATE_SEL(type));813}814