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%
4.6 KB · 151 lines cpp
Raw Blame History
1//-------------------------------------------------------------------------------------------------------------------------------------------------------------2//3// Metal/MTL4PipelineState.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 "MTLPipeline.hpp"27#include "MTLPrivate.hpp"2829namespace MTL430{31class PipelineDescriptor;32class PipelineOptions;33_MTL_ENUM(NS::Integer, AlphaToOneState) {34    AlphaToOneStateDisabled = 0,35    AlphaToOneStateEnabled = 1,36};3738_MTL_ENUM(NS::Integer, AlphaToCoverageState) {39    AlphaToCoverageStateDisabled = 0,40    AlphaToCoverageStateEnabled = 1,41};4243_MTL_ENUM(NS::Integer, BlendState) {44    BlendStateDisabled = 0,45    BlendStateEnabled = 1,46    BlendStateUnspecialized = 2,47};4849_MTL_ENUM(NS::Integer, IndirectCommandBufferSupportState) {50    IndirectCommandBufferSupportStateDisabled = 0,51    IndirectCommandBufferSupportStateEnabled = 1,52};5354_MTL_OPTIONS(NS::UInteger, ShaderReflection) {55    ShaderReflectionNone = 0,56    ShaderReflectionBindingInfo = 1,57    ShaderReflectionBufferTypeInfo = 1 << 1,58};5960class PipelineOptions : public NS::Copying<PipelineOptions>61{62public:63    static PipelineOptions* alloc();6465    PipelineOptions*        init();6667    void                    setShaderReflection(MTL4::ShaderReflection shaderReflection);6869    void                    setShaderValidation(MTL::ShaderValidation shaderValidation);7071    ShaderReflection        shaderReflection() const;7273    MTL::ShaderValidation   shaderValidation() const;74};75class PipelineDescriptor : public NS::Copying<PipelineDescriptor>76{77public:78    static PipelineDescriptor* alloc();7980    PipelineDescriptor*        init();8182    NS::String*                label() const;8384    PipelineOptions*           options() const;8586    void                       setLabel(const NS::String* label);8788    void                       setOptions(const MTL4::PipelineOptions* options);89};9091}92_MTL_INLINE MTL4::PipelineOptions* MTL4::PipelineOptions::alloc()93{94    return NS::Object::alloc<MTL4::PipelineOptions>(_MTL_PRIVATE_CLS(MTL4PipelineOptions));95}9697_MTL_INLINE MTL4::PipelineOptions* MTL4::PipelineOptions::init()98{99    return NS::Object::init<MTL4::PipelineOptions>();100}101102_MTL_INLINE void MTL4::PipelineOptions::setShaderReflection(MTL4::ShaderReflection shaderReflection)103{104    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setShaderReflection_), shaderReflection);105}106107_MTL_INLINE void MTL4::PipelineOptions::setShaderValidation(MTL::ShaderValidation shaderValidation)108{109    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setShaderValidation_), shaderValidation);110}111112_MTL_INLINE MTL4::ShaderReflection MTL4::PipelineOptions::shaderReflection() const113{114    return Object::sendMessage<MTL4::ShaderReflection>(this, _MTL_PRIVATE_SEL(shaderReflection));115}116117_MTL_INLINE MTL::ShaderValidation MTL4::PipelineOptions::shaderValidation() const118{119    return Object::sendMessage<MTL::ShaderValidation>(this, _MTL_PRIVATE_SEL(shaderValidation));120}121122_MTL_INLINE MTL4::PipelineDescriptor* MTL4::PipelineDescriptor::alloc()123{124    return NS::Object::alloc<MTL4::PipelineDescriptor>(_MTL_PRIVATE_CLS(MTL4PipelineDescriptor));125}126127_MTL_INLINE MTL4::PipelineDescriptor* MTL4::PipelineDescriptor::init()128{129    return NS::Object::init<MTL4::PipelineDescriptor>();130}131132_MTL_INLINE NS::String* MTL4::PipelineDescriptor::label() const133{134    return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(label));135}136137_MTL_INLINE MTL4::PipelineOptions* MTL4::PipelineDescriptor::options() const138{139    return Object::sendMessage<MTL4::PipelineOptions*>(this, _MTL_PRIVATE_SEL(options));140}141142_MTL_INLINE void MTL4::PipelineDescriptor::setLabel(const NS::String* label)143{144    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setLabel_), label);145}146147_MTL_INLINE void MTL4::PipelineDescriptor::setOptions(const MTL4::PipelineOptions* options)148{149    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setOptions_), options);150}151