Skip to content

Commit

Permalink
Merge pull request #507 from Cytnx-dev/templatise_fill
Browse files Browse the repository at this point in the history
Templatise `Fill_cpu()` and `Fill_gpu()` and increase block size
  • Loading branch information
IvanaGyro authored Nov 19, 2024
2 parents 6ff4e31 + eed01c2 commit 7fd2551
Show file tree
Hide file tree
Showing 16 changed files with 291 additions and 495 deletions.
36 changes: 18 additions & 18 deletions src/backend/BoolStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -411,10 +411,10 @@ namespace cytnx {
void BoolStorage::fill(const cytnx_double &val) {
cytnx_bool tmp = val;
if (this->device == Device.cpu) {
utils_internal::Fill_cpu_b(this->Mem, (void *)(&tmp), this->len);
utils_internal::FillCpu(this->Mem, tmp, this->len);
} else {
#ifdef UNI_GPU
utils_internal::cuFill_gpu_b(this->Mem, (void *)(&tmp), this->len);
utils_internal::FillGpu(this->Mem, tmp, this->len);
#else
cytnx_error_msg(true, "[ERROR][fill] fatal internal, %s",
"storage is on gpu without CUDA support\n");
Expand All @@ -424,10 +424,10 @@ namespace cytnx {
void BoolStorage::fill(const cytnx_float &val) {
cytnx_bool tmp = val;
if (this->device == Device.cpu) {
utils_internal::Fill_cpu_b(this->Mem, (void *)(&tmp), this->len);
utils_internal::FillCpu(this->Mem, tmp, this->len);
} else {
#ifdef UNI_GPU
utils_internal::cuFill_gpu_b(this->Mem, (void *)(&tmp), this->len);
utils_internal::FillGpu(this->Mem, tmp, this->len);
#else
cytnx_error_msg(true, "[ERROR][fill] fatal internal, %s",
"storage is on gpu without CUDA support\n");
Expand All @@ -437,10 +437,10 @@ namespace cytnx {
void BoolStorage::fill(const cytnx_int64 &val) {
cytnx_bool tmp = val;
if (this->device == Device.cpu) {
utils_internal::Fill_cpu_b(this->Mem, (void *)(&tmp), this->len);
utils_internal::FillCpu(this->Mem, tmp, this->len);
} else {
#ifdef UNI_GPU
utils_internal::cuFill_gpu_b(this->Mem, (void *)(&tmp), this->len);
utils_internal::FillGpu(this->Mem, tmp, this->len);
#else
cytnx_error_msg(true, "[ERROR][fill] fatal internal, %s",
"storage is on gpu without CUDA support\n");
Expand All @@ -450,10 +450,10 @@ namespace cytnx {
void BoolStorage::fill(const cytnx_uint64 &val) {
cytnx_bool tmp = val;
if (this->device == Device.cpu) {
utils_internal::Fill_cpu_b(this->Mem, (void *)(&tmp), this->len);
utils_internal::FillCpu(this->Mem, tmp, this->len);
} else {
#ifdef UNI_GPU
utils_internal::cuFill_gpu_b(this->Mem, (void *)(&tmp), this->len);
utils_internal::FillGpu(this->Mem, tmp, this->len);
#else
cytnx_error_msg(true, "[ERROR][fill] fatal internal, %s",
"storage is on gpu without CUDA support\n");
Expand All @@ -463,10 +463,10 @@ namespace cytnx {
void BoolStorage::fill(const cytnx_int32 &val) {
cytnx_bool tmp = val;
if (this->device == Device.cpu) {
utils_internal::Fill_cpu_b(this->Mem, (void *)(&tmp), this->len);
utils_internal::FillCpu(this->Mem, tmp, this->len);
} else {
#ifdef UNI_GPU
utils_internal::cuFill_gpu_b(this->Mem, (void *)(&tmp), this->len);
utils_internal::FillGpu(this->Mem, tmp, this->len);
#else
cytnx_error_msg(true, "[ERROR][fill] fatal internal, %s",
"storage is on gpu without CUDA support\n");
Expand All @@ -476,10 +476,10 @@ namespace cytnx {
void BoolStorage::fill(const cytnx_uint32 &val) {
cytnx_bool tmp = val;
if (this->device == Device.cpu) {
utils_internal::Fill_cpu_b(this->Mem, (void *)(&tmp), this->len);
utils_internal::FillCpu(this->Mem, tmp, this->len);
} else {
#ifdef UNI_GPU
utils_internal::cuFill_gpu_b(this->Mem, (void *)(&tmp), this->len);
utils_internal::FillGpu(this->Mem, tmp, this->len);
#else
cytnx_error_msg(true, "[ERROR][fill] fatal internal, %s",
"storage is on gpu without CUDA support\n");
Expand All @@ -489,10 +489,10 @@ namespace cytnx {
void BoolStorage::fill(const cytnx_int16 &val) {
cytnx_bool tmp = val;
if (this->device == Device.cpu) {
utils_internal::Fill_cpu_b(this->Mem, (void *)(&tmp), this->len);
utils_internal::FillCpu(this->Mem, tmp, this->len);
} else {
#ifdef UNI_GPU
utils_internal::cuFill_gpu_b(this->Mem, (void *)(&tmp), this->len);
utils_internal::FillGpu(this->Mem, tmp, this->len);
#else
cytnx_error_msg(true, "[ERROR][fill] fatal internal, %s",
"storage is on gpu without CUDA support\n");
Expand All @@ -502,10 +502,10 @@ namespace cytnx {
void BoolStorage::fill(const cytnx_uint16 &val) {
cytnx_bool tmp = val;
if (this->device == Device.cpu) {
utils_internal::Fill_cpu_b(this->Mem, (void *)(&tmp), this->len);
utils_internal::FillCpu(this->Mem, tmp, this->len);
} else {
#ifdef UNI_GPU
utils_internal::cuFill_gpu_b(this->Mem, (void *)(&tmp), this->len);
utils_internal::FillGpu(this->Mem, tmp, this->len);
#else
cytnx_error_msg(true, "[ERROR][fill] fatal internal, %s",
"storage is on gpu without CUDA support\n");
Expand All @@ -514,10 +514,10 @@ namespace cytnx {
}
void BoolStorage::fill(const cytnx_bool &val) {
if (this->device == Device.cpu) {
utils_internal::Fill_cpu_b(this->Mem, (void *)(&val), this->len);
utils_internal::FillCpu(this->Mem, val, this->len);
} else {
#ifdef UNI_GPU
utils_internal::cuFill_gpu_b(this->Mem, (void *)(&val), this->len);
utils_internal::FillGpu(this->Mem, val, this->len);
#else
cytnx_error_msg(true, "[ERROR][fill] fatal internal, %s",
"storage is on gpu without CUDA support\n");
Expand Down
44 changes: 22 additions & 22 deletions src/backend/ComplexDoubleStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -395,11 +395,11 @@ namespace cytnx {

void ComplexDoubleStorage::fill(const cytnx_complex128 &val) {
if (this->device == Device.cpu) {
utils_internal::Fill_cpu_cd(this->Mem, (void *)(&val), this->len);
utils_internal::FillCpu(this->Mem, val, this->len);
} else {
#ifdef UNI_GPU
checkCudaErrors(cudaSetDevice(this->device));
utils_internal::cuFill_gpu_cd(this->Mem, (void *)(&val), this->len);
utils_internal::FillGpu(this->Mem, val, this->len);
#else
cytnx_error_msg(true, "[ERROR][fill] fatal internal, %s",
"storage is on gpu without CUDA support\n");
Expand All @@ -409,11 +409,11 @@ namespace cytnx {
void ComplexDoubleStorage::fill(const cytnx_complex64 &val) {
cytnx_complex128 tmp(val.real(), val.imag());
if (this->device == Device.cpu) {
utils_internal::Fill_cpu_cd(this->Mem, (void *)(&tmp), this->len);
utils_internal::FillCpu(this->Mem, tmp, this->len);
} else {
#ifdef UNI_GPU
checkCudaErrors(cudaSetDevice(this->device));
utils_internal::cuFill_gpu_cd(this->Mem, (void *)(&tmp), this->len);
utils_internal::FillGpu(this->Mem, tmp, this->len);
#else
cytnx_error_msg(true, "[ERROR][fill] fatal internal, %s",
"storage is on gpu without CUDA support\n");
Expand All @@ -423,11 +423,11 @@ namespace cytnx {
void ComplexDoubleStorage::fill(const cytnx_double &val) {
cytnx_complex128 tmp(val, 0);
if (this->device == Device.cpu) {
utils_internal::Fill_cpu_cd(this->Mem, (void *)(&tmp), this->len);
utils_internal::FillCpu(this->Mem, tmp, this->len);
} else {
#ifdef UNI_GPU
checkCudaErrors(cudaSetDevice(this->device));
utils_internal::cuFill_gpu_cd(this->Mem, (void *)(&tmp), this->len);
utils_internal::FillGpu(this->Mem, tmp, this->len);
#else
cytnx_error_msg(true, "[ERROR][fill] fatal internal, %s",
"storage is on gpu without CUDA support\n");
Expand All @@ -437,11 +437,11 @@ namespace cytnx {
void ComplexDoubleStorage::fill(const cytnx_float &val) {
cytnx_complex128 tmp(val, 0);
if (this->device == Device.cpu) {
utils_internal::Fill_cpu_cd(this->Mem, (void *)(&tmp), this->len);
utils_internal::FillCpu(this->Mem, tmp, this->len);
} else {
#ifdef UNI_GPU
checkCudaErrors(cudaSetDevice(this->device));
utils_internal::cuFill_gpu_cd(this->Mem, (void *)(&tmp), this->len);
utils_internal::FillGpu(this->Mem, tmp, this->len);
#else
cytnx_error_msg(true, "[ERROR][fill] fatal internal, %s",
"storage is on gpu without CUDA support\n");
Expand All @@ -451,11 +451,11 @@ namespace cytnx {
void ComplexDoubleStorage::fill(const cytnx_int64 &val) {
cytnx_complex128 tmp(val, 0);
if (this->device == Device.cpu) {
utils_internal::Fill_cpu_cd(this->Mem, (void *)(&tmp), this->len);
utils_internal::FillCpu(this->Mem, tmp, this->len);
} else {
#ifdef UNI_GPU
checkCudaErrors(cudaSetDevice(this->device));
utils_internal::cuFill_gpu_cd(this->Mem, (void *)(&tmp), this->len);
utils_internal::FillGpu(this->Mem, tmp, this->len);
#else
cytnx_error_msg(true, "[ERROR][fill] fatal internal, %s",
"storage is on gpu without CUDA support\n");
Expand All @@ -465,11 +465,11 @@ namespace cytnx {
void ComplexDoubleStorage::fill(const cytnx_uint64 &val) {
cytnx_complex128 tmp(val, 0);
if (this->device == Device.cpu) {
utils_internal::Fill_cpu_cd(this->Mem, (void *)(&tmp), this->len);
utils_internal::FillCpu(this->Mem, tmp, this->len);
} else {
#ifdef UNI_GPU
checkCudaErrors(cudaSetDevice(this->device));
utils_internal::cuFill_gpu_cd(this->Mem, (void *)(&tmp), this->len);
utils_internal::FillGpu(this->Mem, tmp, this->len);
#else
cytnx_error_msg(true, "[ERROR][fill] fatal internal, %s",
"storage is on gpu without CUDA support\n");
Expand All @@ -479,11 +479,11 @@ namespace cytnx {
void ComplexDoubleStorage::fill(const cytnx_int32 &val) {
cytnx_complex128 tmp(val, 0);
if (this->device == Device.cpu) {
utils_internal::Fill_cpu_cd(this->Mem, (void *)(&tmp), this->len);
utils_internal::FillCpu(this->Mem, tmp, this->len);
} else {
#ifdef UNI_GPU
checkCudaErrors(cudaSetDevice(this->device));
utils_internal::cuFill_gpu_cd(this->Mem, (void *)(&tmp), this->len);
utils_internal::FillGpu(this->Mem, tmp, this->len);
#else
cytnx_error_msg(true, "[ERROR][fill] fatal internal, %s",
"storage is on gpu without CUDA support\n");
Expand All @@ -493,11 +493,11 @@ namespace cytnx {
void ComplexDoubleStorage::fill(const cytnx_uint32 &val) {
cytnx_complex128 tmp(val, 0);
if (this->device == Device.cpu) {
utils_internal::Fill_cpu_cd(this->Mem, (void *)(&tmp), this->len);
utils_internal::FillCpu(this->Mem, tmp, this->len);
} else {
#ifdef UNI_GPU
checkCudaErrors(cudaSetDevice(this->device));
utils_internal::cuFill_gpu_cd(this->Mem, (void *)(&tmp), this->len);
utils_internal::FillGpu(this->Mem, tmp, this->len);
#else
cytnx_error_msg(true, "[ERROR][fill] fatal internal, %s",
"storage is on gpu without CUDA support\n");
Expand All @@ -507,11 +507,11 @@ namespace cytnx {
void ComplexDoubleStorage::fill(const cytnx_int16 &val) {
cytnx_complex128 tmp(val, 0);
if (this->device == Device.cpu) {
utils_internal::Fill_cpu_cd(this->Mem, (void *)(&tmp), this->len);
utils_internal::FillCpu(this->Mem, tmp, this->len);
} else {
#ifdef UNI_GPU
checkCudaErrors(cudaSetDevice(this->device));
utils_internal::cuFill_gpu_cd(this->Mem, (void *)(&tmp), this->len);
utils_internal::FillGpu(this->Mem, tmp, this->len);
#else
cytnx_error_msg(true, "[ERROR][fill] fatal internal, %s",
"storage is on gpu without CUDA support\n");
Expand All @@ -521,11 +521,11 @@ namespace cytnx {
void ComplexDoubleStorage::fill(const cytnx_uint16 &val) {
cytnx_complex128 tmp(val, 0);
if (this->device == Device.cpu) {
utils_internal::Fill_cpu_cd(this->Mem, (void *)(&tmp), this->len);
utils_internal::FillCpu(this->Mem, tmp, this->len);
} else {
#ifdef UNI_GPU
checkCudaErrors(cudaSetDevice(this->device));
utils_internal::cuFill_gpu_cd(this->Mem, (void *)(&tmp), this->len);
utils_internal::FillGpu(this->Mem, tmp, this->len);
#else
cytnx_error_msg(true, "[ERROR][fill] fatal internal, %s",
"storage is on gpu without CUDA support\n");
Expand All @@ -535,11 +535,11 @@ namespace cytnx {
void ComplexDoubleStorage::fill(const cytnx_bool &val) {
cytnx_complex128 tmp(val, 0);
if (this->device == Device.cpu) {
utils_internal::Fill_cpu_cd(this->Mem, (void *)(&tmp), this->len);
utils_internal::FillCpu(this->Mem, tmp, this->len);
} else {
#ifdef UNI_GPU
checkCudaErrors(cudaSetDevice(this->device));
utils_internal::cuFill_gpu_cd(this->Mem, (void *)(&tmp), this->len);
utils_internal::FillGpu(this->Mem, tmp, this->len);
#else
cytnx_error_msg(true, "[ERROR][fill] fatal internal, %s",
"storage is on gpu without CUDA support\n");
Expand Down
Loading

0 comments on commit 7fd2551

Please sign in to comment.