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

[SYCL] Remove old style interop #448

Merged
merged 7 commits into from
Sep 16, 2021
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
17 changes: 0 additions & 17 deletions SYCL/Basic/event_creation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -22,21 +22,4 @@ int main() {
} catch (cl::sycl::device_error e) {
std::cout << "Failed to create device for event" << std::endl;
}
try {
std::cout << "Try create OpenCL event" << std::endl;
cl::sycl::context c;
if (!c.is_host()) {
::cl_int error;
cl_event u_e = clCreateUserEvent(c.get(), &error);
cl::sycl::event cl_e(u_e, c);
std::cout << "OpenCL event: " << std::hex << cl_e.get()
<< ((cl_e.get() == u_e) ? " matches " : " does not match ")
<< u_e << std::endl;

} else {
std::cout << "Failed to create OpenCL context" << std::endl;
}
} catch (cl::sycl::device_error e) {
std::cout << "Failed to create device for context" << std::endl;
}
}
14 changes: 8 additions & 6 deletions SYCL/Basic/fpga_tests/fpga_queue.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,7 @@
// REQUIRES: opencl, opencl_icd

// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out %opencl_lib
// RUN: %HOST_RUN_PLACEHOLDER %t.out
// RUN: %ACC_RUN_PLACEHOLDER %t.out
// RUN: %CPU_RUN_PLACEHOLDER %t.out
// RUN: %GPU_RUN_PLACEHOLDER %t.out

//==------------- fpga_queue.cpp - SYCL FPGA queues test -------------------==//
//
Expand All @@ -14,6 +11,7 @@
//
//===----------------------------------------------------------------------===//
#include <CL/sycl.hpp>
#include <CL/sycl/backend/opencl.hpp>
#include <iostream>
#include <set>

Expand All @@ -25,7 +23,7 @@ const int maxNumQueues = 256;
void GetCLQueue(event sycl_event, std::set<cl_command_queue> &cl_queues) {
try {
cl_command_queue cl_queue;
cl_event cl_event = sycl_event.get();
cl_event cl_event = get_native<backend::opencl>(sycl_event);
cl_int error = clGetEventInfo(cl_event, CL_EVENT_COMMAND_QUEUE,
sizeof(cl_queue), &cl_queue, nullptr);
assert(CL_SUCCESS == error && "Failed to obtain queue from OpenCL event");
Expand Down Expand Up @@ -108,7 +106,9 @@ int main() {
int result = cl_queues.size();
device dev = Queue.get_device();
int expected_result =
dev.is_host() ? 0 : getExpectedQueueNumber(dev.get(), 3);
dev.is_host()
? 0
: getExpectedQueueNumber(get_native<backend::opencl>(dev), 3);

if (expected_result != result) {
std::cout << "Result Num of queues = " << result << std::endl
Expand Down Expand Up @@ -149,7 +149,9 @@ int main() {
int result = cl_queues.size();
device dev = Queue.get_device();
int expected_result =
dev.is_host() ? 0 : getExpectedQueueNumber(dev.get(), maxNumQueues);
dev.is_host() ? 0
: getExpectedQueueNumber(get_native<backend::opencl>(dev),
maxNumQueues);

if (expected_result != result) {
std::cout << "Result Num of queues = " << result << std::endl
Expand Down
8 changes: 5 additions & 3 deletions SYCL/Basic/queue/queue.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//
//===----------------------------------------------------------------------===//
#include <CL/sycl.hpp>
#include <CL/sycl/backend/opencl.hpp>
#include <iostream>

using namespace cl::sycl;
Expand All @@ -23,7 +24,7 @@ void print_queue_info(const queue &q) {
q.get_context().get_platform().get_backend() !=
cl::sycl::backend::opencl)
? nullptr
: q.get())
: sycl::get_native<sycl::backend::opencl>(q))
<< std::endl;
std::cout << "queue wraps " << get_type(q.get_device()) << " device"
<< std::endl;
Expand All @@ -50,7 +51,7 @@ int main() {
assert(deviceA.is_host() == MovedQueue.is_host());
if (!deviceA.is_host() &&
deviceA.get_platform().get_backend() == cl::sycl::backend::opencl) {
assert(MovedQueue.get() != nullptr);
assert(sycl::get_native<sycl::backend::opencl>(MovedQueue) != nullptr);
}
}
{
Expand All @@ -63,7 +64,8 @@ int main() {
assert(deviceA.is_host() == WillMovedQueue.is_host());
if (!deviceA.is_host() &&
deviceA.get_platform().get_backend() == cl::sycl::backend::opencl) {
assert(WillMovedQueue.get() != nullptr);
assert(sycl::get_native<sycl::backend::opencl>(WillMovedQueue) !=
nullptr);
}
}
{
Expand Down
6 changes: 4 additions & 2 deletions SYCL/Basic/subdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//

#include <CL/sycl.hpp>
#include <CL/sycl/backend/opencl.hpp>
#include <algorithm>
#include <cassert>
#include <iostream>
Expand Down Expand Up @@ -50,8 +51,9 @@ int main() {
SubDevicesEq[0].get_info<info::device::partition_type_property>() ==
info::partition_property::partition_equally);

assert(SubDevicesEq[0].get_info<info::device::parent_device>().get() ==
dev.get());
assert(sycl::get_native<sycl::backend::opencl>(
SubDevicesEq[0].get_info<info::device::parent_device>()) ==
sycl::get_native<sycl::backend::opencl>(dev));
} catch (feature_not_supported) {
// okay skip it
}
Expand Down
6 changes: 4 additions & 2 deletions SYCL/Basic/subsubdevice.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
//===----------------------------------------------------------------------===//

#include <CL/sycl.hpp>
#include <CL/sycl/backend/opencl.hpp>
#include <algorithm>
#include <cassert>
#include <iostream>
Expand Down Expand Up @@ -51,8 +52,9 @@ int main() {
SubDevicesEq[0].get_info<info::device::partition_type_property>() ==
info::partition_property::partition_equally);

assert(SubDevicesEq[0].get_info<info::device::parent_device>().get() ==
dev.get());
assert(sycl::get_native<sycl::backend::opencl>(
SubDevicesEq[0].get_info<info::device::parent_device>()) ==
sycl::get_native<sycl::backend::opencl>(dev));
} catch (feature_not_supported) {
// okay skip it
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// REQUIRES: opencl, opencl_icd

// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out %opencl_lib
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -D__SYCL_INTERNAL_API -o %t.out %opencl_lib
// RUN: %CPU_RUN_PLACEHOLDER %t.out
// RUN: %GPU_RUN_PLACEHOLDER %t.out
// RUN: %ACC_RUN_PLACEHOLDER %t.out
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// REQUIRES: opencl

// RUN: %clangxx -fsycl %s -o %t.run
// RUN: %clangxx -fsycl -D__SYCL_INTERNAL_API %s -o %t.run
// RUN: %GPU_RUN_PLACEHOLDER %t.run
// RUN: %CPU_RUN_PLACEHOLDER %t.run
// RUN: %ACC_RUN_PLACEHOLDER %t.run
Expand Down Expand Up @@ -43,4 +43,4 @@ int main() {
assert(P1 == P3 && "Platform impls are different");

return 0;
}
}
36 changes: 36 additions & 0 deletions SYCL/DeprecatedFeatures/event_creation_opencl.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
// REQUIRES: opencl, opencl_icd

// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -D__SYCL_INTERNAL_API %s -o %t.out %opencl_lib
// RUN: %HOST_RUN_PLACEHOLDER %t.out
// RUN: %CPU_RUN_PLACEHOLDER %t.out
// RUN: %GPU_RUN_PLACEHOLDER %t.out

//==--------------- event.cpp - SYCL event test ----------------------------==//
//
// 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 <CL/sycl.hpp>
#include <iostream>

int main() {
try {
std::cout << "Try create OpenCL event" << std::endl;
cl::sycl::context c;
if (!c.is_host()) {
::cl_int error;
cl_event u_e = clCreateUserEvent(c.get(), &error);
cl::sycl::event cl_e(u_e, c);
std::cout << "OpenCL event: " << std::hex << cl_e.get()
<< ((cl_e.get() == u_e) ? " matches " : " does not match ")
<< u_e << std::endl;

} else {
std::cout << "Failed to create OpenCL context" << std::endl;
}
} catch (cl::sycl::device_error e) {
std::cout << "Failed to create device for context" << std::endl;
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// REQUIRES: opencl, opencl_icd

// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out %opencl_lib
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -D__SYCL_INTERNAL_API -o %t.out %opencl_lib
// RUN: %HOST_RUN_PLACEHOLDER %t.out
// RUN: %CPU_RUN_PLACEHOLDER %t.out
// RUN: %GPU_RUN_PLACEHOLDER %t.out
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// REQUIRES: opencl, opencl_icd

// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out %opencl_lib
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -D__SYCL_INTERNAL_API %s -o %t.out %opencl_lib
// RUN: %CPU_RUN_PLACEHOLDER %t.out
// RUN: %GPU_RUN_PLACEHOLDER %t.out
// RUN: %ACC_RUN_PLACEHOLDER %t.out
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// REQUIRES: opencl

// RUN: %clangxx -fsycl %s -o %t.out
// RUN: %clangxx -fsycl %s -D__SYCL_INTERNAL_API -o %t.out
// RUN: %CPU_RUN_PLACEHOLDER %t.out
// RUN: %GPU_RUN_PLACEHOLDER %t.out
// RUN: %ACC_RUN_PLACEHOLDER %t.out
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// REQUIRES: opencl, opencl_icd

// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out %opencl_lib
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -D__SYCL_INTERNAL_API %s -o %t.out %opencl_lib
// RUN: %CPU_RUN_PLACEHOLDER %t.out
// RUN: %GPU_RUN_PLACEHOLDER %t.out
// RUN: %ACC_RUN_PLACEHOLDER %t.out
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -D__SYCL_INTERNAL_API %s -o %t.out
// RUN: env SYCL_DEVICE_FILTER=host,%sycl_be %t.out
//==--------------- platform.cpp - SYCL platform test ----------------------==//
//
Expand Down
129 changes: 129 additions & 0 deletions SYCL/DeprecatedFeatures/queue_old_interop.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -D__SYCL_INTERNAL_API %s -o %t.out
// RUN: %BE_RUN_PLACEHOLDER %t.out
//==-------- queue_old_interop.cpp - SYCL queue OpenCL interop test --------==//
//
// 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 <CL/sycl.hpp>
#include <iostream>

using namespace cl::sycl;

std::string get_type(const device &dev) {
return ((dev.is_host()) ? "host"
: (dev.is_gpu() ? "OpenCL.GPU" : "OpenCL.CPU"));
}

void print_queue_info(const queue &q) {
std::cout << "ID=" << std::hex
<< ((q.get_device().is_host() ||
q.get_context().get_platform().get_backend() !=
cl::sycl::backend::opencl)
? nullptr
: q.get())
<< std::endl;
std::cout << "queue wraps " << get_type(q.get_device()) << " device"
<< std::endl;
}
int main() {
try {
std::cout << "Create default queue." << std::endl;
queue q;
print_queue_info(q);

} 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;
queue Queue(deviceA);
size_t hash = std::hash<queue>()(Queue);
queue MovedQueue(std::move(Queue));
assert(hash == std::hash<queue>()(MovedQueue));
assert(deviceA.is_host() == MovedQueue.is_host());
if (!deviceA.is_host() &&
deviceA.get_platform().get_backend() == cl::sycl::backend::opencl) {
assert(MovedQueue.get() != nullptr);
}
}
{
std::cout << "move assignment operator" << std::endl;
queue Queue(deviceA);
size_t hash = std::hash<queue>()(Queue);
queue WillMovedQueue(deviceB);
WillMovedQueue = std::move(Queue);
assert(hash == std::hash<queue>()(WillMovedQueue));
assert(deviceA.is_host() == WillMovedQueue.is_host());
if (!deviceA.is_host() &&
deviceA.get_platform().get_backend() == cl::sycl::backend::opencl) {
assert(WillMovedQueue.get() != nullptr);
}
}
{
std::cout << "copy constructor" << std::endl;
queue Queue(deviceA);
size_t hash = std::hash<queue>()(Queue);
queue QueueCopy(Queue);
assert(hash == std::hash<queue>()(Queue));
assert(hash == std::hash<queue>()(QueueCopy));
assert(Queue == QueueCopy);
assert(Queue.is_host() == QueueCopy.is_host());
}
{
std::cout << "copy assignment operator" << std::endl;
queue Queue(deviceA);
size_t hash = std::hash<queue>()(Queue);
queue WillQueueCopy(deviceB);
WillQueueCopy = Queue;
assert(hash == std::hash<queue>()(Queue));
assert(hash == std::hash<queue>()(WillQueueCopy));
assert(Queue == WillQueueCopy);
assert(Queue.is_host() == WillQueueCopy.is_host());
}

{
property_list pl = {};
queue Queue(pl);
try {
Queue.throw_asynchronous();
} catch (const std::bad_function_call &e) {
std::cout << "Default asynchronous handler call failed: " << e.what()
<< std::endl;
throw;
}
}

{
default_selector Selector;
device Device = Selector.select_device();
context Context(Device);
queue Queue(Context, Selector);
assert(Context == Queue.get_context());
}

{
context Context(deviceA);
queue Queue(Context, deviceA);
assert(Context == Queue.get_context());
}

if (devices.size() > 1) {
bool GotException = false;
try {
context Context(deviceA);
queue Queue(Context, deviceB);
assert(Context == Queue.get_context());
} catch (std::exception &e) {
std::cout << "Exception check passed: " << e.what() << std::endl;
GotException = true;
}
assert(GotException);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// REQUIRES: opencl, opencl_icd

// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out %opencl_lib
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -D__SYCL_INTERNAL_API -o %t.out %opencl_lib
// RUN: %CPU_RUN_PLACEHOLDER %t.out
// RUN: %GPU_RUN_PLACEHOLDER %t.out
// RUN: %ACC_RUN_PLACEHOLDER %t.out
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// REQUIRES: opencl, opencl_icd

// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out %opencl_lib -O3
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -D__SYCL_INTERNAL_API -o %t.out %opencl_lib -O3
// RUN: %CPU_RUN_PLACEHOLDER %t.out
// RUN: %GPU_RUN_PLACEHOLDER %t.out
// RUN: %ACC_RUN_PLACEHOLDER %t.out
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
// REQUIRES: opencl, opencl_icd

// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out %opencl_lib
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple -D__SYCL_INTERNAL_API %s -o %t.out %opencl_lib
// RUN: %CPU_RUN_PLACEHOLDER %t.out
// RUN: %GPU_RUN_PLACEHOLDER %t.out
// RUN: %ACC_RUN_PLACEHOLDER %t.out
Expand Down
Loading