Commit 3ccd938c authored by Cianciosa, Mark's avatar Cianciosa, Mark
Browse files

Inital setup for hip support.

parent 22b5f260
Loading
Loading
Loading
Loading
+15 −0
Original line number Diff line number Diff line
@@ -65,8 +65,13 @@ if (${APPLE})
    endif ()
else ()
    option (USE_CUDA "Enable the cuda backend" OFF)
    option (USE_HIP "Enable the hip backend" OFF)

    if (${USE_CUDA})
        if (${USE_HIP})
            message (FATAL_ERROR "Cannot use hip and cuda at the same time.")
        endif ()

        add_library (cuda_lib INTERFACE)

        find_package (CUDAToolkit REQUIRED)
@@ -84,6 +89,15 @@ else ()
                               $<$<BOOL:${CUDAToolkit_FOUND}>:CUDA::cuda_driver>
                               $<$<BOOL:${CUDAToolkit_FOUND}>:CUDA::nvrtc>
        )
    elseif (${USE_HIP})
        add_library (hip_lib INTERFACE)

        find_package (hip REQUIRED)

        target_link_libraries (hip_lib
                               INTERFACE
                               $<$<BOOL:${HIP_FOUND}>:hip::host>
        )
    endif ()
endif ()

@@ -92,6 +106,7 @@ target_link_libraries (gpu_lib
                       INTERFACE
                       $<$<BOOL:${USE_METAL}>:metal_lib>
                       $<$<BOOL:${USE_CUDA}>:cuda_lib>
                       $<$<BOOL:${USE_HIP}>:hip_lib>
)
target_compile_definitions (gpu_lib
                            INTERFACE
+1 −0
Original line number Diff line number Diff line
@@ -66,4 +66,5 @@ target_precompile_headers (graph_framework
                           $<$<BOOL:${USE_PCH}>:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/random.hpp>>
                           $<$<BOOL:${USE_PCH}>:$<$<BOOL:${USE_METAL}>:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/metal_context.hpp>>>
                           $<$<BOOL:${USE_PCH}>:$<$<BOOL:${USE_CUDA}>:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/cuda_context.hpp>>>
                           $<$<BOOL:${USE_HIP}>:$<$<BOOL:${USE_HIP}>:$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}/hip_context.hpp>>>
)
+6 −11
Original line number Diff line number Diff line
//------------------------------------------------------------------------------
///  @file cuda_context.hpp
///  @brief Cuda context for metal based gpus.
///  @brief Cuda context for nvidia based gpus.
///
///  Defines context for cuda gpu.
//------------------------------------------------------------------------------
@@ -27,7 +27,7 @@ namespace gpu {
///  @param[in] result Result code of the operation.
///  @param[in] name   Name of the operation.
//------------------------------------------------------------------------------
    static void check_nvrtc_error(nvrtcResult result,
    static void check_nvrtc_error(const nvrtcResult result,
                                  const std::string &name) {
#ifndef NDEBUG
        assert(result == NVRTC_SUCCESS && nvrtcGetErrorString(result));
@@ -40,7 +40,7 @@ namespace gpu {
///  @param[in] result Result code of the operation.
///  @param[in] name   Name of the operation.
//------------------------------------------------------------------------------
    static void check_error(CUresult result,
    static void check_error(const CUresult result,
                            const std::string &name) {
#ifndef NDEBUG
        const char *error;
@@ -209,11 +209,6 @@ namespace gpu {
                                                         name.c_str()),
                                  "nvrtcAddNameExpression");
            }
            if (add_reduction) {
                check_nvrtc_error(nvrtcAddNameExpression(kernel_program,
                                                         "max_reduction"),
                                  "nvrtcAddNameExpression");
            }

            std::ostringstream arch;
            int compute_version;