Skip to content

Commit 3cff3d8

Browse files
authored
[Offload] Add skeleton for offload conformance tests (#146391)
Summary: This adds a basic outline for adding 'conformance' tests. These are tests that are intended to check device code against a standard. In this case, we will expect this to be filled with math conformance tests to make sure their results are within the ULP requirements we demand. Right now this just *assumes* the GPU libc is there, meaning you'll likely need to do a manual `ninja` before doing `ninja -C runtimes/runtimes-bins offload.conformance`.
1 parent 6b1c92c commit 3cff3d8

File tree

5 files changed

+49
-0
lines changed

5 files changed

+49
-0
lines changed

offload/unittests/CMakeLists.txt

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,9 +81,34 @@ function(add_offload_unittest test_dirname)
8181
target_include_directories(${target_name} PRIVATE ${PLUGINS_TEST_INCLUDE})
8282
endfunction()
8383

84+
function(add_conformance_test test_name)
85+
set(target_name "${test_name}.conformance")
86+
87+
list(TRANSFORM ARGN PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/" OUTPUT_VARIABLE files)
88+
89+
if(NOT TARGET libc)
90+
message(WARNING "Cannot run conformance tests without the LLVM C library")
91+
return()
92+
endif()
93+
94+
add_executable(${target_name} ${files})
95+
add_dependencies(${target_name} ${PLUGINS_TEST_COMMON} ${test_name}.bin)
96+
target_compile_definitions(${target_name} PRIVATE DEVICE_CODE_PATH="${CONFORMANCE_TEST_DEVICE_CODE_PATH}")
97+
target_link_libraries(${target_name} PRIVATE ${PLUGINS_TEST_COMMON} libc)
98+
target_include_directories(${target_name} PRIVATE ${PLUGINS_TEST_INCLUDE})
99+
set_target_properties(${target_name} PROPERTIES EXCLUDE_FROM_ALL TRUE)
100+
101+
add_custom_target(offload.conformance.${test_name}
102+
COMMAND $<TARGET_FILE:${target_name}>
103+
DEPENDS ${target_name}
104+
COMMENT "Running conformance test ${test_name}")
105+
add_dependencies(offload.conformance offload.conformance.${test_name})
106+
endfunction()
107+
84108
set(OFFLOAD_TESTS_FORCE_NVPTX_ARCH "" CACHE STRING
85109
"Force building of NVPTX device code for Offload unit tests with the given arch, e.g. sm_61")
86110
set(OFFLOAD_TESTS_FORCE_AMDGPU_ARCH "" CACHE STRING
87111
"Force building of AMDGPU device code for Offload unit tests with the given arch, e.g. gfx1030")
88112

89113
add_subdirectory(OffloadAPI)
114+
add_subdirectory(Conformance)
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
add_custom_target(offload.conformance)
2+
3+
set(PLUGINS_TEST_COMMON LLVMOffload LLVMSupport)
4+
set(PLUGINS_TEST_INCLUDE ${LIBOMPTARGET_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/common)
5+
6+
add_subdirectory(device_code)
7+
8+
add_conformance_test(sin sin.cpp)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
# FIXME: Currently missing dependencies to build GPU portion automatically.
2+
add_offload_test_device_code(sin.c sin)
3+
4+
set(OFFLOAD_TEST_DEVICE_CODE_PATH ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE)
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
#include <gpuintrin.h>
2+
#include <math.h>
3+
4+
__gpu_kernel void kernel(double *out) { *out = sin(*out); }

offload/unittests/Conformance/sin.cpp

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
#include "llvm/Support/MemoryBuffer.h"
2+
#include "llvm/Support/raw_ostream.h"
3+
#include <OffloadAPI.h>
4+
#include <math.h>
5+
6+
llvm::StringRef DeviceBinsDirectory = DEVICE_CODE_PATH;
7+
8+
int main() { llvm::errs() << sin(0.0) << "\n"; }

0 commit comments

Comments
 (0)