Skip to content

Commit e5718fa

Browse files
authored
[SYCL] New test for USM memory pooling. (intel#250)
Signed-off-by: rdeodhar <rajiv.deodhar@intel.com>
1 parent dbac627 commit e5718fa

File tree

1 file changed

+126
-0
lines changed

1 file changed

+126
-0
lines changed

SYCL/USM/usm_pooling.cpp

Lines changed: 126 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,126 @@
1+
// REQUIRES: level_zero
2+
// RUN: %clangxx -fsycl -fsycl-targets=%sycl_triple %s -o %t.out
3+
4+
// Allocate 2 items of 2MB. Free 2. Allocate 3 more of 2MB.
5+
6+
// With no pooling: 1,2,3,4,5 allocs lead to ZE call.
7+
// RUN: env ZE_DEBUG=1 %GPU_RUN_PLACEHOLDER SYCL_PI_LEVEL_ZERO_DISABLE_USM_ALLOCATOR=1 %t.out h 2> %t1.out; cat %t1.out %GPU_CHECK_PLACEHOLDER --check-prefix CHECK-NOPOOL
8+
// RUN: env ZE_DEBUG=1 %GPU_RUN_PLACEHOLDER SYCL_PI_LEVEL_ZERO_DISABLE_USM_ALLOCATOR=1 %t.out d 2> %t1.out; cat %t1.out %GPU_CHECK_PLACEHOLDER --check-prefix CHECK-NOPOOL
9+
// RUN: env ZE_DEBUG=1 %GPU_RUN_PLACEHOLDER SYCL_PI_LEVEL_ZERO_DISABLE_USM_ALLOCATOR=1 %t.out s 2> %t1.out; cat %t1.out %GPU_CHECK_PLACEHOLDER --check-prefix CHECK-NOPOOL
10+
11+
// With pooling enabled and MaxPooolable=1MB: 1,2,3,4,5 allocs lead to ZE call.
12+
// RUN: env ZE_DEBUG=1 %GPU_RUN_PLACEHOLDER SYCL_PI_LEVEL_ZERO_USM_ALLOCATOR=1 %t.out h 2> %t1.out; cat %t1.out %GPU_CHECK_PLACEHOLDER --check-prefix CHECK-12345
13+
// RUN: env ZE_DEBUG=1 %GPU_RUN_PLACEHOLDER SYCL_PI_LEVEL_ZERO_USM_ALLOCATOR=1 %t.out d 2> %t1.out; cat %t1.out %GPU_CHECK_PLACEHOLDER --check-prefix CHECK-12345
14+
// RUN: env ZE_DEBUG=1 %GPU_RUN_PLACEHOLDER SYCL_PI_LEVEL_ZERO_USM_ALLOCATOR=1 %t.out s 2> %t1.out; cat %t1.out %GPU_CHECK_PLACEHOLDER --check-prefix CHECK-12345
15+
16+
// With pooling enabled and capacity=1: 1,2,4,5 allocs lead to ZE call.
17+
// RUN: env ZE_DEBUG=1 %GPU_RUN_PLACEHOLDER SYCL_PI_LEVEL_ZERO_USM_ALLOCATOR=2,1 %t.out h 2> %t1.out; cat %t1.out %GPU_CHECK_PLACEHOLDER --check-prefix CHECK-1245
18+
// RUN: env ZE_DEBUG=1 %GPU_RUN_PLACEHOLDER SYCL_PI_LEVEL_ZERO_USM_ALLOCATOR=2,1 %t.out d 2> %t1.out; cat %t1.out %GPU_CHECK_PLACEHOLDER --check-prefix CHECK-1245
19+
// RUN: env ZE_DEBUG=1 %GPU_RUN_PLACEHOLDER SYCL_PI_LEVEL_ZERO_USM_ALLOCATOR=2,1 %t.out s 2> %t1.out; cat %t1.out %GPU_CHECK_PLACEHOLDER --check-prefix CHECK-1245
20+
21+
// With pooling enabled and MaxPoolSize=2MB: 1,2,4,5 allocs lead to ZE call.
22+
// RUN: env ZE_DEBUG=1 %GPU_RUN_PLACEHOLDER SYCL_PI_LEVEL_ZERO_USM_ALLOCATOR=2,,2 %t.out h 2> %t1.out; cat %t1.out %GPU_CHECK_PLACEHOLDER --check-prefix CHECK-1245
23+
// RUN: env ZE_DEBUG=1 %GPU_RUN_PLACEHOLDER SYCL_PI_LEVEL_ZERO_USM_ALLOCATOR=2,,2 %t.out d 2> %t1.out; cat %t1.out %GPU_CHECK_PLACEHOLDER --check-prefix CHECK-1245
24+
// RUN: env ZE_DEBUG=1 %GPU_RUN_PLACEHOLDER SYCL_PI_LEVEL_ZERO_USM_ALLOCATOR=2,,2 %t.out s 2> %t1.out; cat %t1.out %GPU_CHECK_PLACEHOLDER --check-prefix CHECK-1245
25+
26+
#include "CL/sycl.hpp"
27+
using namespace sycl;
28+
29+
constexpr size_t SIZE = 2 * 1024 * 1024;
30+
31+
void test_host(context C) {
32+
33+
void *ph1 = malloc_host(SIZE, C);
34+
void *ph2 = malloc_host(SIZE, C);
35+
free(ph1, C);
36+
free(ph2, C);
37+
void *ph3 = malloc_host(SIZE, C);
38+
void *ph4 = malloc_host(SIZE, C);
39+
void *ph5 = malloc_host(SIZE, C);
40+
free(ph3, C);
41+
free(ph4, C);
42+
free(ph5, C);
43+
}
44+
45+
void test_device(context C, device D) {
46+
47+
void *ph1 = malloc_device(SIZE, D, C);
48+
void *ph2 = malloc_device(SIZE, D, C);
49+
free(ph1, C);
50+
free(ph2, C);
51+
void *ph3 = malloc_device(SIZE, D, C);
52+
void *ph4 = malloc_device(SIZE, D, C);
53+
void *ph5 = malloc_device(SIZE, D, C);
54+
free(ph3, C);
55+
free(ph4, C);
56+
free(ph5, C);
57+
}
58+
59+
void test_shared(context C, device D) {
60+
61+
void *ph1 = malloc_shared(SIZE, D, C);
62+
void *ph2 = malloc_shared(SIZE, D, C);
63+
free(ph1, C);
64+
free(ph2, C);
65+
void *ph3 = malloc_shared(SIZE, D, C);
66+
void *ph4 = malloc_shared(SIZE, D, C);
67+
void *ph5 = malloc_shared(SIZE, D, C);
68+
free(ph3, C);
69+
free(ph4, C);
70+
free(ph5, C);
71+
}
72+
73+
int main(int argc, char *argv[]) {
74+
queue Q;
75+
device D = Q.get_device();
76+
context C = Q.get_context();
77+
78+
const char *devType = D.is_host() ? "Host" : D.is_cpu() ? "CPU" : "GPU";
79+
std::string pluginName =
80+
D.get_platform().get_info<sycl::info::platform::name>();
81+
std::cout << "Running on device " << devType << " ("
82+
<< D.get_info<cl::sycl::info::device::name>() << ") " << pluginName
83+
<< " plugin\n";
84+
85+
if (*argv[1] == 'h') {
86+
std::cerr << "Test zeMemAllocHost\n";
87+
test_host(C);
88+
} else if (*argv[1] == 'd') {
89+
std::cerr << "Test zeMemAllocDevice\n";
90+
test_device(C, D);
91+
} else if (*argv[1] == 's') {
92+
std::cerr << "Test zeMemAllocShared\n";
93+
test_shared(C, D);
94+
}
95+
96+
return 0;
97+
}
98+
99+
// CHECK-NOPOOL: Test [[API:zeMemAllocHost|zeMemAllocDevice|zeMemAllocShared]]
100+
// CHECK-NOPOOL-NEXT: ZE ---> [[API]](
101+
// CHECK-NOPOOL-NEXT: ZE ---> [[API]](
102+
// CHECK-NOPOOL-NEXT: ZE ---> zeMemFree
103+
// CHECK-NOPOOL-NEXT: ZE ---> zeMemFree
104+
// CHECK-NOPOOL-NEXT: ZE ---> [[API]](
105+
// CHECK-NOPOOL-NEXT: ZE ---> [[API]](
106+
// CHECK-NOPOOL-NEXT: ZE ---> [[API]](
107+
108+
// CHECK-12345: Test [[API:zeMemAllocHost|zeMemAllocDevice|zeMemAllocShared]]
109+
// CHECK-12345-NEXT: ZE ---> [[API]](
110+
// CHECK-12345-NEXT: ZE ---> [[API]](
111+
// CHECK-12345-NEXT: ZE ---> zeMemGetAllocProperties
112+
// CHECK-12345-NEXT: ZE ---> zeMemFree
113+
// CHECK-12345-NEXT: ZE ---> zeMemGetAllocProperties
114+
// CHECK-12345-NEXT: ZE ---> zeMemFree
115+
// CHECK-12345-NEXT: ZE ---> [[API]](
116+
// CHECK-12345-NEXT: ZE ---> [[API]](
117+
// CHECK-12345-NEXT: ZE ---> [[API]](
118+
119+
// CHECK-1245: Test [[API:zeMemAllocHost|zeMemAllocDevice|zeMemAllocShared]]
120+
// CHECK-1245-NEXT: ZE ---> [[API]](
121+
// CHECK-1245-NEXT: ZE ---> [[API]](
122+
// CHECK-1245-NEXT: ZE ---> zeMemGetAllocProperties
123+
// CHECK-1245-NEXT: ZE ---> zeMemGetAllocProperties
124+
// CHECK-1245-NEXT: ZE ---> zeMemFree
125+
// CHECK-1245-NEXT: ZE ---> [[API]](
126+
// CHECK-1245-NEXT: ZE ---> [[API]](

0 commit comments

Comments
 (0)