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%
2.9 KB · 101 lines cpp
Raw Blame History
1//-------------------------------------------------------------------------------------------------------------------------------------------------------------2//3// Metal/MTL4CommandAllocator.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"27#include <cstdint>2829namespace MTL30{31class Device;32}3334namespace MTL435{3637class CommandAllocatorDescriptor : public NS::Copying<CommandAllocatorDescriptor>38{39public:40    static CommandAllocatorDescriptor* alloc();4142    CommandAllocatorDescriptor*        init();4344    NS::String*                        label() const;45    void                               setLabel(const NS::String* label);46};4748class CommandAllocator : public NS::Referencing<CommandAllocator>49{50public:51    uint64_t     allocatedSize();5253    MTL::Device* device() const;5455    NS::String*  label() const;5657    void         reset();58};5960}6162_MTL_INLINE MTL4::CommandAllocatorDescriptor* MTL4::CommandAllocatorDescriptor::alloc()63{64    return NS::Object::alloc<MTL4::CommandAllocatorDescriptor>(_MTL_PRIVATE_CLS(MTL4CommandAllocatorDescriptor));65}6667_MTL_INLINE MTL4::CommandAllocatorDescriptor* MTL4::CommandAllocatorDescriptor::init()68{69    return NS::Object::init<MTL4::CommandAllocatorDescriptor>();70}7172_MTL_INLINE NS::String* MTL4::CommandAllocatorDescriptor::label() const73{74    return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(label));75}7677_MTL_INLINE void MTL4::CommandAllocatorDescriptor::setLabel(const NS::String* label)78{79    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setLabel_), label);80}8182_MTL_INLINE uint64_t MTL4::CommandAllocator::allocatedSize()83{84    return Object::sendMessage<uint64_t>(this, _MTL_PRIVATE_SEL(allocatedSize));85}8687_MTL_INLINE MTL::Device* MTL4::CommandAllocator::device() const88{89    return Object::sendMessage<MTL::Device*>(this, _MTL_PRIVATE_SEL(device));90}9192_MTL_INLINE NS::String* MTL4::CommandAllocator::label() const93{94    return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(label));95}9697_MTL_INLINE void MTL4::CommandAllocator::reset()98{99    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(reset));100}101