Skip to content

Commit

Permalink
renamed hipsycl to opensycl
Browse files Browse the repository at this point in the history
  • Loading branch information
Ravil Dorozhinskii committed Apr 1, 2023
1 parent beb893c commit 37cfb0e
Show file tree
Hide file tree
Showing 13 changed files with 157 additions and 38 deletions.
8 changes: 4 additions & 4 deletions .gitlab-ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ stages:


image:
name: "seissol/gpu-ci-image:v0.0.4"
name: "seissol/gpu-ci-image:v0.0.5"
entrypoint: [""]


Expand Down Expand Up @@ -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
Expand All @@ -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
Expand All @@ -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
Expand Down
6 changes: 3 additions & 3 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()

Expand Down Expand Up @@ -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()
Expand Down
4 changes: 2 additions & 2 deletions DeviceMacros.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
12 changes: 6 additions & 6 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -39,18 +39,18 @@ 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`
* The environment variable must be also set before running any code using this lib. The runtime needs this hint to select the right device the code was compile for. If the value was not specified or illegal, the runtime applies a default selection strategy, preferring GPUs over CPUs and CPUs over the host. This might crashes the application if the targeted compilation architecture differs from the runtime target
* 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
Expand Down
45 changes: 45 additions & 0 deletions cmake/FindOpenSyclConfig.cmake
Original file line number Diff line number Diff line change
@@ -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()
83 changes: 83 additions & 0 deletions cmake/find-opensycl.py
Original file line number Diff line number Diff line change
@@ -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()


2 changes: 1 addition & 1 deletion device.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
2 changes: 1 addition & 1 deletion examples/cmake/common_options.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
7 changes: 0 additions & 7 deletions examples/jacobi/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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})
Expand Down
2 changes: 1 addition & 1 deletion examples/jacobi/src/gpu/kernels/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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()
13 changes: 6 additions & 7 deletions examples/jacobi/src/gpu/kernels/sycl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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()
9 changes: 4 additions & 5 deletions sycl.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion tests/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down

0 comments on commit 37cfb0e

Please sign in to comment.