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

[SYCL][CUDA] Add tests for CUDA-specific pi_mem_advice values #602

Merged
merged 7 commits into from
Feb 9, 2022
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
10 changes: 6 additions & 4 deletions SYCL/DiscardEvents/discard_events_test_queue_ops.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,9 @@ void TestQueueOperations(sycl::queue Q) {
sycl::range<1> Range(BUFFER_SIZE);
auto Dev = Q.get_device();
auto Ctx = Q.get_context();
const int MemAdvice =
((Dev.get_backend() == sycl::backend::ext_oneapi_cuda) ? 1 : 0);
const int MemAdvice = ((Dev.get_backend() == sycl::backend::ext_oneapi_cuda)
? PI_MEM_ADVICE_CUDA_SET_READ_MOSTLY
: PI_MEM_ADVICE_UNKNOWN);
int *x = sycl::malloc_shared<int>(BUFFER_SIZE, Q);
assert(x != nullptr);
int *y = sycl::malloc_shared<int>(BUFFER_SIZE, Q);
Expand Down Expand Up @@ -70,8 +71,9 @@ void TestQueueOperationsViaSubmit(sycl::queue Q) {
sycl::range<1> Range(BUFFER_SIZE);
auto Dev = Q.get_device();
auto Ctx = Q.get_context();
const int MemAdvice =
((Dev.get_backend() == sycl::backend::ext_oneapi_cuda) ? 1 : 0);
const int MemAdvice = ((Dev.get_backend() == sycl::backend::ext_oneapi_cuda)
? PI_MEM_ADVICE_CUDA_SET_READ_MOSTLY
: PI_MEM_ADVICE_UNKNOWN);
int *x = sycl::malloc_shared<int>(BUFFER_SIZE, Q);
assert(x != nullptr);
int *y = sycl::malloc_shared<int>(BUFFER_SIZE, Q);
Expand Down
5 changes: 3 additions & 2 deletions SYCL/DiscardEvents/invalid_event.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,9 @@ void QueueAPIsReturnDiscardedEvent(sycl::queue Q) {
sycl::range<1> range(BUFFER_SIZE);

auto Dev = Q.get_device();
const int MemAdvice =
((Dev.get_backend() == sycl::backend::ext_oneapi_cuda) ? 1 : 0);
const int MemAdvice = ((Dev.get_backend() == sycl::backend::ext_oneapi_cuda)
? PI_MEM_ADVICE_CUDA_SET_READ_MOSTLY
: PI_MEM_ADVICE_UNKNOWN);
int *x = sycl::malloc_shared<int>(BUFFER_SIZE, Q);
assert(x != nullptr);
int *y = sycl::malloc_shared<int>(BUFFER_SIZE, Q);
Expand Down
3 changes: 1 addition & 2 deletions SYCL/InorderQueue/in_order_usm_implicit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,7 @@ int main() {
{
queue Queue{property::queue::in_order()};

// optimize for read only
const int mem_advice = 1;
const int mem_advice = PI_MEM_ADVICE_CUDA_SET_READ_MOSTLY;

const int dataSize = 32;
const size_t numBytes = static_cast<size_t>(dataSize) * sizeof(int);
Expand Down
5 changes: 3 additions & 2 deletions SYCL/USM/memadvise.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,9 @@ int main() {
queue q;
auto dev = q.get_device();
auto ctxt = q.get_context();
const int mem_advice =
((dev.get_backend() == backend::ext_oneapi_cuda) ? 1 : 0);
const int mem_advice = ((dev.get_backend() == backend::ext_oneapi_cuda)
? PI_MEM_ADVICE_CUDA_SET_READ_MOSTLY
: PI_MEM_ADVICE_UNKNOWN);
if (!dev.get_info<info::device::usm_shared_allocations>())
return 0;

Expand Down
57 changes: 57 additions & 0 deletions SYCL/USM/memadvise_cuda.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t1.out
// REQUIRES: cuda
// RUN: %HOST_RUN_PLACEHOLDER %t1.out
// RUN: %CPU_RUN_PLACEHOLDER %t1.out
// RUN: %GPU_RUN_PLACEHOLDER %t1.out
// RUN: %ACC_RUN_PLACEHOLDER %t1.out

//==---------------- memadvise_cuda.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
//
//===----------------------------------------------------------------------===//

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

using namespace cl::sycl;

int main() {
const size_t size = 100;
queue q;
auto dev = q.get_device();
auto ctx = q.get_context();
if (!dev.get_info<info::device::usm_shared_allocations>()) {
std::cout << "Shared USM is not supported. Skipping test." << std::endl;
return 0;
}

void *ptr = malloc_shared(size, dev, ctx);
if (ptr == nullptr) {
std::cout << "Allocation failed!" << std::endl;
return -1;
}

std::vector<int> valid_advices{
PI_MEM_ADVICE_CUDA_SET_READ_MOSTLY,
PI_MEM_ADVICE_CUDA_UNSET_READ_MOSTLY,
PI_MEM_ADVICE_CUDA_SET_PREFERRED_LOCATION,
PI_MEM_ADVICE_CUDA_UNSET_PREFERRED_LOCATION,
PI_MEM_ADVICE_CUDA_SET_ACCESSED_BY,
PI_MEM_ADVICE_CUDA_UNSET_ACCESSED_BY,
PI_MEM_ADVICE_CUDA_SET_PREFERRED_LOCATION_HOST,
PI_MEM_ADVICE_CUDA_UNSET_PREFERRED_LOCATION_HOST,
PI_MEM_ADVICE_CUDA_SET_ACCESSED_BY_HOST,
PI_MEM_ADVICE_CUDA_UNSET_ACCESSED_BY_HOST,
};
for (int advice : valid_advices) {
q.mem_advise(ptr, size, advice);
}

q.wait_and_throw();
std::cout << "Test passed." << std::endl;
return 0;
}