Skip to content

Commit

Permalink
Merge branch 'develop' into bugfix/burmark1/launch_fixed_reduce2
Browse files Browse the repository at this point in the history
  • Loading branch information
rhornung67 authored Aug 27, 2024
2 parents dc6807f + 1ffa084 commit ed44146
Show file tree
Hide file tree
Showing 7 changed files with 14 additions and 59 deletions.
5 changes: 0 additions & 5 deletions exercises/dot-product.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -38,11 +38,6 @@ int main(int RAJA_UNUSED_ARG(argc), char **RAJA_UNUSED_ARG(argv[]))

std::cout << "\n\nExercise: vector dot product...\n";

#if defined(RAJA_ENABLE_SYCL)
memoryManager::sycl_res = new camp::resources::Resource{camp::resources::Sycl()};
::RAJA::sycl::detail::setQueue(memoryManager::sycl_res);
#endif

//
// Define vector length
//
Expand Down
7 changes: 1 addition & 6 deletions exercises/dot-product_solution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,6 @@ int main(int RAJA_UNUSED_ARG(argc), char **RAJA_UNUSED_ARG(argv[]))

std::cout << "\n\nExercise: vector dot product...\n";

#if defined(RAJA_ENABLE_SYCL)
memoryManager::sycl_res = new camp::resources::Resource{camp::resources::Sycl()};
::RAJA::sycl::detail::setQueue(memoryManager::sycl_res);
#endif

//
// Define vector length
//
Expand Down Expand Up @@ -113,7 +108,7 @@ int main(int RAJA_UNUSED_ARG(argc), char **RAJA_UNUSED_ARG(argv[]))

RAJA::forall<RAJA::omp_parallel_for_exec>(RAJA::RangeSegment(0, N), [=] (int i) {
ompdot += a[i] * b[i];
});
});

dot = ompdot.get();
// _rajaomp_dotprod_end
Expand Down
5 changes: 0 additions & 5 deletions exercises/vector-addition.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ int main(int RAJA_UNUSED_ARG(argc), char **RAJA_UNUSED_ARG(argv[]))

std::cout << "\n\nExercise: RAJA Vector Addition...\n";

#if defined(RAJA_ENABLE_SYCL)
memoryManager::sycl_res = new camp::resources::Resource{camp::resources::Sycl()};
::RAJA::sycl::detail::setQueue(memoryManager::sycl_res);
#endif

//
// Define vector length
//
Expand Down
7 changes: 1 addition & 6 deletions exercises/vector-addition_solution.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -62,11 +62,6 @@ int main(int RAJA_UNUSED_ARG(argc), char **RAJA_UNUSED_ARG(argv[]))

std::cout << "\n\nExercise: RAJA Vector Addition...\n";

#if defined(RAJA_ENABLE_SYCL)
memoryManager::sycl_res = new camp::resources::Resource{camp::resources::Sycl()};
::RAJA::sycl::detail::setQueue(memoryManager::sycl_res);
#endif

//
// Define vector length
//
Expand Down Expand Up @@ -179,7 +174,7 @@ int main(int RAJA_UNUSED_ARG(argc), char **RAJA_UNUSED_ARG(argv[]))
RAJA::TypedRangeSegment<int>(0, N), [=] (int i) {
c[i] = a[i] + b[i];
}
);
);
// _rajaomp_vector_add_end

checkResult(c, c_ref, N);
Expand Down
16 changes: 6 additions & 10 deletions include/RAJA/policy/sycl/MemUtils_SYCL.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -64,10 +64,6 @@ extern syclInfo tl_status;

extern std::unordered_map<cl::sycl::queue, bool> g_queue_info_map;

void setQueue(camp::resources::Resource* q);

cl::sycl::queue* getQueue();

} // namespace detail

//! Allocator for pinned memory for use in basic_mempool
Expand All @@ -77,7 +73,7 @@ struct PinnedAllocator {
void* malloc(size_t nbytes)
{
void* ptr;
::sycl::queue* q = ::RAJA::sycl::detail::getQueue();
::sycl::queue* q = ::camp::resources::Sycl::get_default().get_queue();
ptr = ::sycl::malloc_host(nbytes, *q);
return ptr;
}
Expand All @@ -86,7 +82,7 @@ struct PinnedAllocator {
// Will throw if ptr is not in q's context
bool free(void* ptr)
{
::sycl::queue* q = ::RAJA::sycl::detail::getQueue();
::sycl::queue* q = ::camp::resources::Sycl::get_default().get_queue();
::sycl::free(ptr, *q);
return true;
}
Expand All @@ -99,7 +95,7 @@ struct DeviceAllocator {
void* malloc(size_t nbytes)
{
void* ptr;
::sycl::queue* q = ::RAJA::sycl::detail::getQueue();
::sycl::queue* q = ::camp::resources::Sycl::get_default().get_queue();
ptr = ::sycl::malloc_device(nbytes, *q);
return ptr;
}
Expand All @@ -108,7 +104,7 @@ struct DeviceAllocator {
// Will throw if ptr is not in q's context
bool free(void* ptr)
{
::sycl::queue* q = ::RAJA::sycl::detail::getQueue();
::sycl::queue* q = ::camp::resources::Sycl::get_default().get_queue();
::sycl::free(ptr, *q);
return true;
}
Expand All @@ -122,7 +118,7 @@ struct DeviceZeroedAllocator {
void* malloc(size_t nbytes)
{
void* ptr;
::sycl::queue* q = ::RAJA::sycl::detail::getQueue();
::sycl::queue* q = ::camp::resources::Sycl::get_default().get_queue();
ptr = ::sycl::malloc_device(nbytes, *q);
q->memset(ptr, 0, nbytes);
return ptr;
Expand All @@ -132,7 +128,7 @@ struct DeviceZeroedAllocator {
// Will throw if ptr is not in q's context
bool free(void* ptr)
{
::sycl::queue* q = ::RAJA::sycl::detail::getQueue();
::sycl::queue* q = ::camp::resources::Sycl::get_default().get_queue();
::sycl::free(ptr, *q);
return true;
}
Expand Down
19 changes: 6 additions & 13 deletions include/RAJA/policy/sycl/reduce.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -107,12 +107,8 @@ struct Reduce_Data
Reduce_Data(T initValue, T identityValue, Offload_Info &info)
: value(initValue)
{
cl::sycl::queue* q = ::RAJA::sycl::detail::getQueue();
cl::sycl::queue* q = ::camp::resources::Sycl::get_default().get_queue();

if(!q) {
camp::resources::Resource res = camp::resources::Sycl();
q = res.get<camp::resources::Sycl>().get_queue();
}

device = reinterpret_cast<T *>(cl::sycl::malloc_device(sycl::MaxNumTeams * sizeof(T), *(q)));
host = reinterpret_cast<T *>(cl::sycl::malloc_host(sycl::MaxNumTeams * sizeof(T), *(q)));
Expand Down Expand Up @@ -140,7 +136,7 @@ struct Reduce_Data
//! transfers from the host to the device -- exit() is called upon failure
RAJA_INLINE void hostToDevice(Offload_Info &info)
{
cl::sycl::queue* q = ::RAJA::sycl::detail::getQueue();
cl::sycl::queue* q = ::camp::resources::Sycl::get_default().get_queue();

if(!q) {
camp::resources::Resource res = camp::resources::Sycl();
Expand All @@ -158,7 +154,7 @@ struct Reduce_Data
//! transfers from the device to the host -- exit() is called upon failure
RAJA_INLINE void deviceToHost(Offload_Info &info)
{
cl::sycl::queue* q = ::RAJA::sycl::detail::getQueue();
cl::sycl::queue* q = ::camp::resources::Sycl::get_default().get_queue();

if(!q) {
camp::resources::Resource res = camp::resources::Sycl();
Expand All @@ -169,18 +165,15 @@ struct Reduce_Data
auto e = q->memcpy(reinterpret_cast<void *>(host),
reinterpret_cast<void *>(device),
sycl::MaxNumTeams * sizeof(T));

e.wait();
}

//! frees all data from the offload information passed
RAJA_INLINE void cleanup(Offload_Info &info)
{
cl::sycl::queue* q = ::RAJA::sycl::detail::getQueue();
if(!q) {
camp::resources::Resource res = camp::resources::Sycl();
q = res.get<camp::resources::Sycl>().get_queue();
}
cl::sycl::queue* q = ::camp::resources::Sycl::get_default().get_queue();

if (device) {
cl::sycl::free(reinterpret_cast<void *>(device), *q);
device = nullptr;
Expand Down
14 changes: 0 additions & 14 deletions src/MemUtils_SYCL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,24 +48,10 @@ syclInfo tl_status;
#pragma omp threadprivate(tl_status)
#endif

camp::resources::Resource* app_q = NULL;

void setQueue(camp::resources::Resource* qu) {
app_q = qu;
}

//! State of raja sycl queue synchronization for sycl reducer objects
std::unordered_map<cl::sycl::queue, bool> g_queue_info_map{
{cl::sycl::queue(), true}};

cl::sycl::queue* getQueue() {
if (app_q != NULL) {
return app_q->get<camp::resources::Sycl>().get_queue();
}

return NULL;
}

} // namespace detail

} // namespace sycl
Expand Down

0 comments on commit ed44146

Please sign in to comment.