Skip to content

Commit 898de60

Browse files
sergey-semenovvladimirlaz
authored andcommitted
[SYCL] Fix struct_kernel_param test
Switch from using memcmp to field by field comparison. Previous approach lead to failure on GPU due to differing padding bits. Applied clang-format. Signed-off-by: Vladimir Lazarev <vladimir.lazarev@intel.com> Signed-off-by: Sergey Semenov <sergey.semenov@intel.com>
1 parent 2b26dcb commit 898de60

File tree

1 file changed

+24
-13
lines changed

1 file changed

+24
-13
lines changed

sycl/test/struct_param/struct_kernel_param.cpp

Lines changed: 24 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,30 @@
1414
//===----------------------------------------------------------------------===//
1515

1616
#include <CL/sycl.hpp>
17+
#include <algorithm>
1718
#include <cstring>
1819
#include <iostream>
20+
#include <iterator>
1921

2022
using namespace cl::sycl;
2123

2224
struct MyNestedStruct {
25+
bool operator==(const MyNestedStruct &Rhs) {
26+
return (FldArr[0] == Rhs.FldArr[0] && FldFloat == Rhs.FldFloat);
27+
}
2328
cl::sycl::cl_char FldArr[1];
2429
cl::sycl::cl_float FldFloat;
2530
};
2631

2732
struct MyStruct {
33+
bool operator==(const MyStruct &Rhs) {
34+
return (FldChar == Rhs.FldChar && FldLong == Rhs.FldLong &&
35+
FldShort == Rhs.FldShort && FldUint == Rhs.FldUint &&
36+
FldStruct == Rhs.FldStruct &&
37+
std::equal(std::begin(FldArr), std::end(FldArr),
38+
std::begin(Rhs.FldArr)) &&
39+
FldInt == Rhs.FldInt);
40+
}
2841
cl::sycl::cl_char FldChar;
2942
cl::sycl::cl_long FldLong;
3043
cl::sycl::cl_short FldShort;
@@ -46,7 +59,7 @@ static void printStruct(const MyStruct &S0) {
4659

4760
bool test0() {
4861
MyStruct S = GlobS;
49-
MyStruct S0 = { 0 };
62+
MyStruct S0 = {0};
5063
{
5164
buffer<MyStruct, 1> Buf(&S0, range<1>(1));
5265
queue myQueue;
@@ -55,7 +68,7 @@ bool test0() {
5568
cgh.single_task<class MyKernel>([=] { B[0] = S; });
5669
});
5770
}
58-
bool Passed = (std::memcmp(&S0, &S, sizeof(MyStruct)) == 0);
71+
bool Passed = (S == S0);
5972

6073
if (!Passed) {
6174
std::cout << "test0 failed" << std::endl;
@@ -72,15 +85,14 @@ bool test0() {
7285
bool test1() {
7386
range<3> ice(8, 9, 10);
7487
uint ice2 = 888;
75-
uint result[4] = { 0 };
88+
uint result[4] = {0};
7689

7790
{
7891
buffer<unsigned int, 1> Buffer((unsigned int *)result, range<1>(4));
7992
queue myQueue;
8093
myQueue.submit([&](handler &cgh) {
8194
auto B = Buffer.get_access<access::mode::write>(cgh);
82-
cgh.parallel_for<class bufferByRange_cap>(range<1>{ 4 },
83-
[=](id<1> index) {
95+
cgh.parallel_for<class bufferByRange_cap>(range<1>{4}, [=](id<1> index) {
8496
B[index.get(0)] = index.get(0) > 2 ? ice2 : ice.get(index.get(0));
8597
});
8698
});
@@ -111,17 +123,16 @@ int main(int argc, char **argv) {
111123
cl::sycl::cl_long PartLong = ((cl::sycl::cl_long)argc) << 32;
112124
cl::sycl::cl_float PartFloat = argc;
113125

114-
GlobS = { PartChar,
115-
PartLong,
116-
PartShort,
117-
PartUint,
118-
{ { PartChar }, PartFloat },
119-
{ PartShort, PartShort, PartShort },
120-
PartInt };
126+
GlobS = {PartChar,
127+
PartLong,
128+
PartShort,
129+
PartUint,
130+
{{PartChar}, PartFloat},
131+
{PartShort, PartShort, PartShort},
132+
PartInt};
121133

122134
bool Pass = test0() & test1();
123135

124136
std::cout << "Test " << (Pass ? "passed" : "FAILED") << std::endl;
125137
return Pass ? 0 : 1;
126138
}
127-

0 commit comments

Comments
 (0)