Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor: Templatise Movemem() function #504

Merged
merged 1 commit into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading