27 Kernel(MTL::Device *
gpu,
const std::string &filename) {
30 this->library = this->gpu->newLibrary(NS::URL::fileURLWithPath(NS::String::string(filename.c_str(), \
31 NS::ASCIIStringEncoding)),
nullptr);
33 if (this->library ==
nullptr) {
34 std::cerr <<
"Error: Could not load library " << filename << std::endl;
50 Kernel(MTL::Device *
gpu,
const std::string &filename,
const std::string &funcname) {
53 this->library = this->gpu->newLibrary(NS::String::string(filename.c_str(), NS::ASCIIStringEncoding),
nullptr);
55 if (this->library ==
nullptr) {
56 std::cerr <<
"Error: Could not load library " << filename << std::endl;
76 this->library->autorelease();
86 std::vector<std::string> names;
87 for (
int i = 0; i < this->library->functionNames()->count(); i++) {
88 names.push_back(this->library->functionNames()->object(i)->description()->cString(NS::ASCIIStringEncoding));
102 this->function = this->library->newFunction(NS::String::string(funcname.c_str(), NS::ASCIIStringEncoding));
103 if (this->function ==
nullptr) {
104 throw std::runtime_error(
"Error: Could not load function " + funcname);
107 NS::Error *error =
nullptr;
108 this->pipeline =
gpu->newComputePipelineState(this->function, &error);
Definition MTLComputeKernel.hpp:7
MTL::ComputePipelineState * getPLS()
Get the MTL::ComputePipelineState object.
Definition MTLComputeKernel.hpp:117
~Kernel()
Destructor for the Kernel class.
Definition MTLComputeKernel.hpp:75
Kernel()=default
Default constructor for the Kernel class.
MTL::Library * library
The Metal library object.
Definition MTLComputeKernel.hpp:11
void useFunction(const std::string &funcname)
Use a function in the library.
Definition MTLComputeKernel.hpp:101
std::vector< std::string > getFunctionNames()
Get the names of the functions in the library.
Definition MTLComputeKernel.hpp:85
MTL::ComputePipelineState * pipeline
The Metal compute pipeline state object.
Definition MTLComputeKernel.hpp:13
Kernel(MTL::Device *gpu, const std::string &filename)
Constructor for the Kernel class.
Definition MTLComputeKernel.hpp:27
MTL::Device * gpu
The Metal device object.
Definition MTLComputeKernel.hpp:10
MTL::Function * function
The Metal function object.
Definition MTLComputeKernel.hpp:12
Kernel(MTL::Device *gpu, const std::string &filename, const std::string &funcname)
Constructor for the Kernel class with function name.
Definition MTLComputeKernel.hpp:50
Definition MTLComputeBuffer.hpp:7