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 
6 #include <cstdint>
7 #include <pxl/v3_api_guard.hpp>
8 #include <string>
9 #include <vector>
10 
11 #include "pxl/function.hpp"
12 
13 namespace pxl
14 {
15 
31 template <auto Func>
32 struct KernelTraits;
33 
45 class Module
46 {
47 public:
51  Module(const Module&) = delete;
52 
56  Module& operator=(const Module&) = delete;
57 
74  virtual Function* createFunction(const char* muFuncName) = 0;
75 
88  template <auto Func>
90  {
91  const char* kernelName = nullptr;
92 
93 #if defined(__PXCC_ANALYSIS__)
94  kernelName = "__pxcc_placeholder__";
95 #else
96  static_assert(sizeof(KernelTraits<Func>) > 0,
97  "Kernel function not found in KernelTraits — was it compiled with pxcc?");
98  kernelName = KernelTraits<Func>::name;
99 #endif
100 
101  return createFunction(kernelName);
102  }
103 
119  virtual void destroyFunction(Function* function) = 0;
120 
126  virtual std::string getMuBinaryPath() const = 0;
127 
133  virtual uint32_t getNumMuFunctions() const = 0;
134 
140  virtual std::vector<std::string> getMuFunctionList() const = 0;
141 
142 protected:
143  Module() = default;
144  virtual ~Module() = default;
145 };
146 
158 Module* createModule(const char* muBinaryPath);
159 
166 Module* createModule(const void* image);
167 
184 
190 void destroyModule(Module* module);
191 
202 void registerKernelBinary(const void* start, const void* end);
203 
204 } // namespace pxl
Defines a function to be executed by each thread on the MU.
Definition: function.hpp:23
A container for Function of MU kernel binary.
Definition: module.hpp:46
virtual ~Module()=default
Function * createFunction()
Creates a Function object via compile-time KernelTraits lookup.
Definition: module.hpp:89
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:13
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:32