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.5 KB · 159 lines cpp
Raw Blame History
1//-------------------------------------------------------------------------------------------------------------------------------------------------------------2//3// Metal/MTLCommandQueue.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 CommandBuffer;31class CommandBufferDescriptor;32class CommandQueueDescriptor;33class Device;34class LogState;35class ResidencySet;3637class CommandQueue : public NS::Referencing<CommandQueue>38{39public:40    void           addResidencySet(const MTL::ResidencySet* residencySet);41    void           addResidencySets(const MTL::ResidencySet* const residencySets[], NS::UInteger count);4243    CommandBuffer* commandBuffer();44    CommandBuffer* commandBuffer(const MTL::CommandBufferDescriptor* descriptor);45    CommandBuffer* commandBufferWithUnretainedReferences();4647    Device*        device() const;4849    void           insertDebugCaptureBoundary();5051    NS::String*    label() const;5253    void           removeResidencySet(const MTL::ResidencySet* residencySet);54    void           removeResidencySets(const MTL::ResidencySet* const residencySets[], NS::UInteger count);5556    void           setLabel(const NS::String* label);57};58class CommandQueueDescriptor : public NS::Copying<CommandQueueDescriptor>59{60public:61    static CommandQueueDescriptor* alloc();6263    CommandQueueDescriptor*        init();6465    LogState*                      logState() const;6667    NS::UInteger                   maxCommandBufferCount() const;6869    void                           setLogState(const MTL::LogState* logState);7071    void                           setMaxCommandBufferCount(NS::UInteger maxCommandBufferCount);72};7374}75_MTL_INLINE void MTL::CommandQueue::addResidencySet(const MTL::ResidencySet* residencySet)76{77    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(addResidencySet_), residencySet);78}7980_MTL_INLINE void MTL::CommandQueue::addResidencySets(const MTL::ResidencySet* const residencySets[], NS::UInteger count)81{82    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(addResidencySets_count_), residencySets, count);83}8485_MTL_INLINE MTL::CommandBuffer* MTL::CommandQueue::commandBuffer()86{87    return Object::sendMessage<MTL::CommandBuffer*>(this, _MTL_PRIVATE_SEL(commandBuffer));88}8990_MTL_INLINE MTL::CommandBuffer* MTL::CommandQueue::commandBuffer(const MTL::CommandBufferDescriptor* descriptor)91{92    return Object::sendMessage<MTL::CommandBuffer*>(this, _MTL_PRIVATE_SEL(commandBufferWithDescriptor_), descriptor);93}9495_MTL_INLINE MTL::CommandBuffer* MTL::CommandQueue::commandBufferWithUnretainedReferences()96{97    return Object::sendMessage<MTL::CommandBuffer*>(this, _MTL_PRIVATE_SEL(commandBufferWithUnretainedReferences));98}99100_MTL_INLINE MTL::Device* MTL::CommandQueue::device() const101{102    return Object::sendMessage<MTL::Device*>(this, _MTL_PRIVATE_SEL(device));103}104105_MTL_INLINE void MTL::CommandQueue::insertDebugCaptureBoundary()106{107    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(insertDebugCaptureBoundary));108}109110_MTL_INLINE NS::String* MTL::CommandQueue::label() const111{112    return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(label));113}114115_MTL_INLINE void MTL::CommandQueue::removeResidencySet(const MTL::ResidencySet* residencySet)116{117    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(removeResidencySet_), residencySet);118}119120_MTL_INLINE void MTL::CommandQueue::removeResidencySets(const MTL::ResidencySet* const residencySets[], NS::UInteger count)121{122    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(removeResidencySets_count_), residencySets, count);123}124125_MTL_INLINE void MTL::CommandQueue::setLabel(const NS::String* label)126{127    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setLabel_), label);128}129130_MTL_INLINE MTL::CommandQueueDescriptor* MTL::CommandQueueDescriptor::alloc()131{132    return NS::Object::alloc<MTL::CommandQueueDescriptor>(_MTL_PRIVATE_CLS(MTLCommandQueueDescriptor));133}134135_MTL_INLINE MTL::CommandQueueDescriptor* MTL::CommandQueueDescriptor::init()136{137    return NS::Object::init<MTL::CommandQueueDescriptor>();138}139140_MTL_INLINE MTL::LogState* MTL::CommandQueueDescriptor::logState() const141{142    return Object::sendMessage<MTL::LogState*>(this, _MTL_PRIVATE_SEL(logState));143}144145_MTL_INLINE NS::UInteger MTL::CommandQueueDescriptor::maxCommandBufferCount() const146{147    return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(maxCommandBufferCount));148}149150_MTL_INLINE void MTL::CommandQueueDescriptor::setLogState(const MTL::LogState* logState)151{152    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setLogState_), logState);153}154155_MTL_INLINE void MTL::CommandQueueDescriptor::setMaxCommandBufferCount(NS::UInteger maxCommandBufferCount)156{157    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setMaxCommandBufferCount_), maxCommandBufferCount);158}159