Skip to content

Commit

Permalink
Merge pull request #504 from Cytnx-dev/templatise_functions
Browse files Browse the repository at this point in the history
Refactor: Templatise `Movemem()` function
  • Loading branch information
IvanaGyro authored Nov 19, 2024
2 parents 0b510a6 + 83b07ca commit 6ff4e31
Show file tree
Hide file tree
Showing 15 changed files with 294 additions and 1,284 deletions.
8 changes: 4 additions & 4 deletions src/backend/BoolStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,10 +89,10 @@ namespace cytnx {
const std::vector<cytnx_uint64> &invmapper) {
boost::intrusive_ptr<Storage_base> tmp(this);
if (this->device == Device.cpu) {
utils_internal::Movemem_cpu_b(tmp, old_shape, mapper, invmapper, 1);
utils_internal::MoveMemoryCpu<cytnx_bool>(tmp, old_shape, mapper, invmapper, 1);
} else {
#ifdef UNI_GPU
utils_internal::cuMovemem_gpu_b(tmp, old_shape, mapper, invmapper, 1);
utils_internal::MoveMemoryGpu<cytnx_bool>(tmp, old_shape, mapper, invmapper, 1);
#else
cytnx_error_msg(1, "%s", "[ERROR][Internal] try to call GPU section without CUDA support");
#endif
Expand All @@ -104,10 +104,10 @@ namespace cytnx {
const std::vector<cytnx_uint64> &invmapper) {
boost::intrusive_ptr<Storage_base> tmp(this);
if (this->device == Device.cpu) {
return utils_internal::Movemem_cpu_b(tmp, old_shape, mapper, invmapper, 0);
return utils_internal::MoveMemoryCpu<cytnx_bool>(tmp, old_shape, mapper, invmapper, 0);
} else {
#ifdef UNI_GPU
return utils_internal::cuMovemem_gpu_b(tmp, old_shape, mapper, invmapper, 0);
return utils_internal::MoveMemoryGpu<cytnx_bool>(tmp, old_shape, mapper, invmapper, 0);
#else
cytnx_error_msg(1, "%s", "[ERROR][Internal] try to call GPU section without CUDA support");
return nullptr;
Expand Down
8 changes: 4 additions & 4 deletions src/backend/ComplexDoubleStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,11 +90,11 @@ namespace cytnx {
const std::vector<cytnx_uint64> &invmapper) {
boost::intrusive_ptr<Storage_base> tmp(this);
if (this->device == Device.cpu) {
utils_internal::Movemem_cpu_cd(tmp, old_shape, mapper, invmapper, 1);
utils_internal::MoveMemoryCpu<cytnx_complex128>(tmp, old_shape, mapper, invmapper, 1);
} else {
#ifdef UNI_GPU
checkCudaErrors(cudaSetDevice(this->device));
utils_internal::cuMovemem_gpu_cd(tmp, old_shape, mapper, invmapper, 1);
utils_internal::MoveMemoryGpu<cytnx_complex128>(tmp, old_shape, mapper, invmapper, 1);
#else
cytnx_error_msg(1, "%s", "[ERROR][Internal] try to call GPU section without CUDA support");
#endif
Expand All @@ -106,11 +106,11 @@ namespace cytnx {
const std::vector<cytnx_uint64> &invmapper) {
boost::intrusive_ptr<Storage_base> tmp(this);
if (this->device == Device.cpu) {
return utils_internal::Movemem_cpu_cd(tmp, old_shape, mapper, invmapper, 0);
return utils_internal::MoveMemoryCpu<cytnx_complex128>(tmp, old_shape, mapper, invmapper, 0);
} else {
#ifdef UNI_GPU
checkCudaErrors(cudaSetDevice(this->device));
return utils_internal::cuMovemem_gpu_cd(tmp, old_shape, mapper, invmapper, 0);
return utils_internal::MoveMemoryGpu<cytnx_complex128>(tmp, old_shape, mapper, invmapper, 0);
#else
cytnx_error_msg(1, "%s", "[ERROR][Internal] try to call GPU section without CUDA support");
#endif
Expand Down
8 changes: 4 additions & 4 deletions src/backend/ComplexFloatStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ namespace cytnx {
const std::vector<cytnx_uint64> &invmapper) {
boost::intrusive_ptr<Storage_base> tmp(this);
if (this->device == Device.cpu) {
utils_internal::Movemem_cpu_cf(tmp, old_shape, mapper, invmapper, 1);
utils_internal::MoveMemoryCpu<cytnx_complex64>(tmp, old_shape, mapper, invmapper, 1);
} else {
#ifdef UNI_GPU
checkCudaErrors(cudaSetDevice(this->device));
utils_internal::cuMovemem_gpu_cf(tmp, old_shape, mapper, invmapper, 1);
utils_internal::MoveMemoryGpu<cytnx_complex64>(tmp, old_shape, mapper, invmapper, 1);
#else
cytnx_error_msg(1, "%s", "[ERROR][Internal] try to call GPU section without CUDA support");
#endif
Expand All @@ -107,11 +107,11 @@ namespace cytnx {
const std::vector<cytnx_uint64> &invmapper) {
boost::intrusive_ptr<Storage_base> tmp(this);
if (this->device == Device.cpu) {
return utils_internal::Movemem_cpu_cf(tmp, old_shape, mapper, invmapper, 0);
return utils_internal::MoveMemoryCpu<cytnx_complex64>(tmp, old_shape, mapper, invmapper, 0);
} else {
#ifdef UNI_GPU
checkCudaErrors(cudaSetDevice(this->device));
return utils_internal::cuMovemem_gpu_cf(tmp, old_shape, mapper, invmapper, 0);
return utils_internal::MoveMemoryGpu<cytnx_complex64>(tmp, old_shape, mapper, invmapper, 0);
#else
cytnx_error_msg(1, "%s", "[ERROR][Internal] try to call GPU section without CUDA support");
return nullptr;
Expand Down
8 changes: 4 additions & 4 deletions src/backend/DoubleStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -93,11 +93,11 @@ namespace cytnx {
const std::vector<cytnx_uint64> &invmapper) {
boost::intrusive_ptr<Storage_base> tmp(this);
if (this->device == Device.cpu) {
utils_internal::Movemem_cpu_d(tmp, old_shape, mapper, invmapper, 1);
utils_internal::MoveMemoryCpu<cytnx_double>(tmp, old_shape, mapper, invmapper, 1);
} else {
#ifdef UNI_GPU
checkCudaErrors(cudaSetDevice(this->device));
utils_internal::cuMovemem_gpu_d(tmp, old_shape, mapper, invmapper, 1);
utils_internal::MoveMemoryGpu<cytnx_double>(tmp, old_shape, mapper, invmapper, 1);
#else
cytnx_error_msg(1, "%s", "[ERROR][Internal] try to call GPU section without CUDA support");
#endif
Expand All @@ -111,11 +111,11 @@ namespace cytnx {
// cout << this->device << " " << Device.cpu << endl;
if (this->device == Device.cpu) {
// cout << "[OK]" << endl;
return utils_internal::Movemem_cpu_d(tmp, old_shape, mapper, invmapper, 0);
return utils_internal::MoveMemoryCpu<cytnx_double>(tmp, old_shape, mapper, invmapper, 0);
} else {
#ifdef UNI_GPU
checkCudaErrors(cudaSetDevice(this->device));
return utils_internal::cuMovemem_gpu_d(tmp, old_shape, mapper, invmapper, 0);
return utils_internal::MoveMemoryGpu<cytnx_double>(tmp, old_shape, mapper, invmapper, 0);
#else
cytnx_error_msg(1, "%s", "[ERROR][Internal] try to call GPU section without CUDA support");
return nullptr;
Expand Down
8 changes: 4 additions & 4 deletions src/backend/FloatStorage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,10 @@ namespace cytnx {
const std::vector<cytnx_uint64> &invmapper) {
boost::intrusive_ptr<Storage_base> tmp(this);
if (this->device == Device.cpu) {
utils_internal::Movemem_cpu_f(tmp, old_shape, mapper, invmapper, 1);
utils_internal::MoveMemoryCpu<cytnx_float>(tmp, old_shape, mapper, invmapper, 1);
} else {
#ifdef UNI_GPU
utils_internal::cuMovemem_gpu_f(tmp, old_shape, mapper, invmapper, 1);
utils_internal::MoveMemoryGpu<cytnx_float>(tmp, old_shape, mapper, invmapper, 1);
#else
cytnx_error_msg(1, "%s", "[ERROR][Internal] try to call GPU section without CUDA support");
#endif
Expand All @@ -105,10 +105,10 @@ namespace cytnx {
const std::vector<cytnx_uint64> &invmapper) {
boost::intrusive_ptr<Storage_base> tmp(this);
if (this->device == Device.cpu) {
return utils_internal::Movemem_cpu_f(tmp, old_shape, mapper, invmapper, 0);
return utils_internal::MoveMemoryCpu<cytnx_float>(tmp, old_shape, mapper, invmapper, 0);
} else {
#ifdef UNI_GPU
return utils_internal::cuMovemem_gpu_f(tmp, old_shape, mapper, invmapper, 0);
return utils_internal::MoveMemoryGpu<cytnx_float>(tmp, old_shape, mapper, invmapper, 0);
#else
cytnx_error_msg(1, "%s", "[ERROR][Internal] try to call GPU section without CUDA support");
return nullptr;
Expand Down
8 changes: 4 additions & 4 deletions src/backend/Int16Storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ namespace cytnx {
const std::vector<cytnx_uint64> &invmapper) {
boost::intrusive_ptr<Storage_base> tmp(this);
if (this->device == Device.cpu) {
utils_internal::Movemem_cpu_i16(tmp, old_shape, mapper, invmapper, 1);
utils_internal::MoveMemoryCpu<cytnx_int16>(tmp, old_shape, mapper, invmapper, 1);
} else {
#ifdef UNI_GPU
checkCudaErrors(cudaSetDevice(this->device));
utils_internal::cuMovemem_gpu_i16(tmp, old_shape, mapper, invmapper, 1);
utils_internal::MoveMemoryGpu<cytnx_int16>(tmp, old_shape, mapper, invmapper, 1);
#else
cytnx_error_msg(1, "%s", "[ERROR][Internal] try to call GPU section without CUDA support");
#endif
Expand All @@ -101,11 +101,11 @@ namespace cytnx {
const std::vector<cytnx_uint64> &invmapper) {
boost::intrusive_ptr<Storage_base> tmp(this);
if (this->device == Device.cpu) {
return utils_internal::Movemem_cpu_i16(tmp, old_shape, mapper, invmapper, 0);
return utils_internal::MoveMemoryCpu<cytnx_int16>(tmp, old_shape, mapper, invmapper, 0);
} else {
#ifdef UNI_GPU
checkCudaErrors(cudaSetDevice(this->device));
return utils_internal::cuMovemem_gpu_i16(tmp, old_shape, mapper, invmapper, 0);
return utils_internal::MoveMemoryGpu<cytnx_int16>(tmp, old_shape, mapper, invmapper, 0);
#else
cytnx_error_msg(1, "%s", "[ERROR][Internal] try to call GPU section without CUDA support");
return nullptr;
Expand Down
8 changes: 4 additions & 4 deletions src/backend/Int32Storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ namespace cytnx {
const std::vector<cytnx_uint64> &invmapper) {
boost::intrusive_ptr<Storage_base> tmp(this);
if (this->device == Device.cpu) {
utils_internal::Movemem_cpu_i32(tmp, old_shape, mapper, invmapper, 1);
utils_internal::MoveMemoryCpu<cytnx_int32>(tmp, old_shape, mapper, invmapper, 1);
} else {
#ifdef UNI_GPU
checkCudaErrors(cudaSetDevice(this->device));
utils_internal::cuMovemem_gpu_i32(tmp, old_shape, mapper, invmapper, 1);
utils_internal::MoveMemoryGpu<cytnx_int32>(tmp, old_shape, mapper, invmapper, 1);
#else
cytnx_error_msg(1, "%s", "[ERROR][Internal] try to call GPU section without CUDA support");
#endif
Expand All @@ -104,11 +104,11 @@ namespace cytnx {
const std::vector<cytnx_uint64> &invmapper) {
boost::intrusive_ptr<Storage_base> tmp(this);
if (this->device == Device.cpu) {
return utils_internal::Movemem_cpu_i32(tmp, old_shape, mapper, invmapper, 0);
return utils_internal::MoveMemoryCpu<cytnx_int32>(tmp, old_shape, mapper, invmapper, 0);
} else {
#ifdef UNI_GPU
checkCudaErrors(cudaSetDevice(this->device));
return utils_internal::cuMovemem_gpu_i32(tmp, old_shape, mapper, invmapper, 0);
return utils_internal::MoveMemoryGpu<cytnx_int32>(tmp, old_shape, mapper, invmapper, 0);
#else
cytnx_error_msg(1, "%s", "[ERROR][Internal] try to call GPU section without CUDA support");
return nullptr;
Expand Down
8 changes: 4 additions & 4 deletions src/backend/Int64Storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ namespace cytnx {
const std::vector<cytnx_uint64> &invmapper) {
boost::intrusive_ptr<Storage_base> tmp(this);
if (this->device == Device.cpu) {
utils_internal::Movemem_cpu_i64(tmp, old_shape, mapper, invmapper, 1);
utils_internal::MoveMemoryCpu<cytnx_int64>(tmp, old_shape, mapper, invmapper, 1);
} else {
#ifdef UNI_GPU
checkCudaErrors(cudaSetDevice(this->device));
utils_internal::cuMovemem_gpu_i64(tmp, old_shape, mapper, invmapper, 1);
utils_internal::MoveMemoryGpu<cytnx_int64>(tmp, old_shape, mapper, invmapper, 1);
#else
cytnx_error_msg(1, "%s", "[ERROR][Internal] try to call GPU section without CUDA support");
#endif
Expand All @@ -103,11 +103,11 @@ namespace cytnx {
const std::vector<cytnx_uint64> &invmapper) {
boost::intrusive_ptr<Storage_base> tmp(this);
if (this->device == Device.cpu) {
return utils_internal::Movemem_cpu_i64(tmp, old_shape, mapper, invmapper, 0);
return utils_internal::MoveMemoryCpu<cytnx_int64>(tmp, old_shape, mapper, invmapper, 0);
} else {
#ifdef UNI_GPU
checkCudaErrors(cudaSetDevice(this->device));
return utils_internal::cuMovemem_gpu_i64(tmp, old_shape, mapper, invmapper, 0);
return utils_internal::MoveMemoryGpu<cytnx_int64>(tmp, old_shape, mapper, invmapper, 0);
#else
cytnx_error_msg(1, "%s", "[ERROR][Internal] try to call GPU section without CUDA support");
return nullptr;
Expand Down
8 changes: 4 additions & 4 deletions src/backend/Uint16Storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,11 @@ namespace cytnx {
const std::vector<cytnx_uint64> &invmapper) {
boost::intrusive_ptr<Storage_base> tmp(this);
if (this->device == Device.cpu) {
utils_internal::Movemem_cpu_u16(tmp, old_shape, mapper, invmapper, 1);
utils_internal::MoveMemoryCpu<cytnx_uint16>(tmp, old_shape, mapper, invmapper, 1);
} else {
#ifdef UNI_GPU
checkCudaErrors(cudaSetDevice(this->device));
utils_internal::cuMovemem_gpu_u16(tmp, old_shape, mapper, invmapper, 1);
utils_internal::MoveMemoryGpu<cytnx_uint16>(tmp, old_shape, mapper, invmapper, 1);
#else
cytnx_error_msg(1, "%s", "[ERROR][Internal] try to call GPU section without CUDA support");
#endif
Expand All @@ -101,11 +101,11 @@ namespace cytnx {
const std::vector<cytnx_uint64> &invmapper) {
boost::intrusive_ptr<Storage_base> tmp(this);
if (this->device == Device.cpu) {
return utils_internal::Movemem_cpu_u16(tmp, old_shape, mapper, invmapper, 0);
return utils_internal::MoveMemoryCpu<cytnx_uint16>(tmp, old_shape, mapper, invmapper, 0);
} else {
#ifdef UNI_GPU
checkCudaErrors(cudaSetDevice(this->device));
return utils_internal::cuMovemem_gpu_u16(tmp, old_shape, mapper, invmapper, 0);
return utils_internal::MoveMemoryGpu<cytnx_uint16>(tmp, old_shape, mapper, invmapper, 0);
#else
cytnx_error_msg(1, "%s", "[ERROR][Internal] try to call GPU section without CUDA support");
return nullptr;
Expand Down
8 changes: 4 additions & 4 deletions src/backend/Uint32Storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,11 +91,11 @@ namespace cytnx {
const std::vector<cytnx_uint64> &invmapper) {
boost::intrusive_ptr<Storage_base> tmp(this);
if (this->device == Device.cpu) {
utils_internal::Movemem_cpu_u32(tmp, old_shape, mapper, invmapper, 1);
utils_internal::MoveMemoryCpu<cytnx_uint32>(tmp, old_shape, mapper, invmapper, 1);
} else {
#ifdef UNI_GPU
checkCudaErrors(cudaSetDevice(this->device));
utils_internal::cuMovemem_gpu_u32(tmp, old_shape, mapper, invmapper, 1);
utils_internal::MoveMemoryGpu<cytnx_uint32>(tmp, old_shape, mapper, invmapper, 1);
#else
cytnx_error_msg(1, "%s", "[ERROR][Internal] try to call GPU section without CUDA support");
#endif
Expand All @@ -107,11 +107,11 @@ namespace cytnx {
const std::vector<cytnx_uint64> &invmapper) {
boost::intrusive_ptr<Storage_base> tmp(this);
if (this->device == Device.cpu) {
return utils_internal::Movemem_cpu_u32(tmp, old_shape, mapper, invmapper, 0);
return utils_internal::MoveMemoryCpu<cytnx_uint32>(tmp, old_shape, mapper, invmapper, 0);
} else {
#ifdef UNI_GPU
checkCudaErrors(cudaSetDevice(this->device));
return utils_internal::cuMovemem_gpu_u32(tmp, old_shape, mapper, invmapper, 0);
return utils_internal::MoveMemoryGpu<cytnx_uint32>(tmp, old_shape, mapper, invmapper, 0);
#else
cytnx_error_msg(1, "%s", "[ERROR][Internal] try to call GPU section without CUDA support");
return nullptr;
Expand Down
8 changes: 4 additions & 4 deletions src/backend/Uint64Storage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -87,11 +87,11 @@ namespace cytnx {
const std::vector<cytnx_uint64> &invmapper) {
boost::intrusive_ptr<Storage_base> tmp(this);
if (this->device == Device.cpu) {
utils_internal::Movemem_cpu_u64(tmp, old_shape, mapper, invmapper, 1);
utils_internal::MoveMemoryCpu<cytnx_uint64>(tmp, old_shape, mapper, invmapper, 1);
} else {
#ifdef UNI_GPU
checkCudaErrors(cudaSetDevice(this->device));
utils_internal::cuMovemem_gpu_u64(tmp, old_shape, mapper, invmapper, 1);
utils_internal::MoveMemoryGpu<cytnx_uint64>(tmp, old_shape, mapper, invmapper, 1);
#else
cytnx_error_msg(1, "%s", "[ERROR][Internal] try to call GPU section without CUDA support");
#endif
Expand All @@ -103,11 +103,11 @@ namespace cytnx {
const std::vector<cytnx_uint64> &invmapper) {
boost::intrusive_ptr<Storage_base> tmp(this);
if (this->device == Device.cpu) {
return utils_internal::Movemem_cpu_u64(tmp, old_shape, mapper, invmapper, 0);
return utils_internal::MoveMemoryCpu<cytnx_uint64>(tmp, old_shape, mapper, invmapper, 0);
} else {
#ifdef UNI_GPU
checkCudaErrors(cudaSetDevice(this->device));
return utils_internal::cuMovemem_gpu_u64(tmp, old_shape, mapper, invmapper, 0);
return utils_internal::MoveMemoryGpu<cytnx_uint64>(tmp, old_shape, mapper, invmapper, 0);
#else
cytnx_error_msg(1, "%s", "[ERROR][Internal] try to call GPU section without CUDA support");
return nullptr;
Expand Down
Loading

0 comments on commit 6ff4e31

Please sign in to comment.