Template Function shad::rt::asyncExecuteAtWithRetBuff(Handle&, const Locality&, FunT&&, const std::shared_ptr<uint8_t>&, const uint32_t, uint8_t *, uint32_t *)¶
- Defined in File runtime.h
Function Documentation¶
-
template <typename FunT>
voidshad::rt
::
asyncExecuteAtWithRetBuff
(Handle &handle, const Locality &loc, FunT &&func, const std::shared_ptr<uint8_t> &argsBuffer, const uint32_t bufferSize, uint8_t *resultBuffer, uint32_t *resultSize)¶ Execute a function on a selected locality asynchronously and return a result buffer.
Typical Usage:
struct Args { int a; char b; }; void task(Handle & handle, const uint8_t *src, const uint32_t size, const uint8_t *dst, uint32_t * outsize) { memcpy(src, dst, size); *outsize = size; } Args args { 2, 'a' }; /* Args doesn't need a dynamic allocated buffer but * more complicated data structure might need it */ std::shared_ptr<uint8_t> ptr(new uint8_t[sizeof(Args)], std::default_delete<uint8_t[]>()); memcpy(ptr.get(), &args, sizeof(Args)); std::vector<std::unique_ptr<uint8_t[]>> outBuffers(numLocalities()); std::vector<uint32_t> outSizes(numLocalities(), 0); for (auto & vecPtr : outBuffers) { std::unique_ptr<uint8_t[]> outbuff(new uint8_t[sizeof(Args)]); vecPtr = std::move(outbuff); } Handle handle; for (auto & locality : allLocalities) { if (static_cast<uint32_t>(locality) % 2) // every call will overwrite outbuff asyncExecuteAtWithRetBuff( handle, locality, task, ptr, sizeof(Args), outBuffers[localityID].get(), &outSizes[localityID]); } waitForCompletion(handle);
- Template Parameters
FunT
: The type of the function to be executed. The function prototype must be:void(Handle &, const uint8_t *, const uint32_t, const uint8_t *, uint32_t *)
- Parameters
handle
: An Handle for the associated task-group.loc
: The Locality where the function must be executed.func
: The function to execute.argsBuffer
: A buffer of bytes to be passed to the function.bufferSize
: The size of the buffer argsBuffer passed.resultBuffer
: The buffer where to store the results.resultSize
: The location where the runtime will store the number of bytes written in the result buffer