Skip to content

[SYCL] Extend USM testing #3189

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
Feb 17, 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
128 changes: 0 additions & 128 deletions sycl/test/extensions/usm.cpp

This file was deleted.

82 changes: 82 additions & 0 deletions sycl/test/extensions/usm/usm_alloc_utility.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t1.out
// RUN: %RUN_ON_HOST %t1.out

//==------ usm_alloc_utility.cpp - USM malloc and aligned_alloc 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 <cassert>

using namespace cl::sycl;

constexpr int N = 8;

int main() {
queue q;
auto dev = q.get_device();
auto ctxt = q.get_context();
int *array;

if (dev.get_info<info::device::usm_host_allocations>()) {
array = (int *)malloc_host(N * sizeof(int), q);
assert((get_pointer_type(array, ctxt) == usm::alloc::host) &&
"Allocation pointer should be host type");
assert((get_pointer_device(array, ctxt) == dev) &&
"Allocation pointer should be host type");
free(array, ctxt);

array =
(int *)aligned_alloc_host(alignof(long long), N * sizeof(int), ctxt);
assert((get_pointer_type(array, ctxt) == usm::alloc::host) &&
"Allocation pointer should be host type");
assert((get_pointer_device(array, ctxt) == dev) &&
"Allocation pointer should be host type");
free(array, ctxt);
}

if (dev.get_info<info::device::usm_shared_allocations>()) {
array = (int *)malloc_shared(N * sizeof(int), q);
// host device treats all allocations as host allocations
assert((get_pointer_type(array, ctxt) == usm::alloc::host) &&
"Allocation pointer should be host type");
assert((get_pointer_device(array, ctxt) == dev) &&
"Allocation pointer should be host type");
free(array, ctxt);

array = (int *)aligned_alloc_shared(alignof(long long), N * sizeof(int),
dev, ctxt);
// host device treats all allocations as host allocations
assert((get_pointer_type(array, ctxt) == usm::alloc::host) &&
"Allocation pointer should be host type");
assert((get_pointer_device(array, ctxt) == dev) &&
"Allocation pointer should be host type");
free(array, ctxt);
}

if (dev.get_info<info::device::usm_device_allocations>()) {
array = (int *)malloc_device(N * sizeof(int), q);
// host device treats all allocations as host allocations
assert((get_pointer_type(array, ctxt) == usm::alloc::host) &&
"Allocation pointer should be host type");
assert((get_pointer_device(array, ctxt) == dev) &&
"Allocation pointer should be host type");
free(array, ctxt);

array = (int *)aligned_alloc_device(alignof(long long), N * sizeof(int),
dev, ctxt);
// host device treats all allocations as host allocations
assert((get_pointer_type(array, ctxt) == usm::alloc::host) &&
"Allocation pointer should be host type");
assert((get_pointer_device(array, ctxt) == dev) &&
"Allocation pointer should be host type");
free(array, ctxt);
}

return 0;
}
43 changes: 43 additions & 0 deletions sycl/test/extensions/usm/usm_allocator.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t1.out
// RUN: %RUN_ON_HOST %t1.out

//==--------- usm_allocator.cpp - USM allocator construction 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 <cassert>

using namespace cl::sycl;

constexpr int N = 8;

int main() {
queue q;
auto dev = q.get_device();
auto ctxt = q.get_context();

{
// Test usm_allocator
if (dev.get_info<info::device::usm_shared_allocations>() &&
dev.get_info<info::device::usm_host_allocations>()) {
usm_allocator<int, usm::alloc::shared> alloc11(ctxt, dev);
usm_allocator<int, usm::alloc::shared> alloc12(ctxt, dev);
usm_allocator<int, usm::alloc::host> alloc21(q);
usm_allocator<int, usm::alloc::host> alloc22(alloc21);

// usm::alloc::device is not supported by usm_allocator

assert((alloc11 != alloc22) && "Allocators should NOT be equal.");
assert((alloc11 == alloc12) && "Allocators should be equal.");
assert((alloc21 == alloc22) && "Allocators should be equal.");
}
}

return 0;
}