PXL
job.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 <cstddef>
6 #include <cstdint>
7 #include <functional>
8 #include <vector>
9 
10 #include "pxl/memory.hpp"
11 #include "pxl/type.hpp"
12 
13 namespace pxl
14 {
15 class Module;
16 class Function;
17 class Context;
18 class Map;
19 
31 class Job
32 {
33 public:
40  using AsyncCallback = std::function<void(Job* job, void* arg)>;
41 
45  Job(const Job&) = delete;
46 
50  Job& operator=(const Job&) = delete;
51 
68  virtual Result load(const char* muBinaryPath) = 0;
69 
88  virtual Result load(const pxl::Module* module) = 0;
89 
95  virtual bool isLoaded() const = 0;
96 
102  virtual const std::vector<uint32_t> subIdList() const = 0;
103 
116  virtual Map* buildMap(const char* muFuncName, const uint32_t taskCount) = 0;
117 
132  virtual Map* buildMap(const pxl::Function* muFunc, const uint32_t taskCount) = 0;
133 
146  virtual Map* buildMap(const uint32_t taskCount) = 0;
147 
165  virtual void destroyMap(Map* map) = 0;
166 
170  virtual uint64_t id() const = 0;
171 
175  virtual uint32_t deviceId() const = 0;
176 
177  // reload() is declared at the tail of the interface, not beside load():
178  // new virtuals must append to the vtable end to preserve ABI for callers
179  // linked against an earlier header.
180 
197  virtual Result reload(const char* muBinaryPath) = 0;
198 
208  virtual Result reload(const pxl::Module* module) = 0;
209 
223  virtual void* allocateMemory(size_t size, AllocFlag flag = AllocFlag::None) = 0;
224 
233  template <typename T>
234  T* allocateMemory(size_t count, AllocFlag flag = AllocFlag::None)
235  {
236  if (count > 0 && count > SIZE_MAX / sizeof(T))
237  {
238  return nullptr;
239  }
240  return static_cast<T*>(allocateMemory(count * sizeof(T), flag));
241  }
242 
268  virtual Result remapMemory(void* ptr, uintptr_t virtualAddr) = 0;
269 
277  virtual Result unmapMemory(uintptr_t virtualAddr) = 0;
278 
279 protected:
280  Job() = default;
281  virtual ~Job() = default;
282 };
283 
284 } // namespace pxl
Defines a function to be executed by each thread on the MU.
Definition: function.hpp:22
Manages device compute resources and offloads user applications.
Definition: job.hpp:32
virtual Result unmapMemory(uintptr_t virtualAddr)=0
Removes a remapMemory mapping. The backing is not freed.
Job(const Job &)=delete
Deleted copy constructor.
virtual Result load(const char *muBinaryPath)=0
Loads binary data into this job.
std::function< void(Job *job, void *arg)> AsyncCallback
Callback type for asynchronous job creation.
Definition: job.hpp:40
virtual ~Job()=default
virtual Map * buildMap(const uint32_t taskCount)=0
create a map object from the job.
virtual void destroyMap(Map *map)=0
Destroys the specified map.
virtual const std::vector< uint32_t > subIdList() const =0
Returns the list of sub IDs associated with this job.
virtual Map * buildMap(const char *muFuncName, const uint32_t taskCount)=0
create a map object from the job.
virtual Result remapMemory(void *ptr, uintptr_t virtualAddr)=0
Makes this Job's private memory reachable by the kernel at a chosen address.
virtual uint32_t deviceId() const =0
Device this Job runs on.
virtual Result reload(const pxl::Module *module)=0
Swaps the loaded module on this job, keeping its Sub set.
T * allocateMemory(size_t count, AllocFlag flag=AllocFlag::None)
Allocates typed device memory used only by this Job.
Definition: job.hpp:234
virtual Result load(const pxl::Module *module)=0
Loads a module into this job.
virtual Result reload(const char *muBinaryPath)=0
Swaps the loaded binary on this job, keeping its Sub set.
Job()=default
virtual Map * buildMap(const pxl::Function *muFunc, const uint32_t taskCount)=0
create a map object from the job.
virtual void * allocateMemory(size_t size, AllocFlag flag=AllocFlag::None)=0
Allocates device memory used only by this Job.
virtual bool isLoaded() const =0
Check whether MU binary is loaded on the job.
virtual uint64_t id() const =0
Returns this Job's identifier.
Job & operator=(const Job &)=delete
Deleted copy assignment operator.
The Map class represents a map operation in the XCENA execution framework.
Definition: map.hpp:48
A container for Function of MU kernel binary.
Definition: module.hpp:44
Definition: config.hpp:11
Result
Definition: type.hpp:55