Skip to content
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
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// REQUIRES: aspect-ext_oneapi_external_semaphore_import, aspect-usm_shared_allocations
// REQUIRES: aspect-ext_oneapi_external_semaphore_import
// REQUIRES: aspect-ext_intel_device_info_luid
// REQUIRES: windows, level_zero

Expand All @@ -10,10 +10,20 @@
// XFAIL-TRACKER: https://github.com/intel/llvm/issues/23249

// RUN: %{build} %link-directx -o %t.exe %if target-spir %{ -Wno-ignored-attributes %}
// RUN: env UR_L0_BATCH_SIZE=8 %{run} %t.exe
// RUN: env UR_L0_BATCH_SIZE=8 SYCL_UR_TRACE=2 UR_L0_DEBUG=1 %{run} %t.exe \
// RUN: 2>&1 | FileCheck --check-prefixes=CHECK%if level_zero_v2_adapter %{,CHECK-V2%} %else %{,CHECK-V1%} %s
//
// CHECK-LABEL: SUBMISSION TRACE BEGIN
// CHECK-V1: zeCommandQueueExecuteCommandLists
// CHECK-V1: zeCommandQueueExecuteCommandLists
// CHECK-V2: zeCommandListImmediateAppendCommandListsExp
// CHECK-V2: zeCommandListImmediateAppendCommandListsExp
// CHECK-LABEL: SUBMISSION TRACE END

// Verify that external semaphore wait and signal operations work on an
// in-order queue backed by regular (non-immediate) command lists.
// in-order queue backed by regular (non-immediate) command lists. The trace
// window ends before status queries so they cannot hide a wait left in the
// batch.

#include "d3d12_setup.hpp"
#include <chrono>
Expand All @@ -22,12 +32,10 @@
#include <cstring>
#include <iostream>
#include <string>
#include <sycl/atomic_ref.hpp>
#include <sycl/detail/core.hpp>
#include <sycl/ext/intel/info/device.hpp>
#include <sycl/ext/oneapi/bindless_images.hpp>
#include <sycl/properties/queue_properties.hpp>
#include <sycl/usm.hpp>
#include <thread>

#define WIN32_LEAN_AND_MEAN
Expand Down Expand Up @@ -56,22 +64,6 @@ D3D12Context createSyclD3D12Context(const sycl::device &device) {
std::_Exit(EXIT_FAILURE);
}

using MarkerAtomicRef =
sycl::atomic_ref<int, sycl::memory_order::relaxed,
sycl::memory_scope::system,
sycl::access::address_space::global_space>;

bool waitForMarker(int *marker) {
const auto deadline =
std::chrono::steady_clock::now() + std::chrono::seconds(5);
while (MarkerAtomicRef(*marker).load() == 0) {
if (std::chrono::steady_clock::now() >= deadline)
return false;
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
return true;
}

bool remainsIncomplete(const sycl::event &event) {
const auto deadline =
std::chrono::steady_clock::now() + std::chrono::milliseconds(100);
Expand Down Expand Up @@ -112,18 +104,18 @@ int main() {
syclexp::external_semaphore_handle_type::win32_nt_dx12_fence};
syclexp::external_semaphore syclSem =
syclexp::import_external_semaphore(semDesc, device, context);
int *marker = sycl::malloc_shared<int>(1, q);
MarkerAtomicRef(*marker).store(0);

try {
const uint64_t D3DSignalValue = extFence.fenceValue + 1;
q.single_task([=]() { MarkerAtomicRef(*marker).store(1); });
std::cerr << "SUBMISSION TRACE BEGIN" << std::endl;
sycl::event precedingEvent = q.single_task([]() {});
sycl::event waitEvent =
q.ext_oneapi_wait_external_semaphore(syclSem, D3DSignalValue);
std::cerr << "SUBMISSION TRACE END" << std::endl;

if (!waitForMarker(marker))
if (!waitForCompletion(precedingEvent))
failWithoutCleanup(
"The external semaphore wait did not submit the preceding batch.");
"Work preceding the external semaphore wait did not complete.");
if (!remainsIncomplete(waitEvent))
failWithoutCleanup(
"The external semaphore wait completed before D3D12 signaled it.");
Expand Down Expand Up @@ -155,7 +147,6 @@ int main() {
failWithoutCleanup(e.what());
}

sycl::free(marker, q);
syclexp::release_external_semaphore(syclSem, device, context);
cleanupExportableFence(extFence);
if (d3dCtx.fenceEvent)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
// REQUIRES: aspect-ext_oneapi_external_semaphore_import
// REQUIRES: aspect-usm_shared_allocations
// REQUIRES: vulkan && level_zero

// Regular command-list external semaphore support requires these driver
Expand All @@ -10,24 +9,31 @@
// XFAIL-TRACKER: https://github.com/intel/llvm/issues/23249

// RUN: %{build} %link-vulkan -o %t.out %if target-spir %{ -Wno-ignored-attributes %}
// RUN: env UR_L0_BATCH_SIZE=8 %{run} %t.out
// RUN: env UR_L0_BATCH_SIZE=8 SYCL_UR_TRACE=2 UR_L0_DEBUG=1 %{run} %t.out \
// RUN: 2>&1 | FileCheck --check-prefixes=CHECK%if level_zero_v2_adapter %{,CHECK-V2%} %else %{,CHECK-V1%} %s
//
// CHECK-LABEL: SUBMISSION TRACE BEGIN
// CHECK-V1: zeCommandQueueExecuteCommandLists
// CHECK-V1: zeCommandQueueExecuteCommandLists
// CHECK-V2: zeCommandListImmediateAppendCommandListsExp
// CHECK-V2: zeCommandListImmediateAppendCommandListsExp
// CHECK-LABEL: SUBMISSION TRACE END

// Verify that external semaphore wait and signal operations work on an
// in-order queue backed by regular (non-immediate) command lists. A timeline
// semaphore provides equivalent coverage on both platforms while avoiding
// Linux binary semaphore sharing issue CMPLRLLVM-78008.
// semaphore provides equivalent coverage on both platforms while avoiding a
// known Linux binary semaphore sharing issue. The trace window ends before
// status queries so they cannot hide a wait left in the batch.

#include "sycl_vulkan_setup.hpp"
#include <chrono>
#include <cstdint>
#include <cstdlib>
#include <iostream>
#include <string>
#include <sycl/atomic_ref.hpp>
#include <sycl/detail/core.hpp>
#include <sycl/ext/oneapi/bindless_images.hpp>
#include <sycl/properties/queue_properties.hpp>
#include <sycl/usm.hpp>
#include <thread>

namespace syclexp = sycl::ext::oneapi::experimental;
Expand All @@ -37,22 +43,6 @@ namespace syclexp = sycl::ext::oneapi::experimental;
std::_Exit(EXIT_FAILURE);
}

using MarkerAtomicRef =
sycl::atomic_ref<int, sycl::memory_order::relaxed,
sycl::memory_scope::system,
sycl::access::address_space::global_space>;

bool waitForMarker(int *marker) {
const auto deadline =
std::chrono::steady_clock::now() + std::chrono::seconds(5);
while (MarkerAtomicRef(*marker).load() == 0) {
if (std::chrono::steady_clock::now() >= deadline)
return false;
std::this_thread::sleep_for(std::chrono::milliseconds(1));
}
return true;
}

bool remainsIncomplete(const sycl::event &event) {
const auto deadline =
std::chrono::steady_clock::now() + std::chrono::milliseconds(100);
Expand Down Expand Up @@ -101,17 +91,17 @@ int main() {
#endif
syclexp::external_semaphore syclSem =
syclexp::import_external_semaphore(desc, device, context);
int *marker = sycl::malloc_shared<int>(1, q);
MarkerAtomicRef(*marker).store(0);

try {
q.single_task([=]() { MarkerAtomicRef(*marker).store(1); });
std::cerr << "SUBMISSION TRACE BEGIN" << std::endl;
sycl::event precedingEvent = q.single_task([]() {});
sycl::event waitEvent =
q.ext_oneapi_wait_external_semaphore(syclSem, VulkanSignalValue);
std::cerr << "SUBMISSION TRACE END" << std::endl;

if (!waitForMarker(marker))
if (!waitForCompletion(precedingEvent))
failWithoutCleanup(
"The external semaphore wait did not submit the preceding batch.");
"Work preceding the external semaphore wait did not complete.");
if (!remainsIncomplete(waitEvent))
failWithoutCleanup(
"The external semaphore wait completed before Vulkan signaled it.");
Expand Down Expand Up @@ -150,7 +140,6 @@ int main() {
failWithoutCleanup(e.what());
}

sycl::free(marker, q);
syclexp::release_external_semaphore(syclSem, device, context);
vkDestroySemaphore(vkCtx.device, vkSem, nullptr);
cleanupVulkanContext(vkCtx);
Expand Down
Loading