diff --git a/.gitlab-ci.yml b/.gitlab-ci.yml index f9729e9..795f769 100644 --- a/.gitlab-ci.yml +++ b/.gitlab-ci.yml @@ -5,7 +5,7 @@ stages: image: - name: "seissol/gpu-ci-image:v0.0.4" + name: "seissol/gpu-ci-image:v0.0.5" entrypoint: [""] @@ -35,7 +35,7 @@ tests: - atsccs68-docker-executor parallel: matrix: - - BACKEND: [cuda, hip, hipsycl] + - BACKEND: [cuda, hip, opensycl] script: - *common_test_script - mkdir -p tests/build @@ -51,7 +51,7 @@ basic_example: - atsccs68-docker-executor parallel: matrix: - - BACKEND: [cuda, hip, hipsycl] + - BACKEND: [cuda, hip, opensycl] script: - *common_test_script - export WORKDIR=./examples/basic/build @@ -67,7 +67,7 @@ jacobi_example: - atsccs68-docker-executor parallel: matrix: - - BACKEND: [cuda, hip, hipsycl] + - BACKEND: [cuda, hip, opensycl] before_script: - git clone --depth 1 --branch release-1.10.0 https://github.com/google/googletest - mkdir -p googletest/build && cd googletest/build diff --git a/CMakeLists.txt b/CMakeLists.txt index 36f7afd..c063559 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -9,13 +9,13 @@ if (NOT DEFINED DEVICE_BACKEND) message(FATAL_ERROR "DEVICE_BACKEND variable has not been provided into the submodule") else() set(FOUND OFF) - foreach(VARIANT cuda hip oneapi hipsycl) + foreach(VARIANT cuda hip oneapi opensycl) if (${DEVICE_BACKEND} STREQUAL ${VARIANT}) set(FOUND ON) endif() endforeach() if (NOT FOUND) - message(FATAL_ERROR "DEVICE_BACKEND must be either cuda, hip, opeapi, or hipsycl. Given: ${DEVICE_BACKEND}") + message(FATAL_ERROR "DEVICE_BACKEND must be either cuda, hip, opeapi, or opensycl. Given: ${DEVICE_BACKEND}") endif() endif() @@ -53,7 +53,7 @@ if (${DEVICE_BACKEND} STREQUAL "cuda") elseif(${DEVICE_BACKEND} STREQUAL "hip") set(BACKEND_FOLDER "hip") include(hip.cmake) -elseif((${DEVICE_BACKEND} STREQUAL "oneapi") OR (${DEVICE_BACKEND} STREQUAL "hipsycl")) +elseif((${DEVICE_BACKEND} STREQUAL "oneapi") OR (${DEVICE_BACKEND} STREQUAL "opensycl")) set(BACKEND_FOLDER "sycl") include(sycl.cmake) endif() diff --git a/DeviceMacros.h b/DeviceMacros.h index ade8bfc..db133ff 100644 --- a/DeviceMacros.h +++ b/DeviceMacros.h @@ -12,8 +12,8 @@ #elif defined(DEVICE_ONEAPI_LANG) #error do not launch kernel with macros using OneAPI -#elif defined(DEVICE_HIPSYCL_LANG) -#error do not launch kernel with macros using hipsycl +#elif defined(DEVICE_OPENSYCL_LANG) +#error do not launch kernel with macros using opensycl #else #error gpu interface not supported. diff --git a/README.md b/README.md index 96a34cf..ac7533b 100644 --- a/README.md +++ b/README.md @@ -14,7 +14,7 @@ The folder structure sets up like this: Currently, there are three implementations available * Nvidia's C CUDA * AMD's HIP -* SYCL implemented by Intel's OneAPI and hipSYCL (https://github.com/illuhad/hipSYCL) +* SYCL implemented by Intel's OneAPI and OpenSYCL (https://github.com/OpenSYCL/OpenSYCL.git) ## Setup and Build The setup is explained with linux commands; for windows, see the belonging batch reference. @@ -39,7 +39,7 @@ If you want to run the examples, follow the instructions in the belonging packag ### Device options for OneAPI * use `-DDEVICE_BACKEND:STRING=oneapi` to build the OneAPI implementation -* currently, OneAPI is mainly used to target Intel devices; for CUDA or HIP as device backend, use hipSYCL and set the right environment variables, respectively +* currently, OneAPI is mainly used to target Intel devices; for CUDA or HIP as device backend, use openSYCL and set the right environment variables, respectively * Set the environment variable `PREFERRED_DEVICE_TYPE` to compile for the defined `DEVICE_ARCH` * If `PREFERRED_DEVICE_TYPE` is not specified on build, JIT compilation is assumed and the value of `DEVICE_ARCH` is ignored * Options for `PREFERRED_DEVICE_TYPE` are `GPU`, `CPU`, or `FPGA` @@ -47,10 +47,10 @@ If you want to run the examples, follow the instructions in the belonging packag * If `PREFERRED_DEVICE_TYPE` was not specified on build but before running an application, the JIT compiler will generate the kernels and allows switching the device type at runtime * Complete example call: `export PREFERRED_DEVICE_TYPE=GPU` and `cmake .. -DDEVICE_BACKEND:STRING=oneapi -DREAL_SIZE_IN_BYTES=4 -DDEVICE_ARCH=dg1` -### Device options for hipSYCL -* use `-DDEVICE_BACKEND:STRING=hipsycl` to build for hipSYCL -* hipSYCL does currently not require the definition of a sub architecture, but it has to be specified in the cmake -* Complete example call: `cmake .. -DDEVICE_BACKEND:STRING=hipsycl -DREAL_SIZE_IN_BYTES=4 -DDEVICE_ARCH=dg1` +### Device options for openSYCL +* use `-DDEVICE_BACKEND:STRING=opensycl` to build for openSYCL +* openSYCL does currently not require the definition of a sub architecture, but it has to be specified in the cmake +* Complete example call: `cmake .. -DDEVICE_BACKEND:STRING=opensycl -DREAL_SIZE_IN_BYTES=4 -DDEVICE_ARCH=dg1` ## Add another API * Extend the CMakeLists.txt with the new API diff --git a/cmake/FindOpenSyclConfig.cmake b/cmake/FindOpenSyclConfig.cmake new file mode 100644 index 0000000..f9c9910 --- /dev/null +++ b/cmake/FindOpenSyclConfig.cmake @@ -0,0 +1,45 @@ +include(FindPackageHandleStandardArgs) +include(CheckCXXSourceRuns) +include(CMakePushCheckState) + +cmake_push_check_state() +include(CheckCXXSourceCompiles) + +if (NOT TARGET opensycl-config::interface) + if (NOT DEFINED DEVICE_ARCH) + message(FATAL_ERROR "`DEVICE_ARCH` env. variable is not provided.") + else() + + add_library(opensycl-config::interface INTERFACE IMPORTED) + + execute_process(COMMAND python3 ${CMAKE_CURRENT_LIST_DIR}/find-opensycl.py -i + OUTPUT_VARIABLE _OPENSYCL_INLCUDE_DIR) + + target_include_directories(opensycl-config::interface INTERFACE ${_OPENSYCL_INLCUDE_DIR} + ${_OPENSYCL_INLCUDE_DIR}/sycl) + + execute_process(COMMAND python3 ${CMAKE_CURRENT_LIST_DIR}/find-opensycl.py --vendor + OUTPUT_VARIABLE _OPENSYCL_VENDOR) + + target_compile_definitions(opensycl-config::interface INTERFACE SYCL_PLATFORM_"${_OPENSYCL_VENDOR}") + + + execute_process(COMMAND python3 ${CMAKE_CURRENT_LIST_DIR}/find-opensycl.py -t -a "${DEVICE_ARCH}" + OUTPUT_VARIABLE _OPENSYCL_FULL_TARGET_NAME) + + set(HIPSYCL_TARGETS "${_OPENSYCL_FULL_TARGET_NAME}") + set(OPENSYCL_TARGETS "${_OPENSYCL_FULL_TARGET_NAME}") + + find_package(OpenMP REQUIRED) + add_library(opensycl-config::device_flags INTERFACE IMPORTED) + target_link_libraries(opensycl-config::device_flags INTERFACE OpenMP::OpenMP_CXX) + set_property(TARGET opensycl-config::device_flags PROPERTY POSITION_INDEPENDENT_CODE ON) + + endif() +endif() + + +find_package_handle_standard_args(OpenSyclConfig _OPENSYCL_INLCUDE_DIR + _OPENSYCL_FULL_TARGET_NAME + _OPENSYCL_VENDOR) +cmake_pop_check_state() diff --git a/cmake/find-opensycl.py b/cmake/find-opensycl.py new file mode 100644 index 0000000..04b63bd --- /dev/null +++ b/cmake/find-opensycl.py @@ -0,0 +1,83 @@ +import os +import sys +from shutil import which +import argparse +import json + + +def get_package_dir(): + exe_name = which("syclcc") + bin_dir = os.path.dirname(exe_name) + return os.path.dirname(bin_dir) + + +def get_config(): + package_dir = get_package_dir() + etc_dir = os.path.join(package_dir, "etc") + config_file = None + for root, dirs, files in os.walk(etc_dir): + for file in files: + if file == "syclcc.json": + config_file = os.path.join(root, file) + break + + if not config_file: + print("failed to find opensycl config file", file=sys.stderr) + sys.exit(1) + + with open(config_file, 'r') as file: + data = json.load(file) + return data + + +def get_full_target_name(arch): + data = get_config() + platform = data["default-platform"] + if platform == 'cuda': + if not (data['default-nvcxx'].isspace() or 'NOTFOUND' in data['default-nvcxx']): + default_target='cuda-nvcxx' + arch = arch.replace('sm_', 'cc') + else: + default_target='cuda' + elif platform == 'rocm': + default_target='hip' + print(f'{default_target}:{arch}', end='') + + +def get_vendor_name(): + data = get_config() + platform = data["default-platform"] + if platform == 'cuda': + print('NVIDIA', end='') + elif platform == 'rocm': + print('AMD', end='') + else: + print('Intel', end='') + + +def get_include_dir(): + package_dir = get_package_dir() + include_dir = os.path.join(package_dir, 'include') + print(include_dir, end = '') + +if __name__ == '__main__': + parser = argparse.ArgumentParser(description='Extracts info from opensycl') + parser.add_argument('-t', '--target', action='store_true', help='get default target') + parser.add_argument('-i', '--include_dir', action='store_true', help='get include dir') + parser.add_argument('-a', '--arch', type=str, help='architecture name') + parser.add_argument('--vendor', action='store_true', help='get vendor name') + args = parser.parse_args() + + if (args.target): + if (not args.arch): + print("architecture name is not provided", file=sys.stderr) + sys.exit(1) + get_full_target_name(args.arch) + + if (args.include_dir): + get_include_dir() + + if (args.vendor): + get_vendor_name() + + \ No newline at end of file diff --git a/device.cpp b/device.cpp index 6a2d137..3fa6e22 100644 --- a/device.cpp +++ b/device.cpp @@ -6,7 +6,7 @@ #include "HipWrappedAPI.h" #elif DEVICE_ONEAPI_LANG #include "interfaces/sycl/SyclWrappedAPI.h" -#elif DEVICE_HIPSYCL_LANG +#elif DEVICE_OPENSYCL_LANG #include "interfaces/sycl/SyclWrappedAPI.h" #else #error "Unknown interface for the device wrapper" diff --git a/examples/cmake/common_options.cmake b/examples/cmake/common_options.cmake index 1ad45de..7529274 100644 --- a/examples/cmake/common_options.cmake +++ b/examples/cmake/common_options.cmake @@ -9,7 +9,7 @@ set(REAL_SIZE_IN_BYTES "8" CACHE STRING "size of the floating point data type") set_property(CACHE REAL_SIZE_IN_BYTES PROPERTY STRINGS "8" "4") set(DEVICE_BACKEND "cuda" CACHE STRING "type of an interface") -set_property(CACHE DEVICE_BACKEND PROPERTY STRINGS "cuda" "hip" "oneapi" "hipsycl") +set_property(CACHE DEVICE_BACKEND PROPERTY STRINGS "cuda" "hip" "oneapi" "opensycl") set(DEVICE_ARCH "sm_60" CACHE STRING "model of Streaming Multiprocessor") set(DEVICE_ARCH_OPTIONS "sm_50" "sm_60" "sm_70" "sm_71" "sm_75" "sm_80" "sm_86" diff --git a/examples/jacobi/CMakeLists.txt b/examples/jacobi/CMakeLists.txt index 786ae34..d21a9a5 100644 --- a/examples/jacobi/CMakeLists.txt +++ b/examples/jacobi/CMakeLists.txt @@ -37,13 +37,6 @@ add_executable(solver src/main.cpp src/gpu/solver.cpp src/matrix_manip.cpp) -if (${DEVICE_BACKEND} STREQUAL "hipsycl") - find_package(OpenMP REQUIRED) - target_link_libraries(solver PUBLIC OpenMP::OpenMP_CXX) - target_link_libraries(device PUBLIC OpenMP::OpenMP_CXX) - target_link_libraries(kernel PUBLIC OpenMP::OpenMP_CXX) -endif() - target_include_directories(solver PUBLIC src root ${__MPI_INCLUDES}) diff --git a/examples/jacobi/src/gpu/kernels/CMakeLists.txt b/examples/jacobi/src/gpu/kernels/CMakeLists.txt index 44dd93f..4860143 100644 --- a/examples/jacobi/src/gpu/kernels/CMakeLists.txt +++ b/examples/jacobi/src/gpu/kernels/CMakeLists.txt @@ -8,6 +8,6 @@ if (${DEVICE_BACKEND} STREQUAL "hip") include(hip.cmake) elseif(${DEVICE_BACKEND} STREQUAL "cuda") include(cuda.cmake) -elseif((${DEVICE_BACKEND} STREQUAL "oneapi") OR (${DEVICE_BACKEND} STREQUAL "hipsycl")) +elseif((${DEVICE_BACKEND} STREQUAL "oneapi") OR (${DEVICE_BACKEND} STREQUAL "opensycl")) include(sycl.cmake) endif() diff --git a/examples/jacobi/src/gpu/kernels/sycl.cmake b/examples/jacobi/src/gpu/kernels/sycl.cmake index d3c3635..5868246 100644 --- a/examples/jacobi/src/gpu/kernels/sycl.cmake +++ b/examples/jacobi/src/gpu/kernels/sycl.cmake @@ -15,15 +15,14 @@ target_compile_definitions(${TARGET_NAME} PRIVATE DEVICE_${DEVICE_BACKEND}_LANG target_include_directories(${TARGET_NAME} PUBLIC root) target_link_libraries(${TARGET_NAME} PUBLIC device) -if (${DEVICE_BACKEND} STREQUAL "hipsycl") - if(NOT DEFINED HIPSYCL_TARGETS) - set(HIPSYCL_TARGETS "cuda:sm_${DEVICE_ARCH}") - endif() - - find_package(hipSYCL CONFIG REQUIRED) +set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/root/cmake" "${CMAKE_ROOT}/Modules") +if (${DEVICE_BACKEND} STREQUAL "opensycl") + find_package(OpenSyclConfig REQUIRED) + find_package(OpenSYCL REQUIRED) + target_link_libraries(${TARGET_NAME} PRIVATE opensycl-config::device_flags) + target_link_libraries(${TARGET_NAME} PUBLIC opensycl-config::interface) add_sycl_to_target(TARGET ${TARGET_NAME} SOURCES ${DEVICE_SOURCE_FILES}) else() - set(CMAKE_MODULE_PATH "${PROJECT_SOURCE_DIR}/root/cmake" "${CMAKE_ROOT}/Modules") find_package(DpcppFlags REQUIRED) target_link_libraries(${TARGET_NAME} PRIVATE dpcpp::device_flags) endif() diff --git a/sycl.cmake b/sycl.cmake index 1b0fcd3..e997d45 100644 --- a/sycl.cmake +++ b/sycl.cmake @@ -21,11 +21,10 @@ endif() add_library(device SHARED ${DEVICE_SOURCE_FILES}) -if (${DEVICE_BACKEND} STREQUAL "hipsycl") - set(HIPSYCL_TARGETS "cuda:${DEVICE_ARCH}") - find_package(hipSYCL CONFIG REQUIRED) - find_package(OpenMP REQUIRED) - target_compile_options(device PRIVATE -Wno-unknown-cuda-version ${OpenMP_CXX_FLAGS}) +if (${DEVICE_BACKEND} STREQUAL "opensycl") + find_package(OpenSyclConfig REQUIRED) + find_package(OpenSYCL REQUIRED) + target_link_libraries(device PRIVATE opensycl-config::device_flags) add_sycl_to_target(TARGET device SOURCES ${DEVICE_SOURCE_FILES}) else() find_package(DpcppFlags REQUIRED) diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 26c754f..cb52dd0 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -12,7 +12,7 @@ set_property(CACHE SM PROPERTY STRINGS ${SM_OPTIONS}) set(DEVICE_ARCH ${SM}) set(DEVICE_BACKEND "cuda" CACHE STRING "type of an interface") -set_property(CACHE DEVICE_BACKEND PROPERTY STRINGS "cuda" "hip" "oneapi" "hipsycl") +set_property(CACHE DEVICE_BACKEND PROPERTY STRINGS "cuda" "hip" "oneapi" "opensycl") set(REAL_SIZE_IN_BYTES "8" CACHE STRING "size of the floating point data type") set_property(CACHE REAL_SIZE_IN_BYTES PROPERTY STRINGS "8" "4")