|
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... | |
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 26 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 37 of file context.hpp.
|
delete |
Deleted copy constructor.
|
protecteddefault |
|
protectedvirtualdefault |
|
pure virtual |
Returns the available memory size of the device.
|
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 |
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.
Declared last among the virtuals on purpose: appending it keeps the vtable slots of all pre-existing methods stable, so a binary compiled against an older Context layout is not silently misdirected.
| ptr | Pointer to the memory to resize (may be nullptr). |
| size | New size in bytes. |
Example usage: