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

fix cuTNPerm & cuGeSvd without is_U=false & attempt to fix cutt call … #480

Draft
wants to merge 1 commit into
base: dev-master
Choose a base branch
from
Draft
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
12 changes: 12 additions & 0 deletions include/cytnx_error.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@
#include <iostream>
#include <stdexcept>

#include <execinfo.h>

#ifdef _MSC_VER
#define __PRETTY_FUNCTION__ __FUNCTION__
#endif
Expand All @@ -31,6 +33,16 @@ static inline void error_msg(char const *const func, const char *const file, int
file, line);
va_end(args);
// std::cerr << output_str << std::endl;
std::cerr << output_str << std::endl;
std::cerr << "Stack trace:" << std::endl;
void *array[10];
size_t size;
size = backtrace(array, 10);
char **strings = backtrace_symbols(array, size);
for (size_t i = 0; i < size; i++) {
std::cerr << strings[i] << std::endl;
}
free(strings);
throw std::logic_error(output_str);
}
// } catch (const char *output_msg) {
Expand Down
8 changes: 4 additions & 4 deletions src/backend/linalg_internal_gpu/cuGeSvd_internal.cu
Original file line number Diff line number Diff line change
Expand Up @@ -70,7 +70,7 @@ namespace cytnx {
(cytnx_double *)S->Mem, (d_data_type *)vTMem, ldu,
(d_data_type *)UMem, ldvT, (d_data_type *)d_work, lwork,
devinfo, gesvdj_params));
if (jobz == CUSOLVER_EIG_MODE_VECTOR) {
if (U->Mem and jobz == CUSOLVER_EIG_MODE_VECTOR) {
U->Move_memory_({(cytnx_uint64)min, (cytnx_uint64)M}, {1, 0}, {1, 0});
linalg_internal::cuConj_inplace_internal_cd(U, M * min);
}
Expand Down Expand Up @@ -158,7 +158,7 @@ namespace cytnx {
(cytnx_float *)S->Mem, (d_data_type *)vTMem, ldu,
(d_data_type *)UMem, ldvT, (d_data_type *)d_work, lwork,
devinfo, gesvdj_params));
if (jobz == CUSOLVER_EIG_MODE_VECTOR) {
if (U->Mem and jobz == CUSOLVER_EIG_MODE_VECTOR) {
U->Move_memory_({(cytnx_uint64)min, (cytnx_uint64)M}, {1, 0}, {1, 0});
linalg_internal::cuConj_inplace_internal_cf(U, M * min);
}
Expand Down Expand Up @@ -244,7 +244,7 @@ namespace cytnx {
checkCudaErrors(cusolverDnDgesvdj(
cusolverH, jobz, econ, N, M, (data_type *)Mij, ldA, (data_type *)S->Mem, (data_type *)vTMem,
ldu, (data_type *)UMem, ldvT, (data_type *)d_work, lwork, devinfo, gesvdj_params));
if (jobz == CUSOLVER_EIG_MODE_VECTOR) {
if (U->Mem and jobz == CUSOLVER_EIG_MODE_VECTOR) {
U->Move_memory_({(cytnx_uint64)min, (cytnx_uint64)M}, {1, 0}, {1, 0});
}

Expand Down Expand Up @@ -329,7 +329,7 @@ namespace cytnx {
checkCudaErrors(cusolverDnSgesvdj(
cusolverH, jobz, econ, N, M, (data_type *)Mij, ldA, (data_type *)S->Mem, (data_type *)vTMem,
ldu, (data_type *)UMem, ldvT, (data_type *)d_work, lwork, devinfo, gesvdj_params));
if (jobz == CUSOLVER_EIG_MODE_VECTOR) {
if (U->Mem and jobz == CUSOLVER_EIG_MODE_VECTOR) {
U->Move_memory_({(cytnx_uint64)min, (cytnx_uint64)M}, {1, 0}, {1, 0});
}

Expand Down
16 changes: 12 additions & 4 deletions src/backend/utils_internal_gpu/cuMovemem_gpu.cu
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,21 @@ namespace cytnx {
#ifdef UNI_GPU
template <class BidirectionalIterator>
void reverse_perm(BidirectionalIterator first, BidirectionalIterator last, int N) {
while ((first != last) && (first != --last)) {
// while ((first != last) && (first != --last)) {
// *first = (N - 1) - *first;
// *last = (N - 1) - *last;
// std::iter_swap(first, last);
// ++first;
// }
// if (N % 2) *first = (N - 1) - *first;
--last;
while (first != last and first != --last) {
++last;
*first = (N - 1) - *first;
*last = (N - 1) - *last;
std::iter_swap(first, last);
++first;
--last;
}
if (N % 2) *first = (N - 1) - *first;
}
Expand Down Expand Up @@ -170,7 +180,6 @@ namespace cytnx {
cuT *dtmp;
dtmp = (cuT *)cuMalloc_gpu(sizeof(cuT) * in->cap);
cytnx_uint64 Nelem = in->len;

std::vector<int> perm(mapper.begin(), mapper.end());
std::vector<int> size(old_shape.begin(), old_shape.end());
std::reverse(size.begin(), size.end()); // matching API CUTT
Expand All @@ -187,8 +196,7 @@ namespace cytnx {
/// cpy back:
checkCudaErrors(cudaMemcpy(in->Mem, dtmp, sizeof(T) * Nelem, cudaMemcpyDeviceToDevice));
cudaFree(dtmp);
return out;

return in;
} else {
out->_Init_byptr(dtmp, Nelem, in->device, true, in->cap);
return out;
Expand Down
Loading
Loading