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.0 KB · 119 lines cpp
Raw Blame History
1//-------------------------------------------------------------------------------------------------------------------------------------------------------------2//3// Metal/MTLResourceViewPool.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 "MTLTypes.hpp"2829namespace MTL30{31class Device;32class ResourceViewPool;33class ResourceViewPoolDescriptor;3435class ResourceViewPoolDescriptor : public NS::Copying<ResourceViewPoolDescriptor>36{37public:38    static ResourceViewPoolDescriptor* alloc();3940    ResourceViewPoolDescriptor*        init();4142    NS::String*                        label() const;4344    NS::UInteger                       resourceViewCount() const;4546    void                               setLabel(const NS::String* label);4748    void                               setResourceViewCount(NS::UInteger resourceViewCount);49};50class ResourceViewPool : public NS::Referencing<ResourceViewPool>51{52public:53    ResourceID   baseResourceID() const;5455    ResourceID   copyResourceViewsFromPool(const MTL::ResourceViewPool* sourcePool, NS::Range sourceRange, NS::UInteger destinationIndex);5657    Device*      device() const;5859    NS::String*  label() const;6061    NS::UInteger resourceViewCount() const;62};6364}65_MTL_INLINE MTL::ResourceViewPoolDescriptor* MTL::ResourceViewPoolDescriptor::alloc()66{67    return NS::Object::alloc<MTL::ResourceViewPoolDescriptor>(_MTL_PRIVATE_CLS(MTLResourceViewPoolDescriptor));68}6970_MTL_INLINE MTL::ResourceViewPoolDescriptor* MTL::ResourceViewPoolDescriptor::init()71{72    return NS::Object::init<MTL::ResourceViewPoolDescriptor>();73}7475_MTL_INLINE NS::String* MTL::ResourceViewPoolDescriptor::label() const76{77    return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(label));78}7980_MTL_INLINE NS::UInteger MTL::ResourceViewPoolDescriptor::resourceViewCount() const81{82    return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(resourceViewCount));83}8485_MTL_INLINE void MTL::ResourceViewPoolDescriptor::setLabel(const NS::String* label)86{87    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setLabel_), label);88}8990_MTL_INLINE void MTL::ResourceViewPoolDescriptor::setResourceViewCount(NS::UInteger resourceViewCount)91{92    Object::sendMessage<void>(this, _MTL_PRIVATE_SEL(setResourceViewCount_), resourceViewCount);93}9495_MTL_INLINE MTL::ResourceID MTL::ResourceViewPool::baseResourceID() const96{97    return Object::sendMessage<MTL::ResourceID>(this, _MTL_PRIVATE_SEL(baseResourceID));98}99100_MTL_INLINE MTL::ResourceID MTL::ResourceViewPool::copyResourceViewsFromPool(const MTL::ResourceViewPool* sourcePool, NS::Range sourceRange, NS::UInteger destinationIndex)101{102    return Object::sendMessage<MTL::ResourceID>(this, _MTL_PRIVATE_SEL(copyResourceViewsFromPool_sourceRange_destinationIndex_), sourcePool, sourceRange, destinationIndex);103}104105_MTL_INLINE MTL::Device* MTL::ResourceViewPool::device() const106{107    return Object::sendMessage<MTL::Device*>(this, _MTL_PRIVATE_SEL(device));108}109110_MTL_INLINE NS::String* MTL::ResourceViewPool::label() const111{112    return Object::sendMessage<NS::String*>(this, _MTL_PRIVATE_SEL(label));113}114115_MTL_INLINE NS::UInteger MTL::ResourceViewPool::resourceViewCount() const116{117    return Object::sendMessage<NS::UInteger>(this, _MTL_PRIVATE_SEL(resourceViewCount));118}119