mirror of
https://gitlab.com/libeigen/eigen.git
synced 2025-04-23 01:59:38 +08:00
Fix CUDA device new and delete, and add test.
HIP does not support new/delete on device, so test is skipped.
This commit is contained in:
parent
119763cf38
commit
5908aeeaba
@ -780,32 +780,45 @@ template<typename T> void swap(scoped_array<T> &a,scoped_array<T> &b)
|
|||||||
|
|
||||||
#else
|
#else
|
||||||
|
|
||||||
#if EIGEN_MAX_ALIGN_BYTES!=0
|
// HIP does not support new/delete on device.
|
||||||
|
#if EIGEN_MAX_ALIGN_BYTES!=0 && !defined(EIGEN_HIP_DEVICE_COMPILE)
|
||||||
#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_NOTHROW(NeedsToAlign) \
|
#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_NOTHROW(NeedsToAlign) \
|
||||||
|
EIGEN_DEVICE_FUNC \
|
||||||
void* operator new(std::size_t size, const std::nothrow_t&) EIGEN_NO_THROW { \
|
void* operator new(std::size_t size, const std::nothrow_t&) EIGEN_NO_THROW { \
|
||||||
EIGEN_TRY { return Eigen::internal::conditional_aligned_malloc<NeedsToAlign>(size); } \
|
EIGEN_TRY { return Eigen::internal::conditional_aligned_malloc<NeedsToAlign>(size); } \
|
||||||
EIGEN_CATCH (...) { return 0; } \
|
EIGEN_CATCH (...) { return 0; } \
|
||||||
}
|
}
|
||||||
#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign) \
|
#define EIGEN_MAKE_ALIGNED_OPERATOR_NEW_IF(NeedsToAlign) \
|
||||||
|
EIGEN_DEVICE_FUNC \
|
||||||
void *operator new(std::size_t size) { \
|
void *operator new(std::size_t size) { \
|
||||||
return Eigen::internal::conditional_aligned_malloc<NeedsToAlign>(size); \
|
return Eigen::internal::conditional_aligned_malloc<NeedsToAlign>(size); \
|
||||||
} \
|
} \
|
||||||
|
EIGEN_DEVICE_FUNC \
|
||||||
void *operator new[](std::size_t size) { \
|
void *operator new[](std::size_t size) { \
|
||||||
return Eigen::internal::conditional_aligned_malloc<NeedsToAlign>(size); \
|
return Eigen::internal::conditional_aligned_malloc<NeedsToAlign>(size); \
|
||||||
} \
|
} \
|
||||||
|
EIGEN_DEVICE_FUNC \
|
||||||
void operator delete(void * ptr) EIGEN_NO_THROW { Eigen::internal::conditional_aligned_free<NeedsToAlign>(ptr); } \
|
void operator delete(void * ptr) EIGEN_NO_THROW { Eigen::internal::conditional_aligned_free<NeedsToAlign>(ptr); } \
|
||||||
|
EIGEN_DEVICE_FUNC \
|
||||||
void operator delete[](void * ptr) EIGEN_NO_THROW { Eigen::internal::conditional_aligned_free<NeedsToAlign>(ptr); } \
|
void operator delete[](void * ptr) EIGEN_NO_THROW { Eigen::internal::conditional_aligned_free<NeedsToAlign>(ptr); } \
|
||||||
|
EIGEN_DEVICE_FUNC \
|
||||||
void operator delete(void * ptr, std::size_t /* sz */) EIGEN_NO_THROW { Eigen::internal::conditional_aligned_free<NeedsToAlign>(ptr); } \
|
void operator delete(void * ptr, std::size_t /* sz */) EIGEN_NO_THROW { Eigen::internal::conditional_aligned_free<NeedsToAlign>(ptr); } \
|
||||||
|
EIGEN_DEVICE_FUNC \
|
||||||
void operator delete[](void * ptr, std::size_t /* sz */) EIGEN_NO_THROW { Eigen::internal::conditional_aligned_free<NeedsToAlign>(ptr); } \
|
void operator delete[](void * ptr, std::size_t /* sz */) EIGEN_NO_THROW { Eigen::internal::conditional_aligned_free<NeedsToAlign>(ptr); } \
|
||||||
/* in-place new and delete. since (at least afaik) there is no actual */ \
|
/* in-place new and delete. since (at least afaik) there is no actual */ \
|
||||||
/* memory allocated we can safely let the default implementation handle */ \
|
/* memory allocated we can safely let the default implementation handle */ \
|
||||||
/* this particular case. */ \
|
/* this particular case. */ \
|
||||||
|
EIGEN_DEVICE_FUNC \
|
||||||
static void *operator new(std::size_t size, void *ptr) { return ::operator new(size,ptr); } \
|
static void *operator new(std::size_t size, void *ptr) { return ::operator new(size,ptr); } \
|
||||||
|
EIGEN_DEVICE_FUNC \
|
||||||
static void *operator new[](std::size_t size, void* ptr) { return ::operator new[](size,ptr); } \
|
static void *operator new[](std::size_t size, void* ptr) { return ::operator new[](size,ptr); } \
|
||||||
|
EIGEN_DEVICE_FUNC \
|
||||||
void operator delete(void * memory, void *ptr) EIGEN_NO_THROW { return ::operator delete(memory,ptr); } \
|
void operator delete(void * memory, void *ptr) EIGEN_NO_THROW { return ::operator delete(memory,ptr); } \
|
||||||
|
EIGEN_DEVICE_FUNC \
|
||||||
void operator delete[](void * memory, void *ptr) EIGEN_NO_THROW { return ::operator delete[](memory,ptr); } \
|
void operator delete[](void * memory, void *ptr) EIGEN_NO_THROW { return ::operator delete[](memory,ptr); } \
|
||||||
/* nothrow-new (returns zero instead of std::bad_alloc) */ \
|
/* nothrow-new (returns zero instead of std::bad_alloc) */ \
|
||||||
EIGEN_MAKE_ALIGNED_OPERATOR_NEW_NOTHROW(NeedsToAlign) \
|
EIGEN_MAKE_ALIGNED_OPERATOR_NEW_NOTHROW(NeedsToAlign) \
|
||||||
|
EIGEN_DEVICE_FUNC \
|
||||||
void operator delete(void *ptr, const std::nothrow_t&) EIGEN_NO_THROW { \
|
void operator delete(void *ptr, const std::nothrow_t&) EIGEN_NO_THROW { \
|
||||||
Eigen::internal::conditional_aligned_free<NeedsToAlign>(ptr); \
|
Eigen::internal::conditional_aligned_free<NeedsToAlign>(ptr); \
|
||||||
} \
|
} \
|
||||||
|
@ -233,6 +233,26 @@ struct replicate {
|
|||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct alloc_new_delete {
|
||||||
|
EIGEN_DEVICE_FUNC
|
||||||
|
void operator()(int i, const typename T::Scalar* in, typename T::Scalar* out) const
|
||||||
|
{
|
||||||
|
int offset = 2*i*T::MaxSizeAtCompileTime;
|
||||||
|
T* x = new T(in + offset);
|
||||||
|
Eigen::Map<T> u(out + offset);
|
||||||
|
u = *x;
|
||||||
|
delete x;
|
||||||
|
|
||||||
|
offset += T::MaxSizeAtCompileTime;
|
||||||
|
T* y = new T[1];
|
||||||
|
y[0] = T(in + offset);
|
||||||
|
Eigen::Map<T> v(out + offset);
|
||||||
|
v = y[0];
|
||||||
|
delete[] y;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
template<typename T>
|
template<typename T>
|
||||||
struct redux {
|
struct redux {
|
||||||
EIGEN_DEVICE_FUNC
|
EIGEN_DEVICE_FUNC
|
||||||
@ -418,4 +438,5 @@ EIGEN_DECLARE_TEST(gpu_basic)
|
|||||||
typedef Matrix<float,6,6> Matrix6f;
|
typedef Matrix<float,6,6> Matrix6f;
|
||||||
CALL_SUBTEST( run_and_compare_to_gpu(eigenvalues<Matrix6f>(), nthreads, in, out) );
|
CALL_SUBTEST( run_and_compare_to_gpu(eigenvalues<Matrix6f>(), nthreads, in, out) );
|
||||||
#endif
|
#endif
|
||||||
|
CALL_SUBTEST( run_and_compare_to_gpu(alloc_new_delete<Vector3f>(), nthreads, in, out) );
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user