CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
112 lines
2.9 KiB
C++
112 lines
2.9 KiB
C++
// REQUIRES: any-device
|
|
// RUN: %clangxx -fsycl %s -o %t.out
|
|
// RUN: %t.out
|
|
|
|
#include <sycl/sycl.hpp>
|
|
|
|
#include <iostream>
|
|
|
|
struct Simple {
|
|
int *Data;
|
|
int Addition;
|
|
};
|
|
|
|
struct WrapperOfSimple {
|
|
int Addition;
|
|
Simple Obj;
|
|
};
|
|
|
|
struct NonTrivial {
|
|
int Addition;
|
|
int *Data;
|
|
|
|
NonTrivial(int *D, int A) : Data(D), Addition(A) {}
|
|
};
|
|
|
|
struct NonTrivialDerived : NonTrivial {
|
|
int AA = 0;
|
|
NonTrivialDerived(int *D, int A) : NonTrivial(D, A) {}
|
|
};
|
|
|
|
using namespace sycl;
|
|
|
|
int main() {
|
|
constexpr int NumOfElements = 7;
|
|
|
|
queue Q;
|
|
|
|
NonTrivial NonTrivialObj(sycl::malloc_shared<int>(NumOfElements, Q), 38);
|
|
NonTrivialDerived NonTrivialDerivedObj(
|
|
sycl::malloc_shared<int>(NumOfElements, Q), 39);
|
|
Simple SimpleObj = {sycl::malloc_shared<int>(NumOfElements, Q), 42};
|
|
WrapperOfSimple WrapperOfSimpleObj = {
|
|
300, {sycl::malloc_shared<int>(NumOfElements, Q), 100500}};
|
|
|
|
// Test simple struct containing pointer.
|
|
Q.parallel_for(NumOfElements, [=](id<1> Idx) {
|
|
SimpleObj.Data[Idx] = Idx + SimpleObj.Addition;
|
|
});
|
|
|
|
// Test simple non-trivial struct containing pointer.
|
|
Q.parallel_for(NumOfElements, [=](id<1> Idx) {
|
|
NonTrivialObj.Data[Idx] = Idx + NonTrivialObj.Addition;
|
|
});
|
|
|
|
// Test simple non-trivial derived struct containing pointer.
|
|
Q.parallel_for(NumOfElements, [=](id<1> Idx) {
|
|
NonTrivialDerivedObj.Data[Idx] = Idx + NonTrivialDerivedObj.Addition;
|
|
});
|
|
|
|
// Test nested struct containing pointer.
|
|
Q.parallel_for(NumOfElements, [=](id<1> Idx) {
|
|
WrapperOfSimpleObj.Obj.Data[Idx] = Idx + WrapperOfSimpleObj.Obj.Addition;
|
|
});
|
|
|
|
// Test array of structs containing pointers.
|
|
Simple SimpleArr[NumOfElements];
|
|
for (int i = 0; i < NumOfElements; ++i) {
|
|
SimpleArr[i].Data = sycl::malloc_shared<int>(NumOfElements, Q);
|
|
SimpleArr[i].Addition = 38 + i;
|
|
}
|
|
|
|
Q.parallel_for(range<2>(NumOfElements, NumOfElements), [=](item<2> Idx) {
|
|
SimpleArr[Idx.get_id(0)].Data[Idx.get_id(1)] =
|
|
Idx.get_id(1) + SimpleArr[Idx.get_id(0)].Addition;
|
|
});
|
|
|
|
Q.wait();
|
|
|
|
auto Checker = [](auto Obj) {
|
|
for (int i = 0; i < NumOfElements; ++i) {
|
|
if (Obj.Data[i] != (i + Obj.Addition)) {
|
|
std::cout << "line: " << __LINE__ << " result[" << i << "] is "
|
|
<< Obj.Data[i] << " expected " << i + Obj.Addition
|
|
<< std::endl;
|
|
return true; // true if fail
|
|
}
|
|
}
|
|
|
|
return false;
|
|
};
|
|
|
|
bool Fail = false;
|
|
Fail |= Checker(SimpleObj);
|
|
Fail |= Checker(NonTrivialObj);
|
|
Fail |= Checker(NonTrivialDerivedObj);
|
|
Fail |= Checker(WrapperOfSimpleObj.Obj);
|
|
|
|
for (int i = 0; i < NumOfElements; ++i)
|
|
Fail |= Checker(SimpleArr[i]);
|
|
|
|
// Free allocated memory.
|
|
sycl::free(NonTrivialObj.Data, Q);
|
|
sycl::free(NonTrivialDerivedObj.Data, Q);
|
|
sycl::free(SimpleObj.Data, Q);
|
|
sycl::free(WrapperOfSimpleObj.Obj.Data, Q);
|
|
|
|
for (int i = 0; i < NumOfElements; ++i)
|
|
sycl::free(SimpleArr[i].Data, Q);
|
|
|
|
return Fail;
|
|
}
|