-
Notifications
You must be signed in to change notification settings - Fork 753
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
[SYCL][ESIMD] Introduce rdtsc API #12315
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1723,6 +1723,20 @@ __ESIMD_API std::enable_if_t<__ESIMD_DNS::is_esimd_scalar<T>::value && | |
return __ESIMD_NS::bfn<FuncControl>(src0, src1, src2); | ||
} | ||
|
||
/// sr0 - get the lower 64 bit value of sr0 register. | ||
/// \return the current value of lower 64 bit of sr0 register | ||
ESIMD_INLINE uint64_t sr0() { | ||
__ESIMD_NS::simd<uint32_t, 4> retv = __esimd_sr0(); | ||
return retv.template bit_cast_view<uint64_t>()[0]; | ||
} | ||
|
||
/// rdtsc - get the value of rdtsc register. | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. rdtsc stands for ReaD TimeStamp Counter (I think). Can you please make it more clear in the comment here? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. GenX returns 4 integers (which is probably the content of the drtsc register (if it is a register). |
||
/// \return the current value of rdtsc | ||
ESIMD_INLINE uint64_t rdtsc() { | ||
v-klochkov marked this conversation as resolved.
Show resolved
Hide resolved
|
||
__ESIMD_NS::simd<uint32_t, 4> retv = __esimd_timestamp(); | ||
return retv.template bit_cast_view<uint64_t>()[0]; | ||
} | ||
|
||
/// @} sycl_esimd_logical | ||
|
||
} // namespace ext::intel::experimental::esimd | ||
|
Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
@@ -0,0 +1,84 @@ | ||||||||||||||||||||||||
// RUN: %{build} -o %t.out | ||||||||||||||||||||||||
// RUN: %{run} %t.out | ||||||||||||||||||||||||
//==- rdtsc_sr0.cpp - Test to verify rdtsc0 and sr0 functionlity------------==// | ||||||||||||||||||||||||
// | ||||||||||||||||||||||||
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions. | ||||||||||||||||||||||||
// See https://llvm.org/LICENSE.txt for license information. | ||||||||||||||||||||||||
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception | ||||||||||||||||||||||||
// | ||||||||||||||||||||||||
//===----------------------------------------------------------------------===// | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
// This is basic test to validate rdtsc and sr0 functions. | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
#include <cmath> | ||||||||||||||||||||||||
#include <iostream> | ||||||||||||||||||||||||
#include <sycl/ext/intel/esimd.hpp> | ||||||||||||||||||||||||
#include <sycl/ext/intel/esimd/simd.hpp> | ||||||||||||||||||||||||
#include <sycl/sycl.hpp> | ||||||||||||||||||||||||
#include <vector> | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
int ErrCnt = 0; | ||||||||||||||||||||||||
template <typename DataT> | ||||||||||||||||||||||||
using shared_allocator = sycl::usm_allocator<DataT, sycl::usm::alloc::shared>; | ||||||||||||||||||||||||
template <typename DataT> | ||||||||||||||||||||||||
using shared_vector = std::vector<DataT, shared_allocator<DataT>>; | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
int test_rdtsc_sr0() { | ||||||||||||||||||||||||
sycl::queue Queue; | ||||||||||||||||||||||||
shared_allocator<uint64_t> Allocator(Queue); | ||||||||||||||||||||||||
constexpr int32_t SIZE = 32; | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
shared_vector<uint64_t> VectorOutputSR0(SIZE, -1, Allocator); | ||||||||||||||||||||||||
shared_vector<uint64_t> VectorOutputRDTSC(SIZE, -1, Allocator); | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
auto GlobalRange = sycl::range<1>(SIZE); | ||||||||||||||||||||||||
sycl::range<1> LocalRange{1}; | ||||||||||||||||||||||||
sycl::nd_range<1> Range(GlobalRange, LocalRange); | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
{ | ||||||||||||||||||||||||
Queue.submit([&](sycl::handler &cgh) { | ||||||||||||||||||||||||
uint64_t *VectorOutputSR0Ptr = VectorOutputSR0.data(); | ||||||||||||||||||||||||
uint64_t *VectorOutputRDTSCPtr = VectorOutputRDTSC.data(); | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
auto Kernel = ([=](sycl::nd_item<1> ndi) [[intel::sycl_explicit_simd]] { | ||||||||||||||||||||||||
using namespace sycl::ext::intel::esimd; | ||||||||||||||||||||||||
auto Idx = ndi.get_global_id(0); | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
simd<uint64_t, 1> VectorResultSR0 = | ||||||||||||||||||||||||
sycl::ext::intel::experimental::esimd::sr0(); | ||||||||||||||||||||||||
simd<uint64_t, 1> VectorResultRDTSC = | ||||||||||||||||||||||||
sycl::ext::intel::experimental::esimd::rdtsc(); | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
VectorResultSR0.copy_to(VectorOutputSR0Ptr + Idx); | ||||||||||||||||||||||||
VectorResultRDTSC.copy_to(VectorOutputRDTSCPtr + Idx); | ||||||||||||||||||||||||
}); | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
cgh.parallel_for(Range, Kernel); | ||||||||||||||||||||||||
}); | ||||||||||||||||||||||||
Queue.wait(); | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
int Result = 0; | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
// Check if returned values are not the same | ||||||||||||||||||||||||
std::sort(VectorOutputRDTSC.begin(), VectorOutputRDTSC.end()); | ||||||||||||||||||||||||
std::sort(VectorOutputSR0.begin(), VectorOutputSR0.end()); | ||||||||||||||||||||||||
Result |= std::equal(VectorOutputRDTSC.begin() + 1, VectorOutputRDTSC.end(), | ||||||||||||||||||||||||
v-klochkov marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||||||||||||||||||||
VectorOutputRDTSC.begin()); | ||||||||||||||||||||||||
Result |= std::equal(VectorOutputSR0.begin() + 1, VectorOutputSR0.end(), | ||||||||||||||||||||||||
VectorOutputSR0.begin()); | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
return Result; | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
int main() { | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
int TestResult = 0; | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
TestResult |= test_rdtsc_sr0(); | ||||||||||||||||||||||||
|
||||||||||||||||||||||||
if (!TestResult) { | ||||||||||||||||||||||||
std::cout << "Pass" << std::endl; | ||||||||||||||||||||||||
} | ||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. nit: it could be shorter without extra-spaces and braces:
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. can you please remove extra space too? |
||||||||||||||||||||||||
return TestResult; | ||||||||||||||||||||||||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
let's drop support of sr0 for a while, until we know better how it is going to be used.