| 597 | } |
| 598 | |
| 599 | inline void allocate() { |
| 600 | if (this->vals == nullptr) { |
| 601 | CHECK_CUDA( cudaSetDevice(this->gpu_id) ); |
| 602 | CHECK_CUDA( cudaSetDevice(this->gpu_id) ); |
| 603 | CHECK_CUDA( cudaMalloc((void**) &this->row_ptrs, sizeof(int) * (this->row_size + 1)) ); |
| 604 | if (nnz > 0) { |
| 605 | CHECK_CUDA( cudaMalloc((void**) &this->col_ids, sizeof(int) * this->nnz) ); |
| 606 | CHECK_CUDA( cudaMalloc((void**) &this->vals, sizeof(T) * this->nnz) ); |
| 607 | } else { |
| 608 | this->col_ids = nullptr; |
| 609 | this->vals = nullptr; |
| 610 | } |
| 611 | CHECK_CUSPARSE( cusparseCreateCsr( |
| 612 | &this->cusparse_descr, this->row_size, this->col_size, this->nnz, |
| 613 | this->row_ptrs, this->col_ids, this->vals, |
| 614 | CUSPARSE_INDEX_32I, CUSPARSE_INDEX_32I, CUSPARSE_INDEX_BASE_ZERO, CudaTypeMapper<T>::value |
| 615 | ) ); |
| 616 | } |
| 617 | } |
| 618 | |
| 619 | void SynchronizeHostToDevice(int* host_col_ids, int* host_row_ptrs, T* host_val){ |
| 620 | // always Synchronize to avoid read-write conflict |