-
Notifications
You must be signed in to change notification settings - Fork 745
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[SYCL][USM] Improve USM Allocator. (#2026)
Add ability to use std::allocate_shared. Add equality operators for allocators. Add tests. Disallow device allocations in usm_allocator as there are too many incompatibilities with how C++ allocators are used. Signed-off-by: James Brodman <[email protected]>
- Loading branch information
Showing
6 changed files
with
144 additions
and
278 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,55 @@ | ||
// piextUSM*Alloc functions for CUDA are not behaving as described in | ||
// https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/USM/USM.adoc | ||
// https://github.com/intel/llvm/blob/sycl/sycl/doc/extensions/USM/cl_intel_unified_shared_memory.asciidoc | ||
// | ||
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t1.out | ||
// RUN: env SYCL_DEVICE_TYPE=HOST %t1.out | ||
// RUN: %CPU_RUN_PLACEHOLDER %t1.out | ||
// RUN: %GPU_RUN_PLACEHOLDER %t1.out | ||
|
||
//==---------- allocator_equal.cpp - Allocator Equality 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; | ||
|
||
int main() { | ||
queue q; | ||
auto dev = q.get_device(); | ||
auto ctxt = q.get_context(); | ||
|
||
queue q2; | ||
auto dev2 = q2.get_device(); | ||
auto ctxt2 = q2.get_context(); | ||
|
||
// Test allocator equality | ||
if (dev.get_info<info::device::usm_host_allocations>()) { | ||
usm_allocator<int, usm::alloc::host> alloc1(ctxt, dev); | ||
usm_allocator<int, usm::alloc::host> alloc2(q); | ||
|
||
assert((alloc1 == alloc2) && "Allocators should be equal."); | ||
|
||
usm_allocator<int, usm::alloc::host, 8> alloc3(ctxt, dev); | ||
usm_allocator<int, usm::alloc::host, 16> alloc4(q); | ||
|
||
assert((alloc1 == alloc2) && "Allocators should be equal."); | ||
} | ||
|
||
if (dev.get_info<info::device::usm_shared_allocations>() && | ||
dev.get_info<info::device::usm_host_allocations>()) { | ||
usm_allocator<int, usm::alloc::shared> alloc1(ctxt, dev); | ||
usm_allocator<int, usm::alloc::host> alloc2(ctxt, dev); | ||
|
||
assert((alloc1 != alloc2) && "Allocators should NOT be equal."); | ||
} | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t1.out | ||
// RUN: env SYCL_DEVICE_TYPE=HOST %t1.out | ||
// RUN: %CPU_RUN_PLACEHOLDER %t1.out | ||
// RUN: %GPU_RUN_PLACEHOLDER %t1.out | ||
|
||
//==-------- allocator_shared.cpp - Allocate Shared 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> | ||
#include <memory> | ||
|
||
using namespace cl::sycl; | ||
|
||
int main() { | ||
queue q; | ||
auto dev = q.get_device(); | ||
auto ctxt = q.get_context(); | ||
|
||
// Test ability to create a shared pointer. | ||
if (dev.get_info<info::device::usm_host_allocations>()) { | ||
usm_allocator<int, usm::alloc::host> alloc(ctxt, dev); | ||
auto ptr1 = std::allocate_shared<int>(alloc); | ||
|
||
// Test construction | ||
auto ptr2 = std::allocate_shared<int>(alloc, 42); | ||
assert((*ptr2 == 42) && "Host construct passed."); | ||
} | ||
|
||
if (dev.get_info<info::device::usm_shared_allocations>()) { | ||
usm_allocator<int, usm::alloc::shared> alloc(ctxt, dev); | ||
auto ptr1 = std::allocate_shared<int>(alloc); | ||
|
||
// Test construction | ||
auto ptr2 = std::allocate_shared<int>(alloc, 42); | ||
assert((*ptr2 == 42) && "Shared construct passed."); | ||
} | ||
|
||
// Device allocations are not supported due to how allocated_shared is | ||
// written. | ||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.