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

Commit 64c4586

Browse files
authored
[SYCL][CUDA] Add tests for CUDA-specific pi_mem_advice values (#602)
Add tests for CUDA-specific pi_mem_advice values are being added in intel/llvm#5090.
1 parent 53adf48 commit 64c4586

File tree

5 files changed

+70
-10
lines changed

5 files changed

+70
-10
lines changed

SYCL/DiscardEvents/discard_events_test_queue_ops.hpp

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,9 @@ void TestQueueOperations(sycl::queue Q) {
1717
sycl::range<1> Range(BUFFER_SIZE);
1818
auto Dev = Q.get_device();
1919
auto Ctx = Q.get_context();
20-
const int MemAdvice =
21-
((Dev.get_backend() == sycl::backend::ext_oneapi_cuda) ? 1 : 0);
20+
const int MemAdvice = ((Dev.get_backend() == sycl::backend::ext_oneapi_cuda)
21+
? PI_MEM_ADVICE_CUDA_SET_READ_MOSTLY
22+
: PI_MEM_ADVICE_UNKNOWN);
2223
int *x = sycl::malloc_shared<int>(BUFFER_SIZE, Q);
2324
assert(x != nullptr);
2425
int *y = sycl::malloc_shared<int>(BUFFER_SIZE, Q);
@@ -70,8 +71,9 @@ void TestQueueOperationsViaSubmit(sycl::queue Q) {
7071
sycl::range<1> Range(BUFFER_SIZE);
7172
auto Dev = Q.get_device();
7273
auto Ctx = Q.get_context();
73-
const int MemAdvice =
74-
((Dev.get_backend() == sycl::backend::ext_oneapi_cuda) ? 1 : 0);
74+
const int MemAdvice = ((Dev.get_backend() == sycl::backend::ext_oneapi_cuda)
75+
? PI_MEM_ADVICE_CUDA_SET_READ_MOSTLY
76+
: PI_MEM_ADVICE_UNKNOWN);
7577
int *x = sycl::malloc_shared<int>(BUFFER_SIZE, Q);
7678
assert(x != nullptr);
7779
int *y = sycl::malloc_shared<int>(BUFFER_SIZE, Q);

SYCL/DiscardEvents/invalid_event.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,9 @@ void QueueAPIsReturnDiscardedEvent(sycl::queue Q) {
2323
sycl::range<1> range(BUFFER_SIZE);
2424

2525
auto Dev = Q.get_device();
26-
const int MemAdvice =
27-
((Dev.get_backend() == sycl::backend::ext_oneapi_cuda) ? 1 : 0);
26+
const int MemAdvice = ((Dev.get_backend() == sycl::backend::ext_oneapi_cuda)
27+
? PI_MEM_ADVICE_CUDA_SET_READ_MOSTLY
28+
: PI_MEM_ADVICE_UNKNOWN);
2829
int *x = sycl::malloc_shared<int>(BUFFER_SIZE, Q);
2930
assert(x != nullptr);
3031
int *y = sycl::malloc_shared<int>(BUFFER_SIZE, Q);

SYCL/InorderQueue/in_order_usm_implicit.cpp

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,7 @@ int main() {
2626
{
2727
queue Queue{property::queue::in_order()};
2828

29-
// optimize for read only
30-
const int mem_advice = 1;
29+
const int mem_advice = PI_MEM_ADVICE_CUDA_SET_READ_MOSTLY;
3130

3231
const int dataSize = 32;
3332
const size_t numBytes = static_cast<size_t>(dataSize) * sizeof(int);

SYCL/USM/memadvise.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,9 @@ int main() {
3030
queue q;
3131
auto dev = q.get_device();
3232
auto ctxt = q.get_context();
33-
const int mem_advice =
34-
((dev.get_backend() == backend::ext_oneapi_cuda) ? 1 : 0);
33+
const int mem_advice = ((dev.get_backend() == backend::ext_oneapi_cuda)
34+
? PI_MEM_ADVICE_CUDA_SET_READ_MOSTLY
35+
: PI_MEM_ADVICE_UNKNOWN);
3536
if (!dev.get_info<info::device::usm_shared_allocations>())
3637
return 0;
3738

SYCL/USM/memadvise_cuda.cpp

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t1.out
2+
// REQUIRES: cuda
3+
// RUN: %HOST_RUN_PLACEHOLDER %t1.out
4+
// RUN: %CPU_RUN_PLACEHOLDER %t1.out
5+
// RUN: %GPU_RUN_PLACEHOLDER %t1.out
6+
// RUN: %ACC_RUN_PLACEHOLDER %t1.out
7+
8+
//==---------------- memadvise_cuda.cpp ------------------------------------==//
9+
//
10+
// Part of the LLVM Project, under the Apache License v2.0 with LLVM Exceptions.
11+
// See https://llvm.org/LICENSE.txt for license information.
12+
// SPDX-License-Identifier: Apache-2.0 WITH LLVM-exception
13+
//
14+
//===----------------------------------------------------------------------===//
15+
16+
#include <CL/sycl.hpp>
17+
#include <iostream>
18+
#include <vector>
19+
20+
using namespace cl::sycl;
21+
22+
int main() {
23+
const size_t size = 100;
24+
queue q;
25+
auto dev = q.get_device();
26+
auto ctx = q.get_context();
27+
if (!dev.get_info<info::device::usm_shared_allocations>()) {
28+
std::cout << "Shared USM is not supported. Skipping test." << std::endl;
29+
return 0;
30+
}
31+
32+
void *ptr = malloc_shared(size, dev, ctx);
33+
if (ptr == nullptr) {
34+
std::cout << "Allocation failed!" << std::endl;
35+
return -1;
36+
}
37+
38+
std::vector<int> valid_advices{
39+
PI_MEM_ADVICE_CUDA_SET_READ_MOSTLY,
40+
PI_MEM_ADVICE_CUDA_UNSET_READ_MOSTLY,
41+
PI_MEM_ADVICE_CUDA_SET_PREFERRED_LOCATION,
42+
PI_MEM_ADVICE_CUDA_UNSET_PREFERRED_LOCATION,
43+
PI_MEM_ADVICE_CUDA_SET_ACCESSED_BY,
44+
PI_MEM_ADVICE_CUDA_UNSET_ACCESSED_BY,
45+
PI_MEM_ADVICE_CUDA_SET_PREFERRED_LOCATION_HOST,
46+
PI_MEM_ADVICE_CUDA_UNSET_PREFERRED_LOCATION_HOST,
47+
PI_MEM_ADVICE_CUDA_SET_ACCESSED_BY_HOST,
48+
PI_MEM_ADVICE_CUDA_UNSET_ACCESSED_BY_HOST,
49+
};
50+
for (int advice : valid_advices) {
51+
q.mem_advise(ptr, size, advice);
52+
}
53+
54+
q.wait_and_throw();
55+
std::cout << "Test passed." << std::endl;
56+
return 0;
57+
}

0 commit comments

Comments
 (0)