| 522 | } |
| 523 | |
| 524 | inline void allocate() { |
| 525 | if (this->vals == nullptr) { |
| 526 | CHECK_CUDA( cudaSetDevice(this->gpu_id) ); |
| 527 | CHECK_CUDA( cudaMalloc((void**) &this->col_ptrs, sizeof(int) * (this->col_size + 1)) ); |
| 528 | CHECK_CUDA( cudaMalloc((void**) &this->row_ids, sizeof(int) * this->nnz) ); |
| 529 | CHECK_CUDA( cudaMalloc((void**) &this->vals, sizeof(T) * this->nnz) ); |
| 530 | CHECK_CUSPARSE( cusparseCreateCsc( |
| 531 | &this->cusparse_descr, this->row_size, this->col_size, this->nnz, |
| 532 | this->col_ptrs, this->row_ids, this->vals, |
| 533 | CUSPARSE_INDEX_32I, CUSPARSE_INDEX_32I, CUSPARSE_INDEX_BASE_ZERO, CudaTypeMapper<T>::value |
| 534 | ) ); |
| 535 | } |
| 536 | return; |
| 537 | } |
| 538 | |
| 539 | void SynchronizeHostToDevice(int* host_col_ptrs, int* host_row_ids, T* host_val){ |
| 540 | // always Synchronize to avoid read-write conflict |