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 
6 #include <cstddef>
7 #include <cstdint>
8 #include <functional>
9 #include <pxl/v3_api_guard.hpp>
10 #include <vector>
11 
12 #include "pxl/memory.hpp"
13 #include "pxl/type.hpp"
14 
15 namespace pxl
16 {
17 class Module;
18 class Function;
19 class Context;
20 class Map;
21 
33 class Job
34 {
35 public:
42  using AsyncCallback = std::function<void(Job* job, void* arg)>;
43 
47  Job(const Job&) = delete;
48 
52  Job& operator=(const Job&) = delete;
53 
70  virtual Result load(const char* muBinaryPath) = 0;
71 
90  virtual Result load(const pxl::Module* module) = 0;
91 
97  virtual bool isLoaded() const = 0;
98 
104  virtual const std::vector<uint32_t> subIdList() const = 0;
105 
118  virtual Map* buildMap(const char* muFuncName, const uint32_t taskCount) = 0;
119 
134  virtual Map* buildMap(const pxl::Function* muFunc, const uint32_t taskCount) = 0;
135 
148  virtual Map* buildMap(const uint32_t taskCount) = 0;
149 
167  virtual void destroyMap(Map* map) = 0;
168 
172  virtual uint64_t id() const = 0;
173 
177  virtual uint32_t deviceId() const = 0;
178 
179  // reload() is declared at the tail of the interface, not beside load():
180  // new virtuals must append to the vtable end to preserve ABI for callers
181  // linked against an earlier header.
182 
202  virtual Result reload(const char* muBinaryPath) = 0;
203 
213  virtual Result reload(const pxl::Module* module) = 0;
214 
228  virtual void* allocateMemory(size_t size, AllocFlag flag = AllocFlag::None) = 0;
229 
238  template <typename T>
239  T* allocateMemory(size_t count, AllocFlag flag = AllocFlag::None)
240  {
241  if (count > 0 && count > SIZE_MAX / sizeof(T))
242  {
243  return nullptr;
244  }
245  return static_cast<T*>(allocateMemory(count * sizeof(T), flag));
246  }
247 
273  virtual Result remapMemory(void* ptr, uintptr_t virtualAddr) = 0;
274 
282  virtual Result unmapMemory(uintptr_t virtualAddr) = 0;
283 
310  virtual Result setMuCoreCountPerSub(uint32_t count) = 0;
311 
312 protected:
313  Job() = default;
314  virtual ~Job() = default;
315 };
316 
317 } // namespace pxl
Defines a function to be executed by each thread on the MU.
Definition: function.hpp:23
Manages device compute resources and offloads user applications.
Definition: job.hpp:34
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:42
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.
virtual Result setMuCoreCountPerSub(uint32_t count)=0
Caps how many MU cores of each of this Job's Subs run tasks.
T * allocateMemory(size_t count, AllocFlag flag=AllocFlag::None)
Allocates typed device memory used only by this Job.
Definition: job.hpp:239
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:50
A container for Function of MU kernel binary.
Definition: module.hpp:46
Definition: config.hpp:13
Result
Definition: type.hpp:70