Skip to content

Commit 1159889

Browse files
Enable zello_world_gpu test on linux
- if copy_buffer_to_buffer.spv file exists, it is used instead appendMemoryCopy builtin Change-Id: Iff78fdc9838474d2f18914c9774d7b0e3929b882 Signed-off-by: Mateusz Hoppe <mateusz.hoppe@intel.com>
1 parent 7166dfd commit 1159889

File tree

2 files changed

+74
-5
lines changed

2 files changed

+74
-5
lines changed

level_zero/core/test/black_box_tests/CMakeLists.txt

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
# SPDX-License-Identifier: MIT
55
#
66

7-
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug" AND WIN32)
7+
if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug")
88
set(L0_BLACK_BOX_TEST_PROJECT_FOLDER "ze_intel_gpu/black_box_tests")
9-
set(TEST_NAME zello_world)
9+
set(TEST_NAME zello_world_gpu)
1010

1111
add_executable(${TEST_NAME} zello_world.cpp)
1212

@@ -16,8 +16,16 @@ if("${CMAKE_BUILD_TYPE}" STREQUAL "Debug" AND WIN32)
1616
VS_DEBUGGER_COMMAND_ARGUMENTS ""
1717
VS_DEBUGGER_WORKING_DIRECTORY "$(OutputPath)"
1818
)
19-
19+
if(MSVC)
2020
add_dependencies(${TEST_NAME} ${TARGET_NAME_L0})
2121
target_link_libraries(${TEST_NAME} PUBLIC ${TARGET_NAME_L0})
22+
else()
23+
if(BUILD_LEVEL_ZERO_LOADER)
24+
add_dependencies(${TEST_NAME} ze_loader)
25+
target_link_libraries(${TEST_NAME} ${NEO_BINARY_DIR}/lib/libze_loader.so)
26+
else()
27+
set_target_properties(${TEST_NAME} PROPERTIES EXCLUDE_FROM_ALL TRUE)
28+
endif()
29+
endif()
2230
set_target_properties(${TEST_NAME} PROPERTIES FOLDER ${L0_BLACK_BOX_TEST_PROJECT_FOLDER})
2331
endif()

level_zero/core/test/black_box_tests/zello_world.cpp

Lines changed: 63 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,8 +8,10 @@
88
#include <level_zero/ze_api.h>
99

1010
#include <cstring>
11+
#include <fstream>
1112
#include <iostream>
1213
#include <limits>
14+
#include <memory>
1315
#include <vector>
1416

1517
#define VALIDATECALL(myZeCall) \
@@ -104,8 +106,67 @@ int main(int argc, char *argv[]) {
104106
memset(srcBuffer, val, allocSize);
105107
memset(dstBuffer, 0, allocSize);
106108

107-
// Perform a GPU copy
108-
VALIDATECALL(zeCommandListAppendMemoryCopy(cmdList, dstBuffer, srcBuffer, allocSize, nullptr, 0, nullptr));
109+
ze_module_handle_t module = nullptr;
110+
ze_kernel_handle_t kernel = nullptr;
111+
112+
std::ifstream file("copy_buffer_to_buffer.spv", std::ios::binary);
113+
114+
if (file.is_open()) {
115+
file.seekg(0, file.end);
116+
auto length = file.tellg();
117+
file.seekg(0, file.beg);
118+
119+
std::unique_ptr<char[]> spirvInput(new char[length]);
120+
file.read(spirvInput.get(), length);
121+
122+
ze_module_desc_t moduleDesc = {};
123+
ze_module_build_log_handle_t buildlog;
124+
moduleDesc.format = ZE_MODULE_FORMAT_IL_SPIRV;
125+
moduleDesc.pInputModule = reinterpret_cast<const uint8_t *>(spirvInput.get());
126+
moduleDesc.inputSize = length;
127+
moduleDesc.pBuildFlags = "";
128+
129+
if (zeModuleCreate(context, device, &moduleDesc, &module, &buildlog) != ZE_RESULT_SUCCESS) {
130+
size_t szLog = 0;
131+
zeModuleBuildLogGetString(buildlog, &szLog, nullptr);
132+
133+
char *strLog = (char *)malloc(szLog);
134+
zeModuleBuildLogGetString(buildlog, &szLog, strLog);
135+
std::cout << "Build log:" << strLog << std::endl;
136+
137+
free(strLog);
138+
}
139+
VALIDATECALL(zeModuleBuildLogDestroy(buildlog));
140+
141+
ze_kernel_desc_t kernelDesc = {};
142+
kernelDesc.pKernelName = "CopyBufferToBufferBytes";
143+
VALIDATECALL(zeKernelCreate(module, &kernelDesc, &kernel));
144+
145+
uint32_t groupSizeX = 32u;
146+
uint32_t groupSizeY = 1u;
147+
uint32_t groupSizeZ = 1u;
148+
VALIDATECALL(zeKernelSuggestGroupSize(kernel, allocSize, 1U, 1U, &groupSizeX, &groupSizeY, &groupSizeZ));
149+
VALIDATECALL(zeKernelSetGroupSize(kernel, groupSizeX, groupSizeY, groupSizeZ));
150+
151+
uint32_t offset = 0;
152+
VALIDATECALL(zeKernelSetArgumentValue(kernel, 1, sizeof(dstBuffer), &dstBuffer));
153+
VALIDATECALL(zeKernelSetArgumentValue(kernel, 0, sizeof(srcBuffer), &srcBuffer));
154+
VALIDATECALL(zeKernelSetArgumentValue(kernel, 2, sizeof(uint32_t), &offset));
155+
VALIDATECALL(zeKernelSetArgumentValue(kernel, 3, sizeof(uint32_t), &offset));
156+
VALIDATECALL(zeKernelSetArgumentValue(kernel, 4, sizeof(uint32_t), &offset));
157+
158+
ze_group_count_t dispatchTraits;
159+
dispatchTraits.groupCountX = allocSize / groupSizeX;
160+
dispatchTraits.groupCountY = 1u;
161+
dispatchTraits.groupCountZ = 1u;
162+
163+
VALIDATECALL(zeCommandListAppendLaunchKernel(cmdList, kernel, &dispatchTraits,
164+
nullptr, 0, nullptr));
165+
file.close();
166+
} else {
167+
// Perform a GPU copy
168+
VALIDATECALL(zeCommandListAppendMemoryCopy(cmdList, dstBuffer, srcBuffer, allocSize, nullptr, 0, nullptr));
169+
}
109170

110171
// Close list and submit for execution
111172
VALIDATECALL(zeCommandListClose(cmdList));

0 commit comments

Comments
 (0)