Skip to content

[Offload] Add skeleton for offload conformance tests #146391

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 1, 2025

Conversation

jhuber6
Copy link
Contributor

@jhuber6 jhuber6 commented Jun 30, 2025

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.

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`.
@llvmbot
Copy link
Member

llvmbot commented Jun 30, 2025

@llvm/pr-subscribers-offload

Author: Joseph Huber (jhuber6)

Changes

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.


Full diff: https://github.com/llvm/llvm-project/pull/146391.diff

5 Files Affected:

  • (modified) offload/unittests/CMakeLists.txt (+25)
  • (added) offload/unittests/Conformance/CMakeLists.txt (+8)
  • (added) offload/unittests/Conformance/device_code/CMakeLists.txt (+4)
  • (added) offload/unittests/Conformance/device_code/sin.c (+4)
  • (added) offload/unittests/Conformance/sin.cpp (+8)
diff --git a/offload/unittests/CMakeLists.txt b/offload/unittests/CMakeLists.txt
index 7cd41e1dcdafd..1eae785b8765f 100644
--- a/offload/unittests/CMakeLists.txt
+++ b/offload/unittests/CMakeLists.txt
@@ -81,9 +81,34 @@ function(add_offload_unittest test_dirname)
   target_include_directories(${target_name} PRIVATE ${PLUGINS_TEST_INCLUDE})
 endfunction()
 
+function(add_conformance_test test_name)
+  set(target_name "${test_name}.conformance")
+
+  list(TRANSFORM ARGN PREPEND "${CMAKE_CURRENT_SOURCE_DIR}/" OUTPUT_VARIABLE files)
+
+  if(NOT TARGET libc)
+    message(WARNING "Cannot run conformance tests without the LLVM C library")
+    return()
+  endif()
+
+  add_executable(${target_name} ${files})
+  add_dependencies(${target_name} ${PLUGINS_TEST_COMMON} ${test_name}.bin)
+  target_compile_definitions(${target_name} PRIVATE DEVICE_CODE_PATH="${CONFORMANCE_TEST_DEVICE_CODE_PATH}")
+  target_link_libraries(${target_name} PRIVATE ${PLUGINS_TEST_COMMON} libc)
+  target_include_directories(${target_name} PRIVATE ${PLUGINS_TEST_INCLUDE})
+  set_target_properties(${target_name} PROPERTIES EXCLUDE_FROM_ALL TRUE)
+
+  add_custom_target(offload.conformance.${test_name}
+    COMMAND $<TARGET_FILE:${target_name}>
+    DEPENDS ${target_name}
+    COMMENT "Running conformance test ${test_name}")
+  add_dependencies(offload.conformance offload.conformance.${test_name})
+endfunction()
+
 set(OFFLOAD_TESTS_FORCE_NVPTX_ARCH "" CACHE STRING
   "Force building of NVPTX device code for Offload unit tests with the given arch, e.g. sm_61")
 set(OFFLOAD_TESTS_FORCE_AMDGPU_ARCH "" CACHE STRING
   "Force building of AMDGPU device code for Offload unit tests with the given arch, e.g. gfx1030")
 
 add_subdirectory(OffloadAPI)
+add_subdirectory(Conformance)
diff --git a/offload/unittests/Conformance/CMakeLists.txt b/offload/unittests/Conformance/CMakeLists.txt
new file mode 100644
index 0000000000000..bc3141757372a
--- /dev/null
+++ b/offload/unittests/Conformance/CMakeLists.txt
@@ -0,0 +1,8 @@
+add_custom_target(offload.conformance)
+
+set(PLUGINS_TEST_COMMON LLVMOffload LLVMSupport)
+set(PLUGINS_TEST_INCLUDE ${LIBOMPTARGET_INCLUDE_DIR} ${CMAKE_CURRENT_SOURCE_DIR}/common)
+
+add_subdirectory(device_code)
+
+add_conformance_test(sin sin.cpp)
diff --git a/offload/unittests/Conformance/device_code/CMakeLists.txt b/offload/unittests/Conformance/device_code/CMakeLists.txt
new file mode 100644
index 0000000000000..223f04ccfb698
--- /dev/null
+++ b/offload/unittests/Conformance/device_code/CMakeLists.txt
@@ -0,0 +1,4 @@
+# FIXME: Currently missing dependencies to build GPU portion automatically.
+add_offload_test_device_code(sin.c sin)
+
+set(OFFLOAD_TEST_DEVICE_CODE_PATH ${CMAKE_CURRENT_BINARY_DIR} PARENT_SCOPE)
diff --git a/offload/unittests/Conformance/device_code/sin.c b/offload/unittests/Conformance/device_code/sin.c
new file mode 100644
index 0000000000000..e969e60f352a2
--- /dev/null
+++ b/offload/unittests/Conformance/device_code/sin.c
@@ -0,0 +1,4 @@
+#include <gpuintrin.h>
+#include <math.h>
+
+__gpu_kernel void kernel(double *out) { *out = sin(*out); }
diff --git a/offload/unittests/Conformance/sin.cpp b/offload/unittests/Conformance/sin.cpp
new file mode 100644
index 0000000000000..9e15690a9e9d7
--- /dev/null
+++ b/offload/unittests/Conformance/sin.cpp
@@ -0,0 +1,8 @@
+#include "llvm/Support/MemoryBuffer.h"
+#include "llvm/Support/raw_ostream.h"
+#include <OffloadAPI.h>
+#include <math.h>
+
+llvm::StringRef DeviceBinsDirectory = DEVICE_CODE_PATH;
+
+int main() { llvm::errs() << sin(0.0) << "\n"; }

Copy link
Contributor

@jplehr jplehr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@jhuber6 jhuber6 merged commit 3cff3d8 into llvm:main Jul 1, 2025
9 checks passed
rlavaee pushed a commit to rlavaee/llvm-project that referenced this pull request Jul 1, 2025
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`.
rlavaee pushed a commit to rlavaee/llvm-project that referenced this pull request Jul 1, 2025
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`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants