Skip to content
This repository was archived by the owner on Mar 20, 2023. It is now read-only.

Commit 00ff7f3

Browse files
committed
Implement omp_get_mapped_ptr
1 parent 781d34f commit 00ff7f3

1 file changed

Lines changed: 15 additions & 3 deletions

File tree

coreneuron/utils/offload.hpp

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,24 @@
2525
#include <cstddef>
2626

2727
namespace coreneuron {
28+
#define cnrn_target_deviceptr(h_ptr) [&]() { std::cout << #h_ptr << std::endl; return cnrn_target_deviceptr2(h_ptr);}()
29+
2830
template <typename T>
29-
T* cnrn_target_deviceptr(const T* h_ptr) {
31+
T* cnrn_target_deviceptr2(T* h_ptr) {
3032
#if defined(CORENEURON_ENABLE_GPU) && !defined(CORENEURON_PREFER_OPENMP_OFFLOAD) && defined(_OPENACC)
31-
return static_cast<T*>(acc_deviceptr(const_cast<T*>(h_ptr)));
33+
return static_cast<T*>(acc_deviceptr(h_ptr));
3234
#elif defined(CORENEURON_ENABLE_GPU) && defined(CORENEURON_PREFER_OPENMP_OFFLOAD) && defined(_OPENMP)
33-
return static_cast<T*>(omp_get_mapped_ptr(const_cast<T*>(h_ptr), omp_get_default_device()));
35+
if (omp_get_mapped_ptr(h_ptr, omp_get_default_device()) == nullptr) {
36+
throw std::runtime_error("here");
37+
}
38+
T *d_ptr = nullptr;
39+
40+
nrn_pragma_omp(target data use_device_ptr(h_ptr))
41+
{
42+
d_ptr = h_ptr;
43+
}
44+
45+
return d_ptr;
3446
#else
3547
throw std::runtime_error("cnrn_target_deviceptr() not implemented without OpenACC/OpenMP and gpu build");
3648
#endif

0 commit comments

Comments
 (0)