-
Notifications
You must be signed in to change notification settings - Fork 771
[SYCL][ESIMD] Introduce rdtsc API #12315
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
Merged
Merged
Changes from 3 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,74 @@ | ||||||
// RUN: %{build} -o %t.out | ||||||
// RUN: %{run} %t.out | ||||||
//==- rdtsc.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 function. | ||||||
|
||||||
#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() { | ||||||
sycl::queue Queue; | ||||||
shared_allocator<uint64_t> Allocator(Queue); | ||||||
constexpr int32_t SIZE = 32; | ||||||
|
||||||
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 *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); | ||||||
uint64_t StartCounter = sycl::ext::intel::experimental::esimd::rdtsc(); | ||||||
simd<uint64_t, 1> VectorResultRDTSC(VectorOutputRDTSCPtr + Idx); | ||||||
uint64_t EndCounter = sycl::ext::intel::experimental::esimd::rdtsc(); | ||||||
VectorResultRDTSC = EndCounter > StartCounter; | ||||||
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. because the original result of the load at L45 is not used, it may be deleted.
Suggested change
|
||||||
|
||||||
VectorResultRDTSC.copy_to(VectorOutputRDTSCPtr + Idx); | ||||||
}); | ||||||
|
||||||
cgh.parallel_for(Range, Kernel); | ||||||
}); | ||||||
Queue.wait(); | ||||||
} | ||||||
|
||||||
int Result = 0; | ||||||
|
||||||
// Check if returned values are positive | ||||||
Result |= std::any_of(VectorOutputRDTSC.begin(), VectorOutputRDTSC.end(), | ||||||
[](uint64_t v) { return v == 0; }); | ||||||
|
||||||
return Result; | ||||||
} | ||||||
|
||||||
int main() { | ||||||
|
||||||
int TestResult = test_rdtsc(); | ||||||
|
||||||
if (!TestResult) { | ||||||
std::cout << "Pass" << std::endl; | ||||||
} | ||||||
return TestResult; | ||||||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
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 comment
The 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).
The function only returns uint64 (part of what GenX can return), please don't use the word register in this decription.