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

[SYCL] Migrate remaining device-dependent in-tree LIT tests #1195

Merged
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
66 changes: 66 additions & 0 deletions SYCL/Basic/built-ins.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
// RUN: %CPU_RUN_PLACEHOLDER %t.out %CPU_CHECK_PLACEHOLDER
// RUN: %GPU_RUN_PLACEHOLDER %t.out %GPU_CHECK_PLACEHOLDER
// RUN: %ACC_RUN_PLACEHOLDER %t.out %ACC_CHECK_PLACEHOLDER

// CUDA does not support printf.
// UNSUPPORTED: cuda
//
// Hits an assertion with AMD:
// XFAIL: hip_amd

#include <sycl/sycl.hpp>

#include <cassert>

namespace s = sycl;

// According to OpenCL C spec, the format string must be in constant address
// space
#ifdef __SYCL_DEVICE_ONLY__
#define CONSTANT __attribute__((opencl_constant))
#else
#define CONSTANT
#endif

static const CONSTANT char format[] = "Hello, World! %d %f\n";

int main() {
s::queue q{};

// Test printf
q.submit([&](s::handler &CGH) {
CGH.single_task<class printf>([=]() {
s::ext::oneapi::experimental::printf(format, 123, 1.23);
// CHECK: {{(Hello, World! 123 1.23)?}}
});
}).wait();

s::ext::oneapi::experimental::printf(format, 321, 3.21);
// CHECK: {{(Hello, World! 123 1.23)?}}

// Test common
{
s::buffer<s::cl_float, 1> BufMin(s::range<1>(1));
s::buffer<s::cl_float2, 1> BufMax(s::range<1>(1));
q.submit([&](s::handler &cgh) {
auto AccMin = BufMin.get_access<s::access::mode::write>(cgh);
auto AccMax = BufMax.get_access<s::access::mode::write>(cgh);
cgh.single_task<class common>([=]() {
AccMax[0] = s::max(s::cl_float2{0.5f, 2.5}, s::cl_float2{2.3f, 2.3});
AccMin[0] = s::min(s::cl_float{0.5f}, s::cl_float{2.3f});
});
});

auto AccMin = BufMin.template get_access<s::access::mode::read>();
auto AccMax = BufMax.template get_access<s::access::mode::read>();

assert(AccMin[0] == 0.5);
assert(AccMax[0].x() == 2.3f && AccMax[0].y() == 2.5f);
assert(s::min(0.5f, 2.3f) == 0.5);
auto Res = s::max(s::int4{5, 2, 1, 5}, s::int4{3, 3, 4, 2});
assert(Res.x() == 5 && Res.y() == 3 && Res.z() == 4 && Res.w() == 5);
}

return 0;
}
83 changes: 83 additions & 0 deletions SYCL/Basic/context.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,83 @@
// 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 context class.

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

using namespace sycl;

int main() {
try {
context c;
} catch (device_error e) {
std::cout << "Failed to create device for context" << std::endl;
}

auto devices = device::get_devices();
device &deviceA = devices[0];
device &deviceB = (devices.size() > 1 ? devices[1] : devices[0]);
{
std::cout << "move constructor" << std::endl;
context Context(deviceA);
size_t hash = std::hash<context>()(Context);
context MovedContext(std::move(Context));
assert(hash == std::hash<context>()(MovedContext));
}
{
std::cout << "move assignment operator" << std::endl;
context Context(deviceA);
size_t hash = std::hash<context>()(Context);
context WillMovedContext(deviceB);
WillMovedContext = std::move(Context);
assert(hash == std::hash<context>()(WillMovedContext));
}
{
std::cout << "copy constructor" << std::endl;
context Context(deviceA);
size_t hash = std::hash<context>()(Context);
context ContextCopy(Context);
assert(hash == std::hash<context>()(Context));
assert(hash == std::hash<context>()(ContextCopy));
assert(Context == ContextCopy);
}
{
std::cout << "copy assignment operator" << std::endl;
context Context(deviceA);
size_t hash = std::hash<context>()(Context);
context WillContextCopy(deviceB);
WillContextCopy = Context;
assert(hash == std::hash<context>()(Context));
assert(hash == std::hash<context>()(WillContextCopy));
assert(Context == WillContextCopy);
}
{
auto AsyncHandler = [](const sycl::exception_list &EL) {};
sycl::context Context1(sycl::property_list{});
sycl::context Context2(AsyncHandler, sycl::property_list{});
sycl::context Context3(deviceA, sycl::property_list{});
sycl::context Context4(deviceA, AsyncHandler, sycl::property_list{});
sycl::context Context5(deviceA.get_platform(), sycl::property_list{});
sycl::context Context6(deviceA.get_platform(), AsyncHandler,
sycl::property_list{});
sycl::context Context7(std::vector<sycl::device>{deviceA},
sycl::property_list{});
sycl::context Context8(
std::vector<sycl::device>{deviceA}, AsyncHandler,
sycl::property_list{
sycl::ext::oneapi::cuda::property::context::use_primary_context{}});

if (!Context8.has_property<sycl::ext::oneapi::cuda::property::context::
use_primary_context>()) {
std::cerr << "Line " << __LINE__ << ": Property was not found"
<< std::endl;
return 1;
}

auto Prop = Context8.get_property<
sycl::ext::oneapi::cuda::property::context::use_primary_context>();
}
}
97 changes: 97 additions & 0 deletions SYCL/Basic/device.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
// 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 device class.

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

using namespace sycl;

std::string get_type(const device &dev) {
if (dev.is_gpu()) {
return "OpenCL.GPU";
} else if (dev.is_accelerator()) {
return "OpenCL.ACC";
} else {
return "OpenCL.CPU";
}
}

int main() {
device d;
std::cout << "Default device type: " << get_type(d) << std::endl;

int i = 1;
std::cout << "Get all devices in the system" << std::endl;
for (const auto &dev : device::get_devices()) {
std::cout << "Device " << i++ << " is available: " << get_type(dev)
<< std::endl;
}
i = 1;
std::cout << "Get host devices in the system" << std::endl;
for (const auto &dev : device::get_devices(info::device_type::host)) {
std::cout << "Device " << i++ << " is available: " << get_type(dev)
<< std::endl;
}
i = 1;
std::cout << "Get OpenCL.CPU devices in the system" << std::endl;
for (const auto &dev : device::get_devices(info::device_type::cpu)) {
std::cout << "Device " << i++ << " is available: " << get_type(dev)
<< std::endl;
}
i = 1;
std::cout << "Get OpenCL.GPU devices in the system" << std::endl;
for (const auto &dev : device::get_devices(info::device_type::gpu)) {
std::cout << "Device " << i++ << " is available: " << get_type(dev)
<< std::endl;
}
i = 1;
std::cout << "Get OpenCL.ACC devices in the system" << std::endl;
for (const auto &dev : device::get_devices(info::device_type::accelerator)) {
std::cout << "Device " << i++ << " is available: " << get_type(dev)
<< std::endl;
}

auto devices = device::get_devices();
device &deviceA = devices[0];
device &deviceB = (devices.size() > 1 ? devices[1] : devices[0]);
{
std::cout << "move constructor" << std::endl;
device Device(deviceA);
size_t hash = std::hash<device>()(Device);
device MovedDevice(std::move(Device));
assert(hash == std::hash<device>()(MovedDevice));
}
{
std::cout << "move assignment operator" << std::endl;
device Device(deviceA);
size_t hash = std::hash<device>()(Device);
device WillMovedDevice(deviceB);
WillMovedDevice = std::move(Device);
assert(hash == std::hash<device>()(WillMovedDevice));
}
{
std::cout << "copy constructor" << std::endl;
device Device(deviceA);
size_t hash = std::hash<device>()(Device);
device DeviceCopy(Device);
assert(hash == std::hash<device>()(Device));
assert(hash == std::hash<device>()(DeviceCopy));
assert(Device == DeviceCopy);
}
{
std::cout << "copy assignment operator" << std::endl;
device Device(deviceA);
size_t hash = std::hash<device>()(Device);
device WillDeviceCopy(deviceB);
WillDeviceCopy = Device;
assert(hash == std::hash<device>()(Device));
assert(hash == std::hash<device>()(WillDeviceCopy));
assert(Device == WillDeviceCopy);
}
}
42 changes: 42 additions & 0 deletions SYCL/Basic/event_async_exception.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
// 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

//==---- event_async_exception.cpp - Test for event async exceptions -------==//
//
// 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
//
//===----------------------------------------------------------------------===//

#include <sycl/sycl.hpp>

// This test checks that if there is a submit failure, the asynchronous
// exception is associated with the returned event.

using namespace sycl;

class KernelName;

int main() {
auto asyncHandler = [](exception_list el) {
for (auto &e : el) {
std::rethrow_exception(e);
}
};

queue q(asyncHandler);

try {
// Check that submitting a CG with no kernel or memory operation doesn't
// produce an async exception
event e = q.submit([&](handler &cgh) {});

e.wait_and_throw();
return 0;
} catch (runtime_error e) {
return 1;
}
}
Loading