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

Commit e120f69

Browse files
authored
[XPTI][SYCL] Update tests (#678)
1 parent 6662672 commit e120f69

File tree

5 files changed

+160
-62
lines changed

5 files changed

+160
-62
lines changed
Lines changed: 64 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
#include "xpti/xpti_trace_framework.hpp"
2+
3+
#include <iostream>
4+
#include <mutex>
5+
#include <string_view>
6+
7+
std::mutex GMutex;
8+
9+
XPTI_CALLBACK_API void memCallback(uint16_t, xpti::trace_event_data_t *,
10+
xpti::trace_event_data_t *, uint64_t,
11+
const void *);
12+
13+
XPTI_CALLBACK_API void xptiTraceInit(unsigned int MajorVersion,
14+
unsigned int MinorVersion,
15+
const char *VersionStr,
16+
const char *StreamName) {
17+
std::cout << "xptiTraceInit: Stream Name = " << StreamName << "\n";
18+
std::string_view NameView{StreamName};
19+
20+
if (NameView == "sycl.experimental.mem_alloc") {
21+
uint8_t StreamID = xptiRegisterStream(StreamName);
22+
xptiRegisterCallback(
23+
StreamID,
24+
static_cast<uint16_t>(xpti::trace_point_type_t::mem_alloc_begin),
25+
memCallback);
26+
xptiRegisterCallback(
27+
StreamID,
28+
static_cast<uint16_t>(xpti::trace_point_type_t::mem_alloc_end),
29+
memCallback);
30+
xptiRegisterCallback(
31+
StreamID,
32+
static_cast<uint16_t>(xpti::trace_point_type_t::mem_release_begin),
33+
memCallback);
34+
xptiRegisterCallback(
35+
StreamID,
36+
static_cast<uint16_t>(xpti::trace_point_type_t::mem_release_end),
37+
memCallback);
38+
}
39+
}
40+
41+
XPTI_CALLBACK_API void xptiTraceFinish(const char *streamName) {
42+
std::cout << "xptiTraceFinish: Stream Name = " << streamName << "\n";
43+
}
44+
45+
XPTI_CALLBACK_API void memCallback(uint16_t TraceType,
46+
xpti::trace_event_data_t *,
47+
xpti::trace_event_data_t *, uint64_t,
48+
const void *UserData) {
49+
std::lock_guard Lock{GMutex};
50+
auto Type = static_cast<xpti::trace_point_type_t>(TraceType);
51+
auto *Data = static_cast<const xpti::mem_alloc_data_t *>(UserData);
52+
if (Type == xpti::trace_point_type_t::mem_alloc_begin) {
53+
std::cout << "Mem Alloc Begin : ";
54+
} else if (Type == xpti::trace_point_type_t::mem_alloc_end) {
55+
std::cout << "Mem Alloc End : ";
56+
} else if (Type == xpti::trace_point_type_t::mem_release_begin) {
57+
std::cout << "Mem Release Begin : ";
58+
} else if (Type == xpti::trace_point_type_t::mem_release_end) {
59+
std::cout << "Mem Release End : ";
60+
}
61+
std::cout << " mem_obj_handle: " << Data->mem_object_handle << "\n";
62+
std::cout << " alloc_pointer : " << Data->alloc_pointer << "\n";
63+
std::cout << " alloc_size : " << Data->alloc_size << "\n";
64+
}

SYCL/XPTI/basic_event_collection.inc

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
#ifdef XPTI_COLLECTOR
2+
3+
#include "Inputs/test_collector.cpp"
4+
5+
#else
6+
7+
#include <sycl/sycl.hpp>
8+
9+
int main() {
10+
sycl::queue Q{sycl::default_selector{}};
11+
12+
auto Ptr = sycl::malloc_device<int>(1, Q);
13+
14+
auto Evt1 = Q.single_task([=]() { Ptr[0] = 1; });
15+
16+
auto Evt2 = Q.submit([&](sycl::handler &CGH) {
17+
CGH.depends_on(Evt1);
18+
CGH.single_task([=]() { Ptr[0]++; });
19+
});
20+
21+
Evt2.wait();
22+
23+
int Res = 0;
24+
Q.memcpy(&Res, Ptr, 1);
25+
Q.wait();
26+
27+
assert(Res == 2);
28+
29+
return 0;
30+
}
31+
32+
#endif
Lines changed: 7 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,19 @@
1-
// REQUIRES: xptifw, opencl
2-
// RUN: %clangxx %s -DXPTI_COLLECTOR -DXPTI_CALLBACK_API_EXPORTS %xptifw_lib %shared_lib %fPIC %cxx_std_optionc++17 -o %t_collector.dll
1+
// REQUIRES: xptifw, opencl, cpu, linux
2+
// RUN: %clangxx %s -DXPTI_COLLECTOR -DXPTI_CALLBACK_API_EXPORTS %xptifw_lib -shared -fPIC -std=c++17 -o %t_collector.so
33
// RUN: %clangxx -fsycl -fsycl-unnamed-lambda -fsycl-targets=%sycl_triple %s -o %t.out
4-
// RUN: env XPTI_TRACE_ENABLE=1 env XPTI_FRAMEWORK_DISPATCHER=%xptifw_dispatcher env XPTI_SUBSCRIBERS=%t_collector.dll env SYCL_DEVICE_FILTER=opencl %t.out | FileCheck %s 2>&1
5-
6-
// REQUIRES: TEMPORARY_DISABLED
7-
#ifdef XPTI_COLLECTOR
8-
9-
#include "Inputs/test_collector.cpp"
10-
11-
#else
12-
13-
#include <sycl/sycl.hpp>
14-
15-
int main() {
16-
sycl::queue Q{sycl::default_selector{}};
17-
18-
auto Ptr = sycl::malloc_device<int>(1, Q);
19-
20-
auto Evt1 = Q.single_task([=]() { Ptr[0] = 1; });
21-
22-
auto Evt2 = Q.submit([&](sycl::handler &CGH) {
23-
CGH.depends_on(Evt1);
24-
CGH.single_task([=]() { Ptr[0]++; });
25-
});
26-
27-
Evt2.wait();
28-
29-
int Res = 0;
30-
Q.memcpy(&Res, Ptr, 1);
31-
Q.wait();
32-
33-
assert(Res == 2);
34-
35-
return 0;
36-
}
37-
38-
#endif
4+
// RUN: env XPTI_TRACE_ENABLE=1 env XPTI_FRAMEWORK_DISPATCHER=%xptifw_dispatcher env XPTI_SUBSCRIBERS=%t_collector.so %CPU_RUN_PLACEHOLDER %t.out %CPU_CHECK_PLACEHOLDER
395

6+
#include "basic_event_collection.inc"
7+
//
408
// CHECK: xptiTraceInit: Stream Name = sycl.experimental.mem_alloc
419
// CHECK: xptiTraceInit: Stream Name = sycl
4210
// CHECK-NEXT: Graph create
4311
// CHECK-NEXT: xptiTraceInit: Stream Name = sycl.pi
4412
// CHECK-NEXT: xptiTraceInit: Stream Name = sycl.pi.debug
45-
// CHECK-NEXT: PI Call Begin : piPlatformsGet
46-
// CHECK-NEXT: PI Call Begin : piPlatformsGet
47-
// CHECK-NEXT: PI Call Begin : piDevicesGet
48-
// CHECK-NEXT: PI Call Begin : piDevicesGet
49-
// CHECK-NEXT: PI Call Begin : piDeviceGetInfo
50-
// CHECK-NEXT: PI Call Begin : piDeviceGetInfo
51-
// CHECK-NEXT: PI Call Begin : piDeviceGetInfo
52-
// CHECK-NEXT: PI Call Begin : piDeviceRetain
53-
// CHECK-NEXT: PI Call Begin : piDeviceGetInfo
54-
// CHECK-NEXT: PI Call Begin : piDeviceGetInfo
55-
// CHECK-NEXT: PI Call Begin : piPlatformGetInfo
56-
// CHECK-NEXT: PI Call Begin : piPlatformGetInfo
57-
// CHECK-NEXT: PI Call Begin : piDeviceRelease
13+
// CHECK: PI Call Begin : piPlatformsGet
5814
// CHECK: PI Call Begin : piContextCreate
5915
// CHECK-NEXT: PI Call Begin : piQueueCreate
60-
// CHECK-NEXT: PI Call Begin : piextUSMDeviceAlloc
61-
// CHECK-NEXT: PI Call Begin : piextDeviceSelectBinary
62-
// CHECK-NEXT: PI Call Begin : piDeviceGetInfo
16+
// CHECK: PI Call Begin : piextDeviceSelectBinary
6317
// CHECK: PI Call Begin : piKernelCreate
6418
// CHECK-NEXT: PI Call Begin : piKernelSetExecInfo
6519
// CHECK-NEXT: PI Call Begin : piextKernelSetArgPointer
@@ -112,12 +66,3 @@ int main() {
11266
// CHECK-NEXT: PI Call Begin : piQueueFinish
11367
// CHECK-NEXT: Wait end
11468
// CHECK-NEXT: sycl_device : {{.*}}
115-
// CHECK-NEXT: PI Call Begin : piEventRelease
116-
// CHECK-NEXT: PI Call Begin : piEventRelease
117-
// CHECK-NEXT: PI Call Begin : piQueueRelease
118-
// CHECK-NEXT: PI Call Begin : piContextRelease
119-
// CHECK-NEXT: PI Call Begin : piKernelRelease
120-
// CHECK-NEXT: PI Call Begin : piKernelRelease
121-
// CHECK-NEXT: PI Call Begin : piProgramRelease
122-
// CHECK-NEXT: PI Call Begin : piDeviceRelease
123-
// CHECK-NEXT: PI Call Begin : piTearDown

SYCL/XPTI/mem_alloc_events.inc

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
#ifdef XPTI_COLLECTOR
2+
3+
#include "Inputs/buffer_info_collector.cpp"
4+
5+
#else
6+
7+
#include <numeric>
8+
#include <sycl/sycl.hpp>
9+
#include <vector>
10+
11+
int main() {
12+
sycl::queue Q{sycl::default_selector{}};
13+
14+
sycl::buffer<int, 1> Buf{sycl::range{100}};
15+
std::vector<int> Vec;
16+
Vec.resize(100);
17+
std::iota(Vec.begin(), Vec.end(), 0);
18+
19+
Q.submit([&](sycl::handler &CGH) {
20+
sycl::accessor Acc{Buf, CGH, sycl::write_only};
21+
CGH.copy(Vec.data(), Acc);
22+
});
23+
24+
Q.submit([&](sycl::handler &CGH) {
25+
sycl::accessor Acc{Buf, CGH, sycl::write_only};
26+
CGH.single_task([=]() { Acc[0] = 42; });
27+
});
28+
29+
Q.wait();
30+
31+
sycl::host_accessor Acc{Buf};
32+
assert(Acc[0] == 42);
33+
34+
return 0;
35+
}
36+
37+
#endif

SYCL/XPTI/mem_alloc_events_linux.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// REQUIRES: xptifw, gpu, linux
2+
// RUN: %clangxx %s -DXPTI_COLLECTOR -DXPTI_CALLBACK_API_EXPORTS %xptifw_lib -shared -fPIC -std=c++17 -o %t_collector.so
3+
// RUN: %clangxx -fsycl -fsycl-unnamed-lambda -fsycl-targets=%sycl_triple %s -o %t.out
4+
// RUN: env XPTI_TRACE_ENABLE=1 env XPTI_FRAMEWORK_DISPATCHER=%xptifw_dispatcher env XPTI_SUBSCRIBERS=%t_collector.so %GPU_RUN_PLACEHOLDER %t.out %GPU_CHECK_PLACEHOLDER
5+
6+
#include "mem_alloc_events.inc"
7+
8+
// CHECK: xptiTraceInit: Stream Name = sycl.experimental.mem_alloc
9+
// CHECK: Mem Alloc Begin : mem_obj_handle: {{.*}}
10+
// CHECK-NEXT: alloc_pointer : 0
11+
// CHECK-NEXT: alloc_size : 400
12+
// CHECK: Mem Alloc End : mem_obj_handle: {{.*}}
13+
// CHECK-NEXT: alloc_pointer : {{.*}}
14+
// CHECK-NEXT: alloc_size : 400
15+
// CHECK: Mem Release Begin : mem_obj_handle: {{.*}}
16+
// CHECK-NEXT: alloc_pointer : {{.*}}
17+
// CHECK-NEXT: alloc_size : 0
18+
// CHECK: Mem Release End : mem_obj_handle: {{.*}}
19+
// CHECK-NEXT: alloc_pointer : {{.*}}
20+
// CHECK-NEXT: alloc_size : 0

0 commit comments

Comments
 (0)