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.5 KB · 118 lines cpp
Raw Blame History
1//-------------------------------------------------------------------------------------------------------------------------------------------------------------2//3// Metal/MTLCommandEncoder.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 Device;3132_MTL_OPTIONS(NS::UInteger, ResourceUsage) {33    ResourceUsageRead = 1,34    ResourceUsageWrite = 1 << 1,35    ResourceUsageSample = 1 << 2,36};3738_MTL_OPTIONS(NS::UInteger, BarrierScope) {39    BarrierScopeBuffers = 1,40    BarrierScopeTextures = 1 << 1,41    BarrierScopeRenderTargets = 1 << 2,42};4344_MTL_OPTIONS(NS::UInteger, Stages) {45    StageVertex = 1,46    StageFragment = 1 << 1,47    StageTile = 1 << 2,48    StageObject = 1 << 3,49    StageMesh = 1 << 4,50    StageResourceState = 1 << 26,51    StageDispatch = 1 << 27,52    StageBlit = 1 << 28,53    StageAccelerationStructure = 1 << 29,54    StageMachineLearning = 1 << 30,55    StageAll = 9223372036854775807,56};5758class CommandEncoder : public NS::Referencing<CommandEncoder>59{60public:61    void        barrierAfterQueueStages(MTL::Stages afterQueueStages, MTL::Stages beforeStages);6263    Device*     device() const;6465    void        endEncoding();6667    void        insertDebugSignpost(const NS::String* string);6869    NS::String* label() const;7071    void        popDebugGroup();7273    void        pushDebugGroup(const NS::String* string);7475    void        setLabel(const NS::String* label);76};7778}79_MTL_INLINE void MTL::CommandEncoder::barrierAfterQueueStages(MTL::Stages afterQueueStages, MTL::Stages beforeStages)80{81    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(barrierAfterQueueStages_beforeStages_), afterQueueStages, beforeStages);82}8384_MTL_INLINE MTL::Device* MTL::CommandEncoder::device() const85{86    return Object::sendMessage<MTL::Device*>(this, _MTL_PRIVATE_SEL(device));87}8889_MTL_INLINE void MTL::CommandEncoder::endEncoding()90{91    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(endEncoding));92}9394_MTL_INLINE void MTL::CommandEncoder::insertDebugSignpost(const NS::String* string)95{96    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(insertDebugSignpost_), string);97}9899_MTL_INLINE NS::String* MTL::CommandEncoder::label() const100{101    return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(label));102}103104_MTL_INLINE void MTL::CommandEncoder::popDebugGroup()105{106    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(popDebugGroup));107}108109_MTL_INLINE void MTL::CommandEncoder::pushDebugGroup(const NS::String* string)110{111    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(pushDebugGroup_), string);112}113114_MTL_INLINE void MTL::CommandEncoder::setLabel(const NS::String* label)115{116    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setLabel_), label);117}118