Skip to content
This repository was archived by the owner on Jan 24, 2024. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -38,3 +38,4 @@ nv_gpu_build
ios_build
gpu_build
output
third-party/extern_miopen
7 changes: 7 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,8 @@ anakin_option(USE_MKL "Use mkl libs." NO if USE_X86_PLACE)
anakin_option(USE_MKLML "Use MKLML libs." YES if USE_X86_PLACE)
anakin_option(USE_XBYAK "Use XBYAK libs." YES if USE_X86_PLACE)
anakin_option(USE_OPENMP "Use Openmp when in android environment." YES if TARGET_ANDROID)
anakin_option(USE_OPENSSL "Use OpenSSL." YES if AMD_GPU)
anakin_option(USE_MIOPENGEMM "Use MIOpenGEMM ." YES if AMD_GPU)

# build components
anakin_option(BUILD_WITH_UNIT_TEST "Build anakin unit test components." YES)
Expand All @@ -148,6 +150,10 @@ if(ENABLE_MIN_DEPENDENCY)
set(CMAKE_SHARED_LINKER_FLAGS "-Wl,--version-script,${ANAKIN_ROOT}/cmake/ak_link.lds")
endif()

# for AMD profile computing performance
anakin_option(ENABLE_AMD_PROFILING "Enable amd profiling" NO)
anakin_option(ENABLE_AMD_DEBUG "Enable amd debug" NO)

# ----------------------------------------------------------------------------
# section: anakin compiler and linker options
# ----------------------------------------------------------------------------
Expand Down Expand Up @@ -201,6 +207,7 @@ endif()

if(AMD_GPU)
include(cmake/amd.cmake)
include(cmake/external/miopen.cmake)
endif()

# gather all the config options to anakin
Expand Down
83 changes: 68 additions & 15 deletions cmake/amd.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,77 @@ macro(amd_set_opencl_path)
#endif()
endmacro()

macro(amd_build_cl_file file_path dest_path)
FILE(GLOB CL_FILES ${file_path}/*.cl)
message(STATUS "found cl files: ${CL_FILES}")
foreach(src_file ${CL_FILES})
get_filename_component(src_file_name ${src_file} NAME)
message(STATUS "copy ${src_file} to : ${dest_path}/${src_file_name}")
configure_file( ${absdir}/${src_file} ${dest_path}/${src_file_name} COPYONLY)
endforeach()
macro(amd_find_file regexps)
FILE(GLOB FOUND_FILES ${regexps})
endmacro()

function(add_kernels KERNEL_FILES)
set(INIT_KERNELS_LIST)

macro(amd_build_cl_binary_file file_path dest_path)
FILE(GLOB CL_FILES ${file_path}/*.so)
message(STATUS "found cl files: ${CL_FILES}")
foreach(src_file ${CL_FILES})
get_filename_component(src_file_name ${src_file} NAME)
message(STATUS "copy ${src_file} to : ${dest_path}/${src_file_name}")
configure_file( ${absdir}/${src_file} ${dest_path}/${src_file_name} COPYONLY)
foreach(KERNEL_FILE ${KERNEL_FILES})
if("${CMAKE_VERSION}" VERSION_LESS 3.0)
configure_file(${KERNEL_FILE} ${KERNEL_FILE}.delete)
else()
set_property(DIRECTORY APPEND PROPERTY CMAKE_CONFIGURE_DEPENDS ${KERNEL_FILE})
endif()
get_filename_component(BASE_NAME ${KERNEL_FILE} NAME_WE)
string(TOUPPER "${BASE_NAME}" KEY_NAME)
string(MAKE_C_IDENTIFIER "${KEY_NAME}" VAR_NAME)
list(APPEND INIT_KERNELS_LIST " { \"${KEY_NAME}\", std::string(reinterpret_cast<const char*>(${VAR_NAME}), ${VAR_NAME}_SIZE) }")
endforeach()
string(REPLACE ";" ",\n" INIT_KERNELS "${INIT_KERNELS_LIST}")
configure_file("${CMAKE_SOURCE_DIR}/saber/core/impl/amd/utils/amd_kernels.cpp.in" ${PROJECT_BINARY_DIR}/amd_kernels.cpp)
endfunction()

macro(generate_amd_kernel_src)
set(AMD_KERNELS)
set(AMD_KERNEL_INCLUDES)

set(FILE_REGEXP
"${CMAKE_SOURCE_DIR}/saber/funcs/impl/amd/cl/*.cl"
"${CMAKE_SOURCE_DIR}/saber/funcs/impl/amd/cl/*.s"
"${CMAKE_SOURCE_DIR}/saber/funcs/impl/amd/lib/*.so"
"${CMAKE_SOURCE_DIR}/test/saber/amd/*.cl"
)
amd_find_file("${FILE_REGEXP}")
list(APPEND AMD_KERNELS ${FOUND_FILES})

set(FILE_REGEXP
"${CMAKE_SOURCE_DIR}/saber/funcs/impl/amd/cl/*.inc"
)
amd_find_file("${FILE_REGEXP}")
list(APPEND AMD_KERNEL_INCLUDES ${FOUND_FILES})

#message(STATUS =======${AMD_KERNELS}======)
#message(STATUS =======${AMD_KERNEL_INCLUDES}======)
add_kernels("${AMD_KERNELS}")
add_custom_command(
OUTPUT ${PROJECT_BINARY_DIR}/amd_kernels.h
WORKING_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}
DEPENDS ${MIOPEN_PROJECT} ${AMD_KERNELS} ${AMD_KERNEL_INCLUDES}
COMMAND ${MIOPEN_BINARY_DIR}/bin/addkernels -guard GUARD_AMD_KERNELS_HPP_ -target ${PROJECT_BINARY_DIR}/amd_kernels.h -source ${AMD_KERNELS}
COMMENT "Inlining AMD kernels"
)
add_custom_target(amd_kernels DEPENDS ${PROJECT_BINARY_DIR}/amd_kernels.h)
include_directories($PROJECT_BINARY_DIR}/amd_kernels.h)
list(APPEND ANAKIN_SABER_DEPENDENCIES amd_kernels)
list(APPEND ANAKIN_SABER_BASE_SRC ${PROJECT_BINARY_DIR}/amd_kernels.cpp)
endmacro()

macro(amd_set_miopengemm_path)
if(NOT DEFINED MIOPENGEMM_INCLUDE_DIR)
set(MIOPENGEMM_INCLUDE_DIR "/opt/rocm/miopengemm/include")
endif()
if(NOT DEFINED MIOPENGEMM_LIBRARY)
set(MIOPENGEMM_LIBRARY "/opt/rocm/miopengemm/lib64/libmiopengemm.so")
endif()

#FIND_PACKAGE(miopengemm REQUIRED)
#if(miopengemm_FOUND)
# message(STATUS "Found miopengemm in ${MIOPENGEMM_INCLUDE_DIR}")
# message(STATUS "Found miopengemm lib in ${MIOPENGEMM_LIBRARY}")
# include_directories(${MIOPENGEMM_INCLUDE_DIR})
# LINK_LIBRARIES(${MIOPENGEMM_LIBRARY})
#endif()
endmacro()

6 changes: 5 additions & 1 deletion cmake/config/anakin_config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@

#cmakedefine USE_GFLAGS

#cmakedefine USE_MIOPENGEMM

// plantform to use
#cmakedefine USE_GPU_PLACE
Expand Down Expand Up @@ -83,6 +84,10 @@
// build arm lite
#cmakedefine BUILD_LITE

// for AMD profiling computing performance
#cmakedefine ENABLE_AMD_PROFILING

#cmakedefine ENABLE_AMD_DEBUG

#if defined(ANDROID) || defined(__ANDROID__)
#define PLATFORM_ANDROID
Expand Down Expand Up @@ -114,4 +119,3 @@
#endif

#endif

43 changes: 10 additions & 33 deletions cmake/external/miopen.cmake
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -14,50 +14,27 @@
include(ExternalProject)

set(MIOPEN_PROJECT extern_miopen)
set(MIOPEN_PREFIX_DIR ${ANAKIN_TEMP_THIRD_PARTY_PATH}/miopen)
set(MIOPEN_INSTALL_ROOT ${ANAKIN_THIRD_PARTY_PATH}/miopen)
set(MIOPEN_SOURCE_DIR ${MIOPEN_PREFIX_DIR}/src/${MIOPEN_PROJECT})
set(MIOPEN_BINARY_DIR ${MIOPEN_PREFIX_DIR}/src/${MIOPEN_PROJECT}-build)
set(MIOPEN_PREFIX_DIR ${ANAKIN_THIRD_PARTY_PATH})
set(MIOPEN_INSTALL_ROOT ${ANAKIN_ROOT}/output/miopen)
set(MIOPEN_SOURCE_DIR ${ANAKIN_THIRD_PARTY_PATH}/${MIOPEN_PROJECT})
set(MIOPEN_STAMP_DIR ${ANAKIN_TEMP_THIRD_PARTY_PATH}/${MIOPEN_PROJECT}/stamp)
set(MIOPEN_BINARY_DIR ${ANAKIN_TEMP_THIRD_PARTY_PATH}/${MIOPEN_PROJECT}/build)
set(MIOPEN_LIB ${MIOPEN_INSTALL_ROOT}/lib/libMIOpen.so CACHE FILEPATH "miopen library." FORCE)

if(NOT Boost_FOUND)
set(BOOST_ROOT ${BOOST_INSTALL_ROOT} CACHE FILEPATH "boost library/" FORCE)
endif()

message(STATUS "Scanning external modules ${Green}MIOPEN${ColourReset} ...")

ExternalProject_Add(
${MIOPEN_PROJECT}_customize
GIT_REPOSITORY "ssh://[email protected]:8235/baidu/third-party/miopen"
GIT_TAG "cbd4e7dbad0599c7327cb43888476ab8d966f285"
PREFIX ${ANAKIN_TEMP_THIRD_PARTY_PATH}/miopen/customize_miopen_file
SOURCE_DIR ${ANAKIN_THIRD_PARTY_PATH}/miopen/customize_miopen_file
CONFIGURE_COMMAND ""
BUILD_COMMAND ""
INSTALL_COMMAND ""
)

ExternalProject_Add(
${MIOPEN_PROJECT}
DEPENDS ${MIOPEN_PROJECT}_customize
GIT_REPOSITORY "ssh://[email protected]:8235/baidu/third-party/miopen"
GIT_TAG 1.4.2
GIT_REPOSITORY https://github.com/ROCmSoftwarePlatform/Anakin.git
GIT_TAG anakin-amd_miopen
PREFIX ${MIOPEN_PREFIX_DIR}
CMAKE_ARGS -DMIOPEN_BACKEND=OpenCL -DCMAKE_INSTALL_PREFIX=${MIOPEN_INSTALL_ROOT} -DCMAKE_INSTALL_LIBDIR=lib -DBOOST_ROOT=${BOOST_ROOT}
#LOG_DOWNLOAD 1
STAMP_DIR ${MIOPEN_STAMP_DIR}
BINARY_DIR ${MIOPEN_BINARY_DIR}
CMAKE_ARGS -DMIOPEN_BACKEND=OpenCL -DCMAKE_INSTALL_PREFIX=${MIOPEN_INSTALL_ROOT} -DCMAKE_INSTALL_LIBDIR=lib
LOG_BUILD 1

)

ExternalProject_Add_Step(
${MIOPEN_PROJECT} ${MIOPEN_PROJECT}_customize
DEPENDEES download
DEPENDERS build
COMMAND ${CMAKE_COMMAND} -E copy_directory ${ANAKIN_THIRD_PARTY_PATH}/miopen/customize_miopen_file ${MIOPEN_SOURCE_DIR}
ALWAYS 1
EXCLUDE_FORM_MAIN 1
LOG 1
)
include_directories(${MIOPEN_INSTALL_ROOT}/include)
add_library(miopen SHARED IMPORTED GLOBAL)
SET_PROPERTY(TARGET miopen PROPERTY IMPORTED_LOCATION ${MIOPEN_LIB})
Expand Down
24 changes: 22 additions & 2 deletions cmake/find_modules.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -440,10 +440,19 @@ macro(anakin_find_bmlib)
list(APPEND BM_LIBRARIES ${BM_ROOT}/lib/app/libbmrt.so)
list(APPEND ANAKIN_LINKER_LIBS ${BM_LIBRARIES})
else()
message(FATAL_ERROR "Could not found bm_lib")
endif()
message(FATAL_ERROR "Could not found bm_lib")
endmacro()

macro(anakin_find_openssl)
find_package(OpenSSL REQUIRED)
if(OPENSSL_FOUND)
message(STATUS "Found openssl in ${OPENSSL_INCLUDE_DIR}")
list(APPEND ANAKIN_LINKER_LIBS ${OPENSSL_LIBRARIES})
include_directories(${OPENSSL_INCLUDE_DIR})
else()
message(FATAL_ERROR "Could not found openmp !")
endif()
endmacro()

macro(anakin_find_nvinfer)
find_path(NVINFER_INCLUDE_DIR NvInfer.h PATHS ${ANAKIN_ROOT}/third-party/tensorrt5/include
Expand Down Expand Up @@ -488,3 +497,14 @@ macro(anakin_find_nvinfer)
endif()
endmacro()

#find miopengemm
macro(anakin_find_miopengemm)
find_package(miopengemm REQUIRED PATHS /opt/rocm)
if(miopengemm_FOUND)
set(MIOPENGEMM_FOUND TRUE)
message(STATUS "Found miopengemm: ${miopengemm_INCLUDE_DIR}")
include_directories(SYSTEM ${miopengemm_INCLUDE_DIR})
list(APPEND ANAKIN_LINKER_LIBS ${miopengemm_LIBRARIES})
endif()
endmacro()

20 changes: 13 additions & 7 deletions cmake/gather.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,14 @@ if(USE_BM_PLACE)
anakin_find_bmlib()
endif()

# set amd opencl path
if(AMD_GPU)
amd_build_cl_file("${CMAKE_SOURCE_DIR}/saber/funcs/impl/amd/cl" "${CMAKE_BINARY_DIR}/cl/amd")
amd_build_cl_binary_file("${CMAKE_SOURCE_DIR}/saber/funcs/impl/amd/lib" "${CMAKE_BINARY_DIR}/cl/amd")
amd_build_cl_file("${CMAKE_SOURCE_DIR}/saber/funcs/impl/amd/cl" "${PROJECT_SOURCE_DIR}/${AK_OUTPUT_PATH}/unit_test")
amd_build_cl_binary_file("${CMAKE_SOURCE_DIR}/saber/funcs/impl/amd/lib" "${PROJECT_SOURCE_DIR}/${AK_OUTPUT_PATH}/unit_test")
amd_build_cl_file("${CMAKE_SOURCE_DIR}/test/saber/amd" "${PROJECT_SOURCE_DIR}/${AK_OUTPUT_PATH}/unit_test")
# find openssl
if(USE_OPENSSL)
anakin_find_openssl()
endif()

# find openssl
if(USE_OPENSSL)
anakin_find_openssl()
endif()

# find opencl
Expand Down Expand Up @@ -105,3 +106,8 @@ endif()
if(USE_TENSORRT)
anakin_find_nvinfer()
endif()

# find miopengemm
if(USE_MIOPENGEMM)
anakin_find_miopengemm()
endif()
7 changes: 6 additions & 1 deletion saber/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,11 @@ if(USE_GPU_PLACE)
else()
anakin_fetch_files_with_suffix(${ANAKIN_SABER}/core/impl/amd "cpp" ANAKIN_SABER_BASE_SRC)
anakin_fetch_files_with_suffix(${ANAKIN_SABER}/funcs/impl/amd "cpp" ANAKIN_SABER_BASE_SRC)
anakin_fetch_files_with_suffix(${ANAKIN_SABER}/core/impl/amd/utils "cpp" ANAKIN_SABER_BASE_SRC)
if(USE_OPENCL)
anakin_fetch_files_with_suffix(${ANAKIN_SABER}/core/impl/amd/utils/ocl "cpp" ANAKIN_SABER_BASE_SRC)
endif()
generate_amd_kernel_src()
endif()
endif()

Expand Down Expand Up @@ -92,7 +97,7 @@ if(UNIX OR APPLE)
if (BUILD_SHARED)
ADD_LIBRARY(${ANAKIN_SABER_TEMP_COMMMON_LIB} SHARED ${ANAKIN_SABER_CUDA_C_SRC_OBJS} ${ANAKIN_SABER_BASE_SRC})
#$<TARGET_OBJECTS:ANAKIN_SABER_BASE_OBJS>)
if(USE_X86_PLACE OR USE_CUDA)
if(USE_X86_PLACE OR USE_CUDA OR AMD_GPU)
list(LENGTH ANAKIN_SABER_DEPENDENCIES dependencies_len)
if(dependencies_len GREATER 0)
add_dependencies(${ANAKIN_SABER_TEMP_COMMMON_LIB} ${ANAKIN_SABER_DEPENDENCIES})
Expand Down
2 changes: 1 addition & 1 deletion saber/core/device.h
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ struct Device<AMD> {

typedef TargetWrapper<AMD> API;

Device(int max_stream = 1);
Device(int max_stream = 4);

void get_info();
void create_stream();
Expand Down
49 changes: 0 additions & 49 deletions saber/core/env.h
Original file line number Diff line number Diff line change
Expand Up @@ -56,55 +56,6 @@ class Env {
Env(){}
};

#ifdef AMD_GPU
typedef std::list<cl_event> cl_event_list;

template <>
class Env<AMD> {
public:
typedef TargetWrapper<AMD> AMD_API;
typedef std::vector<Device<AMD>> Devs;
static Devs& cur_env() {
static Devs* _g_env = new Devs();
return *_g_env;
}

static void env_init(int max_stream = 4);
static bool is_init();
static cl_platform_id get_platform_id();

static void add_event(const char *tag, cl_event_list event);
static void add_event(cl_event_list event) {
add_event(mTag.c_str(), event);
}

static void pop();
static void set_tag(const char *tag){
mTag = std::string(tag);
}

static const std::string& get_tag(){
return mTag;
}

static void start_record(){
record = true;
}
static void stop_record(){
record = false;
}
private:
Env(){}

static cl_platform_id platform_id;
static std::map<std::string, std::list<cl_event_list>> eMap;
static std::list<std::string> tList;
static bool record;
static std::string mTag;

};
#endif

} //namespace saber

} //namespace anakin
Expand Down
Loading