-
Notifications
You must be signed in to change notification settings - Fork 788
[SYCL] Add tests for inline asm feature #1444
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 2 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
7179d3a
[SYCL] Add tests for inline asm feature
MochalovaAn aa01a1d
[SYCL] Refactor inline asm tests to reduce code duplication
AlexeySachkov d67e0e9
Apply suggestion
MochalovaAn 29c858a
Small fix
MochalovaAn 0fc675d
Small fix
MochalovaAn 063e027
Small fix
MochalovaAn d4fb662
Small fix
MochalovaAn 8bb6e52
Correctly handle buffer
MochalovaAn 2efe78f
Move inline asm tests to feature tests
MochalovaAn aebe6a8
Apply suggestion
MochalovaAn 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// UNSUPPORTED: cuda | ||
// REQUIRES: gpu,linux | ||
// RUN: %clangxx -fsycl %s -DINLINE_ASM -o %t.out | ||
// RUN: %t.out | ||
// RUN: %clangxx -fsycl %s -o %t.ref.out | ||
// RUN: %t.ref.out | ||
|
||
#include "include/asmhelper.h" | ||
#include <CL/sycl.hpp> | ||
#include <iostream> | ||
#include <vector> | ||
|
||
using dataType = cl::sycl::cl_int; | ||
|
||
template <typename T = dataType> | ||
struct KernelFunctor : WithOutputBuffer<T> { | ||
KernelFunctor(size_t problem_size) : WithOutputBuffer<T>(problem_size) {} | ||
|
||
void operator()(cl::sycl::handler &cgh) { | ||
auto C = this->getOutputBuffer().template get_access<cl::sycl::access::mode::write>(cgh); | ||
cgh.parallel_for<KernelFunctor<T>>( | ||
cl::sycl::range<1>{this->getOutputBufferSize()}, [=](cl::sycl::id<1> wiID) [[cl::intel_reqd_sub_group_size(16)]] { | ||
C[wiID] = 43; | ||
#if defined(INLINE_ASM) && defined(__SYCL_DEVICE_ONLY__) | ||
asm volatile(""); | ||
#endif | ||
}); | ||
} | ||
}; | ||
|
||
int main() { | ||
KernelFunctor<> f(DEFAULT_PROBLEM_SIZE); | ||
if (!launchInlineASMTest(f)) | ||
return 0; | ||
|
||
if (verify_all_the_same(f.getOutputBufferData(), 43)) | ||
return 0; | ||
|
||
return 1; | ||
} |
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,44 @@ | ||
// UNSUPPORTED: cuda | ||
// REQUIRES: gpu,linux | ||
// RUN: %clangxx -fsycl %s -DINLINE_ASM -o %t.out | ||
// RUN: %t.out | ||
// RUN: %clangxx -fsycl %s -o %t.ref.out | ||
// RUN: %t.ref.out | ||
|
||
#include "include/asmhelper.h" | ||
#include <CL/sycl.hpp> | ||
#include <iostream> | ||
#include <vector> | ||
|
||
using dataType = cl::sycl::cl_int; | ||
|
||
template <typename T = dataType> | ||
struct KernelFunctor : WithOutputBuffer<T> { | ||
KernelFunctor(size_t problem_size) : WithOutputBuffer<T>(problem_size) {} | ||
|
||
void operator()(cl::sycl::handler &cgh) { | ||
auto C = this->getOutputBuffer().template get_access<cl::sycl::access::mode::write>(cgh); | ||
cgh.parallel_for<KernelFunctor<T>>( | ||
cl::sycl::range<1>{this->getOutputBufferSize()}, [=](cl::sycl::id<1> wiID) [[cl::intel_reqd_sub_group_size(16)]] { | ||
volatile int output = 0; | ||
#if defined(INLINE_ASM) && defined(__SYCL_DEVICE_ONLY__) | ||
asm volatile("mov (M1,16) %0(0,0)<1> 0x7:d" | ||
: "=rw"(output)); | ||
#else | ||
output = 7; | ||
#endif | ||
C[wiID] = output; | ||
}); | ||
} | ||
}; | ||
|
||
int main() { | ||
KernelFunctor<> f(DEFAULT_PROBLEM_SIZE); | ||
if (!launchInlineASMTest(f)) | ||
return 0; | ||
|
||
if (verify_all_the_same(f.getOutputBufferData(), 7)) | ||
return 0; | ||
|
||
return 1; | ||
} |
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,44 @@ | ||
// UNSUPPORTED: cuda | ||
// REQUIRES: gpu,linux | ||
// RUN: %clangxx -fsycl %s -DINLINE_ASM -o %t.out | ||
// RUN: %t.out | ||
// RUN: %clangxx -fsycl %s -o %t.ref.out | ||
// RUN: %t.ref.out | ||
|
||
#include "include/asmhelper.h" | ||
#include <CL/sycl.hpp> | ||
#include <iostream> | ||
#include <vector> | ||
|
||
using dataType = cl::sycl::cl_int; | ||
|
||
template <typename T = dataType> | ||
struct KernelFunctor : WithOutputBuffer<T> { | ||
KernelFunctor(size_t problem_size) : WithOutputBuffer<T>(problem_size) {} | ||
|
||
void operator()(cl::sycl::handler &cgh) { | ||
auto C = this->getOutputBuffer().template get_access<cl::sycl::access::mode::write>(cgh); | ||
cgh.parallel_for<KernelFunctor<T>>( | ||
cl::sycl::range<1>{this->getOutputBufferSize()}, [=](cl::sycl::id<1> wiID) [[cl::intel_reqd_sub_group_size(16)]] { | ||
volatile int output = 0; | ||
#if defined(INLINE_ASM) && defined(__SYCL_DEVICE_ONLY__) | ||
asm volatile("mov (M1,16) %0(0,0)<1> 0x7:d" | ||
: "=rw"(output)); | ||
#else | ||
output = 7; | ||
#endif | ||
C[wiID] = output; | ||
}); | ||
} | ||
}; | ||
|
||
int main() { | ||
KernelFunctor<> f(DEFAULT_PROBLEM_SIZE); | ||
if (!launchInlineASMTest(f)) | ||
return 0; | ||
|
||
if (verify_all_the_same(f.getOutputBufferData(), 7)) | ||
return 0; | ||
|
||
return 1; | ||
} |
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,45 @@ | ||
// UNSUPPORTED: cuda | ||
// REQUIRES: gpu,linux | ||
// RUN: %clangxx -fsycl %s -DINLINE_ASM -o %t.out | ||
// RUN: %t.out | ||
// RUN: %clangxx -fsycl %s -o %t.ref.out | ||
// RUN: %t.ref.out | ||
|
||
#include "include/asmhelper.h" | ||
#include <CL/sycl.hpp> | ||
#include <iostream> | ||
#include <vector> | ||
|
||
using dataType = cl::sycl::cl_int; | ||
|
||
template <typename T = dataType> | ||
struct KernelFunctor : WithOutputBuffer<T> { | ||
KernelFunctor(size_t problem_size) : WithOutputBuffer<T>(problem_size) {} | ||
|
||
void operator()(cl::sycl::handler &cgh) { | ||
auto C = this->getOutputBuffer().template get_access<cl::sycl::access::mode::write>(cgh); | ||
cgh.parallel_for<KernelFunctor<T>>( | ||
cl::sycl::range<1>{this->getOutputBufferSize()}, [=](cl::sycl::id<1> wiID) [[cl::intel_reqd_sub_group_size(16)]] { | ||
for (int i = 0; i < 10; ++i) { | ||
#if defined(INLINE_ASM) && defined(__SYCL_DEVICE_ONLY__) | ||
asm("fence_sw"); | ||
C[wiID] += i; | ||
|
||
#else | ||
C[wiID] += i; | ||
#endif | ||
} | ||
}); | ||
} | ||
}; | ||
|
||
int main() { | ||
KernelFunctor<> f(DEFAULT_PROBLEM_SIZE); | ||
if (!launchInlineASMTest(f)) | ||
return 0; | ||
|
||
if (verify_all_the_same(f.getOutputBufferData(), 45)) | ||
return 0; | ||
|
||
return 1; | ||
} |
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,40 @@ | ||
// UNSUPPORTED: cuda | ||
// REQUIRES: gpu,linux | ||
// RUN: %clangxx -fsycl %s -DINLINE_ASM -o %t.out | ||
// RUN: %t.out | ||
// RUN: %clangxx -fsycl %s -o %t.ref.out | ||
// RUN: %t.ref.out | ||
|
||
#include "include/asmhelper.h" | ||
#include <CL/sycl.hpp> | ||
#include <iostream> | ||
#include <vector> | ||
|
||
using dataType = cl::sycl::cl_int; | ||
|
||
template <typename T = dataType> | ||
struct KernelFunctor : WithOutputBuffer<T> { | ||
KernelFunctor(size_t problem_size) : WithOutputBuffer<T>(problem_size) {} | ||
|
||
void operator()(cl::sycl::handler &cgh) { | ||
auto C = this->getOutputBuffer().template get_access<cl::sycl::access::mode::write>(cgh); | ||
cgh.parallel_for<KernelFunctor<T>>( | ||
cl::sycl::range<1>{this->getOutputBufferSize()}, [=](cl::sycl::id<1> wiID) [[cl::intel_reqd_sub_group_size(8)]] { | ||
C[wiID] = 43; | ||
#if defined(INLINE_ASM) && defined(__SYCL_DEVICE_ONLY__) | ||
asm volatile(""); | ||
#endif | ||
}); | ||
} | ||
}; | ||
|
||
int main() { | ||
KernelFunctor<> f(DEFAULT_PROBLEM_SIZE); | ||
if (!launchInlineASMTest(f)) | ||
return 0; | ||
|
||
if (verify_all_the_same(f.getOutputBufferData(), 43)) | ||
return 0; | ||
|
||
return 1; | ||
} |
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,44 @@ | ||
// UNSUPPORTED: cuda | ||
// REQUIRES: gpu,linux | ||
// RUN: %clangxx -fsycl %s -DINLINE_ASM -o %t.out | ||
// RUN: %t.out | ||
// RUN: %clangxx -fsycl %s -o %t.ref.out | ||
// RUN: %t.ref.out | ||
|
||
#include "include/asmhelper.h" | ||
#include <CL/sycl.hpp> | ||
#include <iostream> | ||
#include <vector> | ||
|
||
using dataType = cl::sycl::cl_int; | ||
|
||
template <typename T = dataType> | ||
struct KernelFunctor : WithOutputBuffer<T> { | ||
KernelFunctor(size_t problem_size) : WithOutputBuffer<T>(problem_size) {} | ||
|
||
void operator()(cl::sycl::handler &cgh) { | ||
auto C = this->getOutputBuffer().template get_access<cl::sycl::access::mode::write>(cgh); | ||
cgh.parallel_for<KernelFunctor<T>>( | ||
cl::sycl::range<1>{this->getOutputBufferSize()}, [=](cl::sycl::id<1> wiID) [[cl::intel_reqd_sub_group_size(8)]] { | ||
volatile int output = 0; | ||
#if defined(INLINE_ASM) && defined(__SYCL_DEVICE_ONLY__) | ||
asm volatile("mov (M1,8) %0(0,0)<1> 0x7:d" | ||
: "=rw"(output)); | ||
#else | ||
output = 7; | ||
#endif | ||
C[wiID] = output; | ||
}); | ||
} | ||
}; | ||
|
||
int main() { | ||
KernelFunctor<> f(DEFAULT_PROBLEM_SIZE); | ||
if (!launchInlineASMTest(f)) | ||
return 0; | ||
|
||
if (verify_all_the_same(f.getOutputBufferData(), 7)) | ||
return 0; | ||
|
||
return 1; | ||
} |
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,59 @@ | ||
// UNSUPPORTED: cuda | ||
// REQUIRES: gpu,linux | ||
// RUN: %clangxx -fsycl %s -DINLINE_ASM -o %t.out | ||
// RUN: %t.out | ||
// RUN: %clangxx -fsycl %s -o %t.ref.out | ||
// RUN: %t.ref.out | ||
|
||
#include "include/asmhelper.h" | ||
#include <CL/sycl.hpp> | ||
#include <iostream> | ||
#include <vector> | ||
|
||
using dataType = cl::sycl::cl_int; | ||
|
||
template <typename T = dataType> | ||
struct KernelFunctor : WithInputBuffers<T, 3>, WithOutputBuffer<T> { | ||
KernelFunctor(const std::vector<T> &input1, const std::vector<T> &input2, const std::vector<T> &input3) : WithInputBuffers<T, 3>(input1, input2, input3), WithOutputBuffer<T>(input1.size()) {} | ||
|
||
void operator()(cl::sycl::handler &cgh) { | ||
auto A = this->getInputBuffer(0).template get_access<cl::sycl::access::mode::read>(cgh); | ||
auto B = this->getInputBuffer(1).template get_access<cl::sycl::access::mode::read>(cgh); | ||
auto C = this->getInputBuffer(2).template get_access<cl::sycl::access::mode::read>(cgh); | ||
auto D = this->getOutputBuffer().template get_access<cl::sycl::access::mode::write>(cgh); | ||
|
||
cgh.parallel_for<KernelFunctor<T>>( | ||
cl::sycl::range<1>{this->getOutputBufferSize()}, [=](cl::sycl::id<1> wiID) [[cl::intel_reqd_sub_group_size(8)]] { | ||
#if defined(INLINE_ASM) && defined(__SYCL_DEVICE_ONLY__) | ||
asm("mad (M1, 8) %0(0, 0)<1> %3(0, 0)<1;1,0> %1(0, 0)<1;1,0> %2(0, 0)<1;1,0>" | ||
: "=rw"(D[wiID]) | ||
: "rw"(B[wiID]), "rw"(C[wiID]), "rw"(A[wiID])); | ||
#else | ||
D[wiID] = A[wiID] * B[wiID] + C[wiID]; | ||
#endif | ||
}); | ||
} | ||
}; | ||
|
||
int main() { | ||
std::vector<dataType> inputA(DEFAULT_PROBLEM_SIZE), inputB(DEFAULT_PROBLEM_SIZE), inputC(DEFAULT_PROBLEM_SIZE); | ||
for (int i = 0; i < DEFAULT_PROBLEM_SIZE; i++) { | ||
inputA[i] = i; | ||
inputB[i] = i; | ||
inputC[i] = DEFAULT_PROBLEM_SIZE - i * i; | ||
} | ||
|
||
KernelFunctor<> f(inputA, inputB, inputC); | ||
if (!launchInlineASMTest(f)) | ||
return 0; | ||
|
||
auto &D = f.getOutputBufferData(); | ||
for (int i = 0; i < DEFAULT_PROBLEM_SIZE; ++i) { | ||
if (D[i] != inputA[i] * inputB[i] + inputC[i]) { | ||
std::cerr << "At index: " << i << ". "; | ||
std::cerr << D[i] << " != " << inputA[i] * inputB[i] + inputC[i] << "\n"; | ||
return 1; | ||
} | ||
} | ||
return 0; | ||
} |
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,67 @@ | ||
// UNSUPPORTED: cuda | ||
// REQUIRES: gpu,linux | ||
// RUN: %clangxx -fsycl %s -DINLINE_ASM -o %t.out | ||
// RUN: %t.out | ||
// RUN: %clangxx -fsycl %s -o %t.ref.out | ||
// RUN: %t.ref.out | ||
|
||
#include "include/asmhelper.h" | ||
#include <CL/sycl.hpp> | ||
#include <iostream> | ||
#include <vector> | ||
|
||
using dataType = cl::sycl::cl_int; | ||
|
||
template <typename T = dataType> | ||
struct KernelFunctor : WithInputBuffers<T, 2>, WithOutputBuffer<T> { | ||
KernelFunctor(const std::vector<T> &input1, const std::vector<T> &input2) : WithInputBuffers<T, 2>(input1, input2), WithOutputBuffer<T>(input1.size()) {} | ||
|
||
void operator()(cl::sycl::handler &cgh) { | ||
auto A = this->getInputBuffer(0).template get_access<cl::sycl::access::mode::read>(cgh); | ||
auto B = this->getInputBuffer(1).template get_access<cl::sycl::access::mode::read>(cgh); | ||
auto C = this->getOutputBuffer().template get_access<cl::sycl::access::mode::write>(cgh); | ||
|
||
cgh.parallel_for<KernelFunctor<T>>( | ||
cl::sycl::range<1>{this->getOutputBufferSize()}, | ||
[=](cl::sycl::id<1> wiID) [[cl::intel_reqd_sub_group_size(16)]] { | ||
// declaration of temp within and outside the scope | ||
#if defined(INLINE_ASM) && defined(__SYCL_DEVICE_ONLY__) | ||
asm("{\n" | ||
".decl temp v_type=G type=d num_elts=16 align=GRF\n" | ||
"mov (M1, 16) temp(0, 0)<1> %1(0, 0)<1;1,0>\n" | ||
"mov (M1, 16) %0(0, 0)<1> temp(0, 0)<1;1,0>\n" | ||
"}\n" | ||
".decl temp v_type=G type=d num_elts=16 align=GRF\n" | ||
"mul (M1, 16) temp(0, 0)<1> %2(0, 0)<1;1,0> %0(0, 0)<1;1,0>\n" | ||
"mov (M1, 16) %0(0, 0)<1> temp(0, 0)<1;1,0>\n" | ||
: "+rw"(C[wiID]) | ||
: "rw"(A[wiID]), "rw"(B[wiID])); | ||
#else | ||
C[wiID] = A[wiID]; | ||
C[wiID] *= B[wiID]; | ||
#endif | ||
}); | ||
} | ||
}; | ||
|
||
int main() { | ||
std::vector<dataType> inputA(DEFAULT_PROBLEM_SIZE), inputB(DEFAULT_PROBLEM_SIZE); | ||
for (int i = 0; i < DEFAULT_PROBLEM_SIZE; i++) { | ||
inputA[i] = i; | ||
inputB[i] = 2; | ||
} | ||
|
||
KernelFunctor<> f(inputA, inputB); | ||
if (!launchInlineASMTest(f)) | ||
return 0; | ||
|
||
auto &C = f.getOutputBufferData(); | ||
for (int i = 0; i < DEFAULT_PROBLEM_SIZE; ++i) { | ||
if (C[i] != inputA[i] * inputB[i]) { | ||
std::cerr << "At index: " << i << ". "; | ||
std::cerr << C[i] << " != " << inputA[i] * inputB[i] << "\n"; | ||
return 1; | ||
} | ||
} | ||
return 0; | ||
} |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.