15 #ifndef HTGS_CUDATASK_HPP 16 #define HTGS_CUDATASK_HPP 18 #include <cuda_runtime_api.h> 21 #include <unordered_map> 119 template<
class T,
class U>
121 static_assert(std::is_base_of<IData, T>::value,
"T must derive from IData");
122 static_assert(std::is_base_of<IData, U>::value,
"U must derive from IData");
155 virtual void executeTask(std::shared_ptr<T> data) = 0;
167 return "Unnamed GPU ITask";
257 cudaMemcpyPeerAsync((
void *) destination,
259 (
void *) data->get(),
260 this->
cudaIds[data->getPipelineId()],
261 sizeof(V) * numElems,
277 cudaGetDeviceCount(&numGpus);
279 HTGS_ASSERT(this->
cudaId < numGpus,
"Error: Cuda ID: " << std::to_string(this->
cudaId) <<
" is larger than the number of GPUs: " << std::to_string(numGpus));
281 cudaSetDevice(this->
cudaId);
282 cudaStreamCreate(&
stream);
286 for (
size_t i = 0; i < this->
numGpus; i++) {
288 if (peerId != this->
cudaId) {
290 cudaDeviceCanAccessPeer(&canAccess, this->
cudaId, peerId);
293 cudaDeviceEnablePeerAccess(peerId, 0);
310 cudaStreamDestroy(
stream);
343 cudaStreamSynchronize(
stream);
357 #endif //HTGS_CUDATASK_HPP bool autoCopy(V *destination, std::shared_ptr< MemoryData< V >> data, long numElems)
Will automatically copy from one GPU to another (if it is required).
Definition: ICudaTask.hpp:254
int getCudaId()
Gets the Cuda Id for this cudaTask.
Definition: ICudaTask.hpp:200
bool requiresCopy(size_t pipelineId)
Checks if the requested pipelineId requires GPU-to-GPU copy.
Definition: ICudaTask.hpp:211
bool requiresCopy(std::shared_ptr< MemoryData< V >> data)
Checks if the requested pipelineId requires GPU-to-GPU copy.
Definition: ICudaTask.hpp:225
void initialize() override final
Initializes the CudaTask to be bound to a particular GPU.
Definition: ICudaTask.hpp:273
cudaStream_t stream
The CUDA stream for the ICudaTask (set after initialize)
Definition: ICudaTask.hpp:347
virtual void debug() override
Virtual function that can be used to provide debug information.
Definition: ICudaTask.hpp:189
int cudaId
The CudaID for the ICudaTask (set after initialize)
Definition: ICudaTask.hpp:351
Describes memory allocated by a MemoryManager to manage shared memory across multiple ITask...
Definition: ICudaTask.hpp:28
size_t numGpus
The number of GPUs.
Definition: ICudaTask.hpp:350
size_t getNumGPUs()
Gets the number of GPUs specified during ICudaTask construction.
Definition: ICudaTask.hpp:333
int * getCudaIds()
Gets the cudaIds specified during ICudaTask construction.
Definition: ICudaTask.hpp:325
void shutdown() override final
Shutsdown the ICudaTask.
Definition: ICudaTask.hpp:308
virtual void executeTask(std::shared_ptr< T > data)=0
Executes the ICudaTask on some data.
size_t getPipelineId()
Gets the pipeline ID.
Definition: AnyITask.hpp:367
const cudaStream_t & getStream() const
Gets the CUDA stream for this CUDA task.
Definition: ICudaTask.hpp:317
ICudaTask(int *cudaIds, size_t numGpus, bool autoEnablePeerAccess=true)
Creates an ICudaTask.
Definition: ICudaTask.hpp:135
An interface to process input data and forward results within a TaskGraph.
Definition: ITask.hpp:165
virtual void initializeCudaGPU()
Virtual function that is called when the ICudaTask has been initialized and is bound to a CUDA GPU...
Definition: ICudaTask.hpp:149
int * cudaIds
The array of cuda Ids (one per GPU)
Definition: ICudaTask.hpp:348
#define HTGS_ASSERT(condition, message)
Prints a more meaningful assertion message and terminates if the condition fails. ...
Definition: debug_message.hpp:25
void syncStream()
Synchronizes the Cuda stream associated with this task.
Definition: ICudaTask.hpp:342
std::vector< int > nonPeerDevIds
The list of CudaIds that do not have peer-to-peer access.
Definition: ICudaTask.hpp:352
virtual std::string getName() override
Virtual function that gets the name of this ICudaTask.
Definition: ICudaTask.hpp:166
An ICudaTask is used to attach a task to an NVIDIA Cuda GPU.
Definition: ICudaTask.hpp:120
bool autoEnablePeerAccess
Flag to automatically enables peer access between multiple GPUs.
Definition: ICudaTask.hpp:353
std::string getDotFillColor() override
Gets the color for filling the shape for graphviz dot.
Definition: ICudaTask.hpp:170
size_t pipelineId
The execution pipeline id for the ITask.
Definition: AnyITask.hpp:604
An interface to process input data and forward results within a TaskGraph.
virtual ITask< T, U > * copy()=0
Pure virtual function that copies this ICudaTask.
bool hasPeerToPeerCopy(size_t pipelineId)
Checks if the requested pipelineId allows peer to peer GPU copy.
Definition: ICudaTask.hpp:236
Definition: Bookkeeper.hpp:23
virtual void shutdownCuda()
Virtual function that is called when the ICudaTask is shutting down.
Definition: ICudaTask.hpp:160