Skip to content

Commit

Permalink
improve gtensor int tests, add readme
Browse files Browse the repository at this point in the history
  • Loading branch information
bd4 committed Jul 2, 2024
1 parent 1ee02b1 commit cb74858
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 11 deletions.
23 changes: 14 additions & 9 deletions integration_tests/gtensor/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ if(GTENSOR_DEVICE STREQUAL "cuda")
find_package(CUDAToolkit REQUIRED)
endif()

option(USE_THAPI_CTL "use thapi-ctl to start/stop tracing" ON)
set(THAPI_PATH "/opt/thapi" CACHE STRING "Path to thapi installation")

message(STATUS "${PROJECT_NAME}: THAPI_PATH=${THAPI_PATH}")
Expand All @@ -19,15 +20,19 @@ CPMFindPackage(NAME gtensor
OPTIONS "GTENSOR_ENABLE_BLAS ON"
"GTENSOR_ENABLE_SOLVER ON")

find_package(PkgConfig REQUIRED)
pkg_check_modules(LTTNG_CTL REQUIRED lttng-ctl)

add_library(thapi_ctl INTERFACE IMPORTED)
target_include_directories(thapi_ctl INTERFACE "${THAPI_PATH}/include")
target_link_libraries(thapi_ctl INTERFACE "${THAPI_PATH}/lib/libthapi-ctl.so")
target_link_libraries(thapi_ctl INTERFACE ${LTTNG_CTL_LDFLAGS})

add_executable(axpy_start_stop)
target_gtensor_sources(axpy_start_stop PRIVATE axpy_start_stop.cxx)
target_link_libraries(axpy_start_stop gtensor::gtensor)
target_link_libraries(axpy_start_stop thapi_ctl)

if (${USE_THAPI_CTL})
find_package(PkgConfig REQUIRED)
pkg_check_modules(LTTNG_CTL REQUIRED lttng-ctl)

add_library(thapi_ctl INTERFACE IMPORTED)
target_include_directories(thapi_ctl INTERFACE "${THAPI_PATH}/include")
target_link_libraries(thapi_ctl INTERFACE "${THAPI_PATH}/lib/libthapi-ctl.so")
target_link_libraries(thapi_ctl INTERFACE ${LTTNG_CTL_LDFLAGS})
target_link_libraries(axpy_start_stop thapi_ctl)
else()
target_compile_definitions(axpy_start_stop PRIVATE NO_THAPI_CTL)
endif()
13 changes: 13 additions & 0 deletions integration_tests/gtensor/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# gtensor integration tests

Allows testing cuda, hip, and ze backends with single source file.

# Usage

```
GTENSOR_DEVICE=cuda bats ./integration_tests/gtensor.bats
```
Or "hip" or "sycl"

Note that THAPI hip backend does not yet do device profiling, modifications will need to be
made for tests to pass on hip.
10 changes: 8 additions & 2 deletions integration_tests/gtensor/axpy_start_stop.cxx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@

#include <gtensor/gtensor.h>

#ifndef NO_THAPI_CTL
#include "thapi-ctl.h"
#endif

// provides convenient shortcuts for common gtensor functions, for example
// underscore ('_') to represent open slice ends.
Expand Down Expand Up @@ -73,20 +75,24 @@ int main(int argc, char** argv)
auto expr = a * d_x + d_y;

for (int i = 0; i < 10; i++) {
#ifndef NO_THAPI_CTL
if (i % 2 == 1) {
thapi_ctl_start();
gt::synchronize();
}
#endif

d_axpy = gt::eval(expr);
h_axpy = gt::empty_like(h_x);
gt::copy(d_axpy, h_axpy);
gt::synchronize();

std::cout << "axpy(10) = " << h_axpy(10) << std::endl;

#ifndef NO_THAPI_CTL
if (i % 2 == 1) {
thapi_ctl_stop();
gt::synchronize();
}
#endif
}

// Define a slice to print a subset of elements for spot checking the
Expand Down

0 comments on commit cb74858

Please sign in to comment.