PXL
module.hpp
Go to the documentation of this file.
1 // SPDX-License-Identifier: Apache-2.0
2 // Copyright 2024 XCENA Inc.
3 
4 #pragma once
5 #include <cstdint>
6 #include <string>
7 #include <vector>
8 
9 #include "pxl/function.hpp"
10 
11 namespace pxl
12 {
13 
29 template <auto Func>
30 struct KernelTraits;
31 
43 class Module
44 {
45 public:
49  Module(const Module&) = delete;
50 
54  Module& operator=(const Module&) = delete;
55 
72  virtual Function* createFunction(const char* muFuncName) = 0;
73 
86  template <auto Func>
88  {
89  const char* kernelName = nullptr;
90 
91 #if defined(__PXCC_ANALYSIS__)
92  kernelName = "__pxcc_placeholder__";
93 #else
94  static_assert(sizeof(KernelTraits<Func>) > 0,
95  "Kernel function not found in KernelTraits — was it compiled with pxcc?");
96  kernelName = KernelTraits<Func>::name;
97 #endif
98 
99  return createFunction(kernelName);
100  }
101 
117  virtual void destroyFunction(Function* function) = 0;
118 
124  virtual std::string getMuBinaryPath() const = 0;
125 
131  virtual uint32_t getNumMuFunctions() const = 0;
132 
138  virtual std::vector<std::string> getMuFunctionList() const = 0;
139 
140 protected:
141  Module() = default;
142  virtual ~Module() = default;
143 };
144 
156 Module* createModule(const char* muBinaryPath);
157 
164 Module* createModule(const void* image);
165 
182 
188 void destroyModule(Module* module);
189 
200 void registerKernelBinary(const void* start, const void* end);
201 
202 } // namespace pxl
Defines a function to be executed by each thread on the MU.
Definition: function.hpp:22
A container for Function of MU kernel binary.
Definition: module.hpp:44
virtual ~Module()=default
Function * createFunction()
Creates a Function object via compile-time KernelTraits lookup.
Definition: module.hpp:87
Module & operator=(const Module &)=delete
Deleted copy assignment operator.
virtual std::string getMuBinaryPath() const =0
Gets the binary path of the module.
Module()=default
virtual uint32_t getNumMuFunctions() const =0
Gets the number of functions in the module.
virtual std::vector< std::string > getMuFunctionList() const =0
Gets the name of MU functions in the module.
virtual Function * createFunction(const char *muFuncName)=0
Creates a Function object from the specified function name.
Module(const Module &)=delete
Deleted copy constructor.
virtual void destroyFunction(Function *function)=0
Destroys the specified Function object.
Definition: config.hpp:11
void destroyModule(Module *module)
Destroys the specified Module object.
Module * createModule(const char *muBinaryPath)
Creates a Module object from the specified MU binary path.
void registerKernelBinary(const void *start, const void *end)
Registers an embedded kernel binary for automatic loading.
Traits class that maps a kernel function pointer to its name string.
Definition: module.hpp:30