9#ifdef USING_MULTIPLE_CLASSES
10#error "Cannot include both MTLCompute.hpp and MTLComputeGPU.hpp"
13#define USING_SINGLE_CLASS
33 if (!this->kernelLoaded) {
34 throw std::runtime_error(
"MTLCompute error: Kernel not loaded");
51 this->gpu = MTL::CreateSystemDefaultDevice();
55 this->kernelLoaded =
true;
65 this->gpu = MTL::CreateSystemDefaultDevice();
75 this->gpu->autorelease();
88 void loadKernel(std::string libname, std::string functionName) {
92 this->kernelLoaded =
true;
109 this->commandManager.
loadBuffer(buffer, index);
122 void loadMatrix(std::vector<std::vector<T>> &matrix,
int index) {
180 this->commandManager.
reset();
Definition MTLComputeBuffer.hpp:10
std::vector< T > getData()
Get the data from the buffer as a vector.
Definition MTLComputeBuffer.hpp:181
Definition MTLComputeCommandManager.hpp:13
void loadBuffer(Buffer< T > buffer, int index)
Load a buffer into the CommandManager.
Definition MTLComputeCommandManager.hpp:75
void loadTexture(Texture< T > texture, int index)
Load a texture into the CommandManager.
Definition MTLComputeCommandManager.hpp:95
void reset()
reset the buffers and textures
Definition MTLComputeCommandManager.hpp:211
void dispatch()
Dispatch the kernel.
Definition MTLComputeCommandManager.hpp:118
Definition MTLComputeGPU.hpp:18
void runKernel()
Run the kernel.
Definition MTLComputeGPU.hpp:135
void checkloaded()
Check if the kernel has been loaded.
Definition MTLComputeGPU.hpp:32
GPU()
Default constructor for the GPU class.
Definition MTLComputeGPU.hpp:64
std::vector< std::vector< T > > getMatrix(int index)
Get a matrix from the GPU.
Definition MTLComputeGPU.hpp:166
void loadArray(std::vector< T > &array, int index)
Load an array into the GPU.
Definition MTLComputeGPU.hpp:105
void reset()
Reset the GPU.
Definition MTLComputeGPU.hpp:178
MTL::Device * gpu
The Metal device object.
Definition MTLComputeGPU.hpp:21
MTLCompute::CommandManager< T > commandManager
The MetalCompute command manager object.
Definition MTLComputeGPU.hpp:24
GPU(std::string libname, std::string functionName)
Constructor for the GPU class.
Definition MTLComputeGPU.hpp:50
MTLCompute::Kernel kernel
The MetalCompute kernel object.
Definition MTLComputeGPU.hpp:22
void loadMatrix(std::vector< std::vector< T > > &matrix, int index)
Load a matrix into the GPU.
Definition MTLComputeGPU.hpp:122
std::vector< T > getArray(int index)
Get an array from the GPU.
Definition MTLComputeGPU.hpp:150
void loadKernel(std::string libname, std::string functionName)
Load a metal library and function.
Definition MTLComputeGPU.hpp:88
~GPU()
Destructor for the GPU class.
Definition MTLComputeGPU.hpp:74
MTL::Device * getGPU()
Get the GPU device.
Definition MTLComputeGPU.hpp:189
bool kernelLoaded
Whether the kernel has been loaded.
Definition MTLComputeGPU.hpp:23
Definition MTLComputeKernel.hpp:7
void useFunction(const std::string &funcname)
Use a function in the library.
Definition MTLComputeKernel.hpp:101
Definition MTLComputeTexture.hpp:10
std::vector< std::vector< T > > getData()
Get the data from the texture as a vector.
Definition MTLComputeTexture.hpp:252
Definition MTLComputeBuffer.hpp:7