Skip to content

Commit

Permalink
Rewrite mem_fence by wrapping atomic_fence
Browse files Browse the repository at this point in the history
  • Loading branch information
nmnobre committed May 3, 2023
1 parent 80fab42 commit eccf762
Showing 1 changed file with 3 additions and 26 deletions.
29 changes: 3 additions & 26 deletions include/hipSYCL/sycl/libkernel/detail/mem_fence.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
#ifndef HIPSYCL_MEM_FENCE_HPP
#define HIPSYCL_MEM_FENCE_HPP

#include "hipSYCL/sycl/libkernel/atomic_fence.hpp"
#include "hipSYCL/sycl/libkernel/backend.hpp"
#include "hipSYCL/sycl/access.hpp"

Expand All @@ -41,20 +42,7 @@ struct mem_fence_impl
HIPSYCL_KERNEL_TARGET
static void mem_fence()
{

__hipsycl_if_target_hiplike(
__threadfence();
);
__hipsycl_if_target_spirv(
__spirv_MemoryBarrier(__spv::Scope::Device,
__spv::MemorySemanticsMask::SequentiallyConsistent |
__spv::MemorySemanticsMask::CrossWorkgroupMemory |
__spv::MemorySemanticsMask::WorkgroupMemory);
);
// TODO What about CPU?
// Empty __hipsycl_if_target_* breaks at compile time w/ nvc++ 22.7 or
// older, so comment out that statement for now.
//__hipsycl_if_target_host(/* todo */);
detail::atomic_fence(memory_order::seq_cst, memory_scope::device);
}

};
Expand All @@ -65,21 +53,10 @@ struct mem_fence_impl<access::fence_space::local_space, M>
HIPSYCL_KERNEL_TARGET
static void mem_fence()
{
__hipsycl_if_target_hiplike(
__threadfence_block();
);
__hipsycl_if_target_spirv(
__spirv_MemoryBarrier(
__spv::Scope::Workgroup,
static_cast<uint32_t>(
__spv::MemorySemanticsMask::SequentiallyConsistent |
__spv::MemorySemanticsMask::WorkgroupMemory));
);
detail::atomic_fence(memory_order::seq_cst, memory_scope::work_group);
}
};



template <
access::fence_space Fence_space = access::fence_space::global_and_local,
access::mode Mode = access::mode::read_write
Expand Down

0 comments on commit eccf762

Please sign in to comment.