Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.

[SYCL] Move more in-tree tests to the test-suite #1279

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
111 changes: 111 additions & 0 deletions SYCL/Basic/exceptions-SYCL-2020.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
// RUN: %CPU_RUN_PLACEHOLDER %t.out
// RUN: %GPU_RUN_PLACEHOLDER %t.out
// RUN: %ACC_RUN_PLACEHOLDER %t.out

#include <sycl/sycl.hpp>

using namespace sycl;

int main() {
// Test new constructors, initially each with empty string messages.
std::string emptyStr;
const char *emptyCharPtr = "";

// Going to set the error code values to each of the enum (0-12).
exception ex1(make_error_code(errc::runtime), emptyStr); // errc::runtime == 1
exception ex2(make_error_code(errc::kernel), emptyCharPtr);
exception ex3(make_error_code(errc::accessor));
exception ex4(static_cast<int>(errc::nd_range), sycl_category(), emptyStr);
exception ex5(static_cast<int>(errc::event), sycl_category(), emptyCharPtr);
exception ex6(static_cast<int>(errc::kernel_argument), sycl_category());

queue Q;
context ctx = Q.get_context();
exception ex7(ctx, make_error_code(errc::build), emptyStr);
exception ex8(ctx, make_error_code(errc::invalid), emptyCharPtr);
exception ex9(ctx, make_error_code(errc::memory_allocation));
exception ex10(ctx, static_cast<int>(errc::platform), sycl_category(),
emptyStr);
exception ex11(ctx, static_cast<int>(errc::profiling), sycl_category(),
emptyCharPtr);
exception ex12(ctx, static_cast<int>(errc::feature_not_supported),
sycl_category());

std::vector<exception> v{ex1, ex2, ex3, ex4, ex5, ex6,
ex7, ex8, ex9, ex10, ex11, ex12};
for (int i = 0; i < 12; i++) {
exception ex = v[i];
assert(ex.code().value() == i + 1 &&
"unexpected error_code.value() retrieved");
assert(ex.category() == sycl_category() && "expected SYCL error category");
if (i < 6) {
assert(!ex.has_context() &&
"none of the first six exceptions should have a context");
} else {
assert(ex.has_context() && ex.get_context() == ctx &&
"the second six exceptions should have a context equal to ctx");
}
assert(strlen(ex.what()) == 0 &&
"all these exceptions were initialized with empty strings. We "
"should not have anything in the 'what' message");
}

// Now test constructor with a real string value, including one containing
// null string terminator
std::string testString("this is a test");
exception ex_string1(make_error_code(errc::kernel_not_supported), testString);
assert(testString.compare(ex_string1.what()) == 0);
testString[0] = '\0';
exception ex_early_terminated(make_error_code(errc::kernel_not_supported),
testString);
assert(ex_early_terminated.code().value() ==
static_cast<int>(errc::kernel_not_supported));
char testCharPtr[] = "this is also a test";
exception ex_string2(make_error_code(errc::backend_mismatch), testCharPtr);
assert(strcmp(ex_string2.what(), testCharPtr) == 0);

// Test sycl_category.
assert(std::string("sycl").compare(sycl_category().name()) == 0 &&
"sycl_category name should be 'sycl'");

// Test make_error_code.
std::error_code ec = make_error_code(errc::feature_not_supported);
assert(ec.value() == static_cast<int>(errc::feature_not_supported));
assert(std::string("sycl").compare(ec.category().name()) == 0 &&
"error code category name should be 'sycl'");

// Test enum
static_assert(std::is_error_code_enum<sycl::errc>::value,
"errc enum should identify as error code");
static_assert(!std::is_error_condition_enum<sycl::errc>::value,
"errc enum should not identify as error condition");

// Test errc_for and backends. Should compile without complaint.
constexpr int EC = 1;
sycl::backend_traits<sycl::backend::opencl>::errc someOpenCLErrCode{EC};
sycl::errc_for<sycl::backend::opencl> anotherOpenCLErrCode{EC};
assert(someOpenCLErrCode == anotherOpenCLErrCode);
sycl::backend_traits<sycl::backend::ext_oneapi_level_zero>::errc
someL0ErrCode{EC};
sycl::errc_for<sycl::backend::ext_oneapi_level_zero> anotherL0ErrCode{EC};
assert(someL0ErrCode == anotherL0ErrCode);
sycl::backend_traits<sycl::backend::host>::errc someHOSTErrCode{EC};
sycl::errc_for<sycl::backend::host> anotherHOSTErrCode{EC};
assert(someHOSTErrCode == anotherHOSTErrCode);
sycl::backend_traits<sycl::backend::ext_oneapi_cuda>::errc someCUDAErrCode{
EC};
sycl::errc_for<sycl::backend::ext_oneapi_cuda> anotherCUDAErrCode{EC};
assert(someCUDAErrCode == anotherCUDAErrCode);
sycl::backend_traits<sycl::backend::ext_intel_esimd_emulator>::errc
someESIMDErrCode{EC};
sycl::errc_for<sycl::backend::ext_intel_esimd_emulator> anotherESIMDErrCode{
EC};
assert(someESIMDErrCode == anotherESIMDErrCode);
sycl::backend_traits<sycl::backend::ext_oneapi_hip>::errc someHIPErrCode{EC};
sycl::errc_for<sycl::backend::ext_oneapi_hip> anotherHIPErrCode{EC};
assert(someHIPErrCode == anotherHIPErrCode);

std::cout << "OK" << std::endl;
return 0;
}
17 changes: 17 additions & 0 deletions SYCL/Basic/library_loading.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// REQUIRES: linux
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
// RUN: env SYCL_PI_TRACE=-1 %t.out &> %t_trace.txt || true
// RUN: FileCheck --input-file=%t_trace.txt %s

// Checks pi traces on library loading
#include <sycl/sycl.hpp>

using namespace sycl;

int main() {
// CHECK: {{(SYCL_PI_TRACE\[-1\]: dlopen\(.*/libpi_cuda.so\) failed with)|(SYCL_PI_TRACE\[basic\]: Plugin found and successfully loaded: libpi_cuda.so)}}
// CHECK: {{(SYCL_PI_TRACE\[-1\]: dlopen\(.*/libpi_hip.so\) failed with)|(SYCL_PI_TRACE\[basic\]: Plugin found and successfully loaded: libpi_hip.so)}}
// CHECK: {{(SYCL_PI_TRACE\[-1\]: dlopen\(.*/libpi_esimd_emulator.so\) failed with)|(SYCL_PI_TRACE\[basic\]: Plugin found and successfully loaded: libpi_esimd_emulator.so)}}
queue q;
q.submit([&](handler &cgh) {});
}
82 changes: 82 additions & 0 deletions SYCL/Basic/property_list.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
// RUN: %CPU_RUN_PLACEHOLDER %t.out
// RUN: %GPU_RUN_PLACEHOLDER %t.out
// RUN: %ACC_RUN_PLACEHOLDER %t.out

// This test performs basic check of the SYCL property_list class.

#include <iostream>
#include <sycl/sycl.hpp>

namespace sycl_property = sycl::property;

int main() {
bool Failed = false;

{
sycl::property_list Empty{};
if (Empty.has_property<sycl_property::buffer::use_host_ptr>()) {
std::cerr << "Error: empty property list has property." << std::endl;
Failed = true;
}
}

{
sycl::context SYCLContext;
sycl_property::buffer::context_bound ContextBound(SYCLContext);

sycl::property_list SeveralProps{sycl_property::image::use_host_ptr(),
sycl_property::buffer::use_host_ptr(),
sycl_property::image::use_host_ptr(),
ContextBound};

if (!SeveralProps.has_property<sycl_property::buffer::use_host_ptr>()) {
std::cerr << "Error: property list has no property while should have."
<< std::endl;
Failed = true;
}

if (!SeveralProps.has_property<sycl_property::image::use_host_ptr>()) {
std::cerr << "Error: property list has no property while should have."
<< std::endl;
Failed = true;
}

try {
sycl_property::buffer::context_bound ContextBoundRet =
SeveralProps.get_property<sycl_property::buffer::context_bound>();
if (SYCLContext != ContextBoundRet.get_context()) {
std::cerr << "Error: returned SYCL context is not the same that was "
"passed to c'tor earlier."
<< std::endl;
Failed = true;
}

} catch (sycl::invalid_object_error &Error) {
Error.what();
std::cerr << "Error: exception was thrown in get_property method."
<< std::endl;
Failed = true;
}
}

{
sycl::property_list MemChannelProp{sycl_property::buffer::mem_channel(2)};
if (!MemChannelProp.has_property<sycl_property::buffer::mem_channel>()) {
std::cerr << "Error: property list has no property while should have."
<< std::endl;
Failed = true;
}
auto Prop =
MemChannelProp.get_property<sycl_property::buffer::mem_channel>();
if (Prop.get_channel() != 2) {
std::cerr << "Error: mem_channel property is not equal to 2."
<< std::endl;
Failed = true;
}
}

std::cerr << "Test status : " << (Failed ? "FAILED" : "PASSED") << std::endl;

return Failed;
}