MCPcopy Create free account
hub / github.com/ComputationalRobotics/XM-code / DeviceDnVecInt

Class DeviceDnVecInt

XM/include/Utils/memory.h:1016–1045  ·  view source on GitHub ↗

dense vector wrapper on device: int type

Source from the content-addressed store, hash-verified

1014
1015// dense vector wrapper on device: int type
1016class DeviceDnVecInt {
1017 public:
1018 int gpu_id;
1019 int size;
1020 int* vals;
1021
1022 DeviceDnVecInt(): gpu_id(0), size(0), vals(nullptr) {}
1023 DeviceDnVecInt(const int gpu_id, const int size): gpu_id(gpu_id), size(size), vals(nullptr) {
1024 this->allocate(this->gpu_id, this->size);
1025 }
1026
1027 inline void allocate(const int gpu_id, const int size) {
1028 if (this->vals == nullptr) {
1029 this->gpu_id = gpu_id;
1030 this->size = size;
1031 CHECK_CUDA( cudaSetDevice(this->gpu_id) );
1032 CHECK_CUDA( cudaMalloc((void**) &this->vals, sizeof(int) * this->size) );
1033 }
1034 return;
1035 }
1036
1037 ~DeviceDnVecInt() {
1038 CHECK_CUDA( cudaSetDevice(this->gpu_id) );
1039 if (this->vals != nullptr) {
1040 CHECK_CUDA( cudaFree(this->vals) );
1041 this->vals = nullptr;
1042 }
1043 // std::cout << "DeviceDnVecInt destructor called!" << std::endl;
1044 }
1045};
1046
1047// dense vector wrapper on device: long int type
1048class DeviceDnVecLongInt {

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected