Skip to content
This repository was archived by the owner on Mar 28, 2023. It is now read-only.
Merged
Changes from 6 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
40 changes: 40 additions & 0 deletions SYCL/USM/free_during_kernel_execution.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
//==------------------- free_during_kernel_execution.cpp -------------------==//
//
// 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
//
//===----------------------------------------------------------------------===//
//
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t1.out
// RUN: %HOST_RUN_PLACEHOLDER %t1.out
// RUN: %CPU_RUN_PLACEHOLDER %t1.out
// RUN: %GPU_RUN_PLACEHOLDER %t1.out
// RUN: %ACC_RUN_PLACEHOLDER %t1.out

#include <CL/sycl.hpp>

class KernelA;

int main() {
const int N = 512;
sycl::queue Queue;
sycl::buffer<int, 1> Buffer(N);
sycl::range<1> NumOfWorkItems{Buffer.size()};

auto *USM = sycl::malloc_host<int>(1, Queue.get_context());

Queue.submit([&](sycl::handler &cgh) {
auto Accessor = Buffer.get_access<sycl::access::mode::write>(cgh);
cgh.single_task<KernelA>([=]() {
for (int I = 0; I < N; ++I) {
Accessor[I] = I;
}
});
});

// Check that freeing USM before the kernel was finished works.
free(USM, Queue.get_context());

return 0;
}