MetalCompute 1.0
An API to make GPU compute calls easier
Loading...
Searching...
No Matches
MTLCompute::GPU< T > Class Template Reference

#include <MTLComputeGPU.hpp>

Public Member Functions

 GPU (std::string libname, std::string functionName)
 Constructor for the GPU class.
 
 GPU ()
 Default constructor for the GPU class.
 
 ~GPU ()
 Destructor for the GPU class.
 
void loadKernel (std::string libname, std::string functionName)
 Load a metal library and function.
 
void loadArray (std::vector< T > &array, int index)
 Load an array into the GPU.
 
void loadMatrix (std::vector< std::vector< T > > &matrix, int index)
 Load a matrix into the GPU.
 
void runKernel ()
 Run the kernel.
 
std::vector< T > getArray (int index)
 Get an array from the GPU.
 
std::vector< std::vector< T > > getMatrix (int index)
 Get a matrix from the GPU.
 
void reset ()
 Reset the GPU.
 
MTL::Device * getGPU ()
 Get the GPU device.
 

Private Member Functions

void checkloaded ()
 Check if the kernel has been loaded.
 

Private Attributes

MTL::Device * gpu
 The Metal device object.
 
MTLCompute::Kernel kernel
 The MetalCompute kernel object.
 
bool kernelLoaded = false
 Whether the kernel has been loaded.
 
MTLCompute::CommandManager< T > commandManager
 The MetalCompute command manager object.
 

Constructor & Destructor Documentation

◆ GPU() [1/2]

template<typename T >
MTLCompute::GPU< T >::GPU ( std::string libname,
std::string functionName )
inline

Constructor for the GPU class.

Takes in the name of the Metal library and the name of the function and creates a new GPU object, MTLCompute::Kernel object, and MTLCompute::CommandManager object

Parameters
libnameThe name of the Metal library
functionNameThe name of the function

◆ GPU() [2/2]

template<typename T >
MTLCompute::GPU< T >::GPU ( )
inline

Default constructor for the GPU class.

Creates a new GPU object, MTLCompute::Kernel object, and MTLCompute::CommandManager object

◆ ~GPU()

template<typename T >
MTLCompute::GPU< T >::~GPU ( )
inline

Destructor for the GPU class.

Releases the GPU object

Member Function Documentation

◆ checkloaded()

template<typename T >
void MTLCompute::GPU< T >::checkloaded ( )
inlineprivate

Check if the kernel has been loaded.

If the kernel has not been loaded, print an error message

◆ getArray()

template<typename T >
std::vector< T > MTLCompute::GPU< T >::getArray ( int index)
inline

Get an array from the GPU.

Takes in an index and returns the array at that index

Parameters
indexThe index of the array
Returns
The array at the index

◆ getGPU()

template<typename T >
MTL::Device * MTLCompute::GPU< T >::getGPU ( )
inline

Get the GPU device.

Returns
The GPU device

◆ getMatrix()

template<typename T >
std::vector< std::vector< T > > MTLCompute::GPU< T >::getMatrix ( int index)
inline

Get a matrix from the GPU.

Takes in an index and returns the matrix at that index

Parameters
indexThe index of the matrix
Returns
The matrix at the index

◆ loadArray()

template<typename T >
void MTLCompute::GPU< T >::loadArray ( std::vector< T > & array,
int index )
inline

Load an array into the GPU.

Takes in a vector of type T and an index and loads the array into the GPU at that index

Parameters
arrayThe array to load
indexThe index to load the array into

◆ loadKernel()

template<typename T >
void MTLCompute::GPU< T >::loadKernel ( std::string libname,
std::string functionName )
inline

Load a metal library and function.

Takes in the name of the Metal library and the name of the function and creates a new MTLCompute::Kernel object and MTLCompute::CommandManager object

Parameters
libnameThe name of the Metal library
functionNameThe name of the function

◆ loadMatrix()

template<typename T >
void MTLCompute::GPU< T >::loadMatrix ( std::vector< std::vector< T > > & matrix,
int index )
inline

Load a matrix into the GPU.

Takes in a vector of vectors of type T and an index and loads the matrix into the GPU at that index

Parameters
matrixThe matrix to load
indexThe index to load the matrix into

◆ reset()

template<typename T >
void MTLCompute::GPU< T >::reset ( )
inline

Reset the GPU.

Resets the command manager

◆ runKernel()

template<typename T >
void MTLCompute::GPU< T >::runKernel ( )
inline

Run the kernel.

Dispatches the command manager

Member Data Documentation

◆ commandManager

template<typename T >
MTLCompute::CommandManager<T> MTLCompute::GPU< T >::commandManager
private

The MetalCompute command manager object.

◆ gpu

template<typename T >
MTL::Device* MTLCompute::GPU< T >::gpu
private

The Metal device object.

◆ kernel

template<typename T >
MTLCompute::Kernel MTLCompute::GPU< T >::kernel
private

The MetalCompute kernel object.

◆ kernelLoaded

template<typename T >
bool MTLCompute::GPU< T >::kernelLoaded = false
private

Whether the kernel has been loaded.


The documentation for this class was generated from the following file: