| 686 | } |
| 687 | |
| 688 | inline void allocate() { |
| 689 | if (this->vals == nullptr) { |
| 690 | CHECK_CUDA( cudaSetDevice(this->gpu_id) ); |
| 691 | CHECK_CUDA( cudaSetDevice(this->gpu_id) ); |
| 692 | |
| 693 | if (nnz > 0) { |
| 694 | CHECK_CUDA( cudaMalloc((void**) &this->row_ids, sizeof(int) * this->nnz) ); |
| 695 | CHECK_CUDA( cudaMalloc((void**) &this->col_ids, sizeof(int) * this->nnz) ); |
| 696 | CHECK_CUDA( cudaMalloc((void**) &this->vals, sizeof(T) * this->nnz) ); |
| 697 | } else { |
| 698 | this->row_ids = nullptr; |
| 699 | this->col_ids = nullptr; |
| 700 | this->vals = nullptr; |
| 701 | } |
| 702 | CHECK_CUSPARSE( cusparseCreateCoo( |
| 703 | &this->cusparse_descr, this->row_size, this->col_size, this->nnz, |
| 704 | this->row_ids, this->col_ids, this->vals, |
| 705 | CUSPARSE_INDEX_32I, CUSPARSE_INDEX_BASE_ZERO, CudaTypeMapper<T>::value |
| 706 | ) ); |
| 707 | } |
| 708 | } |
| 709 | |
| 710 | void SynchronizeHostToDevice(int* host_col_ids, int* host_row_ids, T* host_val){ |
| 711 | // always Synchronize to avoid read-write conflict |