|
PXL
|
An execution abstraction of a Device object. More...
#include <context.hpp>
Public Types | |
| using | AsyncCallback = std::function< void(Job *job, void *arg)> |
| Callback function type for job creation. More... | |
Public Member Functions | |
| Context (const Context &)=delete | |
| Deleted copy constructor. More... | |
| Context & | operator= (const Context &)=delete |
| Deleted copy assignment operator. More... | |
| virtual Job * | createJob ()=0 |
| Creates a new job with the default number of sub. More... | |
| virtual Job * | createJob (const uint32_t numSub)=0 |
| Creates a new job with the specified number of sub. More... | |
| virtual Result | createJobForceAsync (const uint32_t numSub, const AsyncCallback &callback, void *arg, uint32_t timeout=0)=0 |
| Creates a new job with the specified number of sub asynchronously. More... | |
| virtual Result | destroyJob (Job *job)=0 |
| Destroys the specified job. More... | |
| virtual void * | memAlloc (const size_t size)=0 |
| Allocates memory on the device. More... | |
| virtual void * | memCalloc (const size_t num, const size_t size)=0 |
| Allocates zero-initialized memory on the device. More... | |
| virtual void | memFree (const void *ptr)=0 |
| Frees previously allocated memory on the device. More... | |
| virtual uint32_t | deviceId () const =0 |
| Returns the ID of the device. More... | |
| virtual uint32_t | availableSubCount () const =0 |
| Returns the available number of Sub. More... | |
| virtual uint64_t | availableMemSize () const =0 |
| Returns the available memory size of the device. More... | |
| virtual Result | getAttribute (DeviceAttr attr, uint64_t &value) const =0 |
| Returns information about the device attribute. More... | |
| virtual void * | memRealloc (void *ptr, const size_t size)=0 |
| Resizes previously allocated device memory. More... | |
| virtual MemoryUsage_t | memoryUsage () const =0 |
| Returns the device's CXL memory by state. More... | |
Protected Member Functions | |
| Context ()=default | |
| virtual | ~Context ()=default |
An execution abstraction of a Device object.
The Context class provides an execution abstraction for a specific device, identified by its ID. It offers functionality for:
Definition at line 28 of file context.hpp.
| using pxl::Context::AsyncCallback = std::function<void(Job* job, void* arg)> |
Callback function type for job creation.
| job | Pointer to the created job. |
| arg | Argument to be passed to the callback function. |
This callback is called when a job is created.
Definition at line 39 of file context.hpp.
|
delete |
Deleted copy constructor.
|
protecteddefault |
|
protectedvirtualdefault |
|
pure virtual |
Returns the available memory size of the device.
Memory still being released is not included; see memoryUsage(). On a device without CXL memory this is the IO memory memAlloc serves from. On a CXL device it includes free space this process holds, among it an emptied granule kept for reuse (PXL_CXL_IDLE_GRANULE_MS). A request for more than one granule may not use that space at once and can fail briefly while the daemon zeroes it.
|
pure virtual |
Returns the available number of Sub.
|
pure virtual |
Creates a new job with the default number of sub.
Each Job owns a private default stream allocated from the per-process stream pool. Returns nullptr when that pool is exhausted, so the effective concurrent-Job ceiling is shared with user-created Streams.
Example usage:
|
pure virtual |
Creates a new job with the specified number of sub.
| numSub | Number of Sub to assign to the job. |
Example usage:
|
pure virtual |
Creates a new job with the specified number of sub asynchronously.
| numSub | Number of sub to assign to the job. |
| callback | Callback function to be called when the job creation is complete. |
| arg | Argument to be passed to the callback function. |
| timeout | Timeout value for creation operation. |
If the callback throws, the exception is caught and logged on the invoking thread rather than propagated beyond the callback.
Example usage:
Destroys the specified job.
| job | Pointer to the job to be destroyed. |
This function synchronously drains every Map built from the job (waiting for any in-flight map executions) before freeing it.
When called from a completion, error, or message callback for one of this Job's Maps, this function cannot drain the Job because the callback itself is part of the outstanding work. In that case, it returns Result::Cancelled and leaves the Job valid. Retry from a thread that can wait after the callback returns. Unrelated callbacks are not subject to this restriction; for example, a createJobForceAsync() callback can destroy the Job it just received.
Example usage:
|
pure virtual |
Returns the ID of the device.
Example usage:
|
pure virtual |
Returns information about the device attribute.
| attr | Device attribute to query. |
| value | Reference to store the attribute value. |
Example usage:
|
pure virtual |
Allocates memory on the device.
| size | Size of the memory to allocate. |
Example usage:
|
pure virtual |
Allocates zero-initialized memory on the device.
This function allocates an array of num elements, each of size size, and initializes all bytes in the allocated storage to zero.
| num | Number of elements to allocate. |
| size | Size of each element. |
Example usage:
|
pure virtual |
Frees previously allocated memory on the device.
| ptr | Pointer to the memory to free. |
Example usage:
|
pure virtual |
Returns the device's CXL memory by state.
On a CXL device, availableMemSize() also counts free space inside memory this process holds, which this leaves in used. That includes an emptied granule kept for reuse, which other processes see as used too. A device without CXL memory reports all zero here while availableMemSize() reports its IO memory. An allocation that fails while releasing is non-zero can succeed shortly after.
Appended after memRealloc() for the same reason.
|
pure virtual |
Resizes previously allocated device memory.
Mirrors C realloc: tries an in-place resize, otherwise relocates with a copy. memRealloc(nullptr, size) allocates; memRealloc(ptr, 0) frees and returns nullptr. On failure the original pointer is left intact.
Appended after the virtuals that predate it on purpose: their vtable slots stay where binaries built against them expect.
| ptr | Pointer to the memory to resize (may be nullptr). |
| size | New size in bytes. |
Example usage: