| 975 | } |
| 976 | |
| 977 | inline void allocate(const int gpu_id, const int size, bool as_byte = false) { |
| 978 | if (this->vals == nullptr) { |
| 979 | this->gpu_id = gpu_id; |
| 980 | CHECK_CUDA( cudaSetDevice(this->gpu_id) ); |
| 981 | // as_byte is used to allocate buffer size, which is usually given in terms of bytes |
| 982 | if (as_byte) { |
| 983 | this->size = (size + sizeof(float) - 1) / sizeof(float); |
| 984 | } else { |
| 985 | this->size = size; |
| 986 | } |
| 987 | CHECK_CUDA( cudaMalloc((void**) &this->vals, sizeof(float) * this->size) ); |
| 988 | CHECK_CUSPARSE( cusparseCreateDnVec(&this->cusparse_descr, this->size, this->vals, CUDA_R_32F) ); |
| 989 | } |
| 990 | return; |
| 991 | } |
| 992 | inline float get_norm(const DeviceBlasHandle& cublas_H) { |
| 993 | float norm; |
| 994 | CHECK_CUDA( cudaSetDevice(this->gpu_id) ); |