Skip to content

Commit

Permalink
Compiler Updates - Set AMD clang++ as default compiler (#1454)
Browse files Browse the repository at this point in the history
* Compiler - Set AMD clang++ as default compiler for HIP

* C Compiler - Set AMD Clang

* AMD Custom - Cleanup

* Docs - added
  • Loading branch information
kiritigowda authored Nov 21, 2024
1 parent e580795 commit b774bdb
Show file tree
Hide file tree
Showing 15 changed files with 141 additions and 107 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ The full documentation for MIVisionX is available at [https://rocm.docs.amd.com/
### Changed

* Setup: OpenCV package install for Ubuntu
* AMD Clang is now the default CXX and C compiler.

### Known issues

Expand Down
28 changes: 16 additions & 12 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,21 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
cmake_minimum_required(VERSION 3.10)

# ROCM Path
if(DEFINED ENV{ROCM_PATH})
set(ROCM_PATH $ENV{ROCM_PATH} CACHE PATH "Default ROCm installation path")
elseif(ROCM_PATH)
message("-- INFO:ROCM_PATH Set -- ${ROCM_PATH}")
else()
set(ROCM_PATH /opt/rocm CACHE PATH "Default ROCm installation path")
endif()
# Set AMD Clang as default compiler
if (NOT DEFINED CMAKE_CXX_COMPILER AND EXISTS "${ROCM_PATH}/bin/amdclang++")
set(CMAKE_C_COMPILER ${ROCM_PATH}/bin/amdclang)
set(CMAKE_CXX_COMPILER ${ROCM_PATH}/bin/amdclang++)
endif()

set(VERSION "3.2.0")

# Set Project Version and Language
Expand All @@ -34,14 +49,6 @@ find_program(MAKE_NSIS_EXE makensis)
find_program(RPMBUILD_EXE rpmbuild)
find_program(DPKG_EXE dpkg)

# ROCM Path
if(DEFINED ENV{ROCM_PATH})
set(ROCM_PATH $ENV{ROCM_PATH} CACHE PATH "Default ROCm installation path")
elseif(ROCM_PATH)
message("-- INFO:ROCM_PATH Set -- ${ROCM_PATH}")
else()
set(ROCM_PATH /opt/rocm CACHE PATH "Default ROCm installation path")
endif()
# avoid setting the default installation path to /usr/local
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX ${ROCM_PATH} CACHE PATH "MIVisionX default installation path" FORCE)
Expand All @@ -53,7 +60,6 @@ option(NEURAL_NET "Build MIVisionX with Neural Net Support" ON)
option(LOOM "Build MIVisionX with LOOM Support" ON)
option(GPU_SUPPORT "Build MIVisionX with GPU Support" ON)
option(MIGRAPHX "Build MIVisionX with MIGraphX Support" ON)
option(BUILD_WITH_AMD_ADVANCE "Build MIVisionX for advanced AMD GPU Architecture" OFF)

if(WIN32)
set(BACKEND "OpenCL")
Expand Down Expand Up @@ -110,8 +116,7 @@ endif()
if(CMAKE_BUILD_TYPE MATCHES Debug)
# -O0 -- Don't Optimize output file
# -g -- generate debugging information
# -Og -- Optimize for debugging experience rather than speed or size
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g -Og")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -O0 -g")
else()
# -O3 -- Optimize output file
# -DNDEBUG -- turn off asserts
Expand Down Expand Up @@ -164,7 +169,6 @@ message("-- ${Cyan} -D LOOM=${LOOM} [Turn ON/OFF LOOM OpenCL Modules (defaul
message("-- ${Cyan} -D GPU_SUPPORT=${GPU_SUPPORT} [Turn ON/OFF GPU support (default:ON)]${ColourReset}")
message("-- ${Cyan} -D MIGRAPHX=${MIGRAPHX} [Turn ON/OFF MIGraphX Module (default:ON)]${ColourReset}")
message("-- ${Cyan} -D BACKEND=${BACKEND} [Select MIVisionX Backend [options:CPU/OPENCL/HIP](default:HIP)]${ColourReset}")
message("-- ${Cyan} -D BUILD_WITH_AMD_ADVANCE=${BUILD_WITH_AMD_ADVANCE} [Turn ON/OFF Build for AMD advanced GPUs(default:OFF)]${ColourReset}")

add_subdirectory(amd_openvx)
add_subdirectory(amd_openvx_extensions)
Expand Down
5 changes: 5 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ MIVisionX toolkit provides tools for accomplishing your tasks throughout the who
* macOS - Ventura `13` / Sonoma `14` / Sequoia `15`

### Libraries
* AMD Clang++ Version `18.0.0` or later - installed with ROCm
* CMake - Version `3.10` and above
```shell
sudo apt install cmake
Expand All @@ -108,6 +109,10 @@ MIVisionX toolkit provides tools for accomplishing your tasks throughout the who
```shell
sudo apt install libopencv-dev
```
* OpenMP
```
sudo apt install libomp-dev
```
* pkg-config
```shell
sudo apt install pkg-config
Expand Down
2 changes: 1 addition & 1 deletion amd_openvx/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,7 +183,7 @@ Build this project to generate AMD OpenVX™ library

### Build using CMake

* Install CMake 3.5 or later
* Install CMake 3.10 or later
* Use CMake to configure and generate Makefile

**NOTE:** OpenVX and the OpenVX logo are trademarks of the Khronos Group Inc.
2 changes: 0 additions & 2 deletions amd_openvx/openvx/hipvx/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,6 @@ list(APPEND HIPVX_SOURCES
set_source_files_properties(${HIPVX_SOURCES} PROPERTIES HIP_SOURCE_PROPERTY_FORMAT 1)

set(HIP_CXX_FLAGS -std=gnu++14)
set(COMPILER_FOR_HIP ${ROCM_PATH}/lib/llvm/bin/clang++)
set(CMAKE_CXX_COMPILER ${COMPILER_FOR_HIP})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${HIP_CXX_FLAGS}")

add_library(${PROJECT_NAME} OBJECT ${HIPVX_SOURCES})
Expand Down
86 changes: 41 additions & 45 deletions amd_openvx_extensions/amd_custom/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -19,76 +19,72 @@
# THE SOFTWARE.

cmake_minimum_required(VERSION 3.10)

set(VERSION "1.0.1")
project(vx_amd_custom VERSION ${VERSION} LANGUAGES CXX)

set(CMAKE_CXX_STANDARD 14)

list (APPEND CMAKE_PREFIX_PATH ${ROCM_PATH} ${ROCM_PATH}/hip)
# ROCM Path
if(DEFINED ENV{ROCM_PATH})
set(ROCM_PATH $ENV{ROCM_PATH} CACHE PATH "Default ROCm installation path")
elseif(ROCM_PATH)
message("-- ${PROJECT_NAME}: INFO -- ROCM_PATH Set -- ${ROCM_PATH}")
else()
set(ROCM_PATH /opt/rocm CACHE PATH "Default ROCm installation path")
endif()

# OpenMP
find_package(OpenMP QUIET)
list(APPEND CMAKE_PREFIX_PATH ${ROCM_PATH} ${ROCM_PATH}/hip)

if(GPU_SUPPORT AND "${BACKEND}" STREQUAL "HIP" AND OpenMP_FOUND)
# Find Packages
# HIP
if(GPU_SUPPORT AND "${BACKEND}" STREQUAL "HIP")
if(NOT DEFINED HIP_PATH)
if(NOT DEFINED ENV{HIP_PATH})
set(HIP_PATH ${ROCM_PATH})
set(HIP_PATH ${ROCM_PATH} CACHE PATH "Path to which HIP has been installed")
else()
set(HIP_PATH $ENV{HIP_PATH})
set(HIP_PATH $ENV{HIP_PATH} CACHE PATH "Path to which HIP has been installed")
endif()
endif()
list(APPEND CMAKE_PREFIX_PATH ${ROCM_PATH} ${ROCM_PATH}/hip)
find_package(HIP QUIET)
if(NOT HIP_FOUND)
message("-- ${Red}${PROJECT_NAME} WARNING: HIP Not Found${ColourReset}")
endif()
endif()
# OpenMP
find_package(OpenMP QUIET)
if(OpenMP_FOUND)
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} ${OpenMP_C_FLAGS}")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OpenMP_CXX_FLAGS}")
include_directories(${OpenMP_INCLUDE_DIRS})
set(LINK_LIBRARY_LIST ${LINK_LIBRARY_LIST} OpenMP::OpenMP_CXX)
message("-- ${White}${PROJECT_NAME} -- OpenMP Found${ColourReset}")
else()
message("-- ${Yellow}WARNING: ${PROJECT_NAME} -- OpenMP Not FOUND${ColourReset}")
endif()

if("${CMAKE_CXX_COMPILER_ID}" STREQUAL "MSVC")
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS_RELEASE} /MD")
set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS_DEBUG} /MDd")
else()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -fPIC -msse4.2")
endif()
list(APPEND SOURCES source/custom_kernels.cpp source/custom_layer.cpp)
include_directories(../../amd_openvx/openvx/include ${ROCM_PATH}/include include ./custom_lib)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -msse4.2")

if(HIP_FOUND AND OpenMP_FOUND)
message("-- ${Green}${PROJECT_NAME} -- Building HIP backend${ColourReset}")
set(ENABLE_HIP 1)
link_directories(${HIP_PATH}/lib)
list(APPEND PACKAGE_DEPENDS PACKAGE HIP)

include_directories(../../amd_openvx/openvx/include ${ROCM_PATH}/include include ./custom_lib)

list(APPEND SOURCES
source/custom_kernels.cpp
source/custom_layer.cpp
)

if (HIP_FOUND)
message("-- ${Green}${PROJECT_NAME} -- Building with HIP backend${ColourReset}")
set(ENABLE_HIP 1)
add_definitions(-DENABLE_HIP=${ENABLE_HIP} -D__HIP_PLATFORM_AMD__)
link_directories(${HIP_PATH}/lib)
add_subdirectory(custom_lib)
add_library(${PROJECT_NAME} SHARED ${SOURCES} $<TARGET_OBJECTS:custom_lib>)
target_link_libraries(${PROJECT_NAME} openvx hip::host ${LINK_LIBRARY_LIST})
set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR})
# install MIVisionX libs -- {ROCM_PATH}/lib -- TBD: Remove duplicate install
install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT runtime NAMELINK_SKIP)
install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT dev NAMELINK_ONLY)
install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT asan)
# install MIVisionX include files -- {ROCM_PATH}/include/mivisionx/
install(FILES include/vx_amd_custom.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mivisionx COMPONENT dev)
else()
message("-- ${Red}WARNING: HIP Not Found -- ${PROJECT_NAME} module excluded${ColourReset}")
endif()
else()
set(ENABLE_HIP 0)
add_definitions(-DENABLE_HIP=${ENABLE_HIP})
message("-- ${Red}WARNING: GPU Support Turned OFF -- ${PROJECT_NAME} built for CPU only${ColourReset}")
add_subdirectory(custom_lib)
add_library(${PROJECT_NAME} SHARED ${SOURCES} $<TARGET_OBJECTS:custom_lib>)
target_link_libraries(${PROJECT_NAME} openvx hip::host)
target_compile_definitions(${PROJECT_NAME} PRIVATE __HIP_PLATFORM_AMD__)
target_link_libraries(${PROJECT_NAME} openvx hip::host ${LINK_LIBRARY_LIST})
target_compile_definitions(${PROJECT_NAME} PUBLIC ENABLE_HIP=${ENABLE_HIP})
set_target_properties(${PROJECT_NAME} PROPERTIES VERSION ${PROJECT_VERSION} SOVERSION ${PROJECT_VERSION_MAJOR})
# install MIVisionX libs -- {ROCM_PATH}/lib
# install MIVisionX libs -- {ROCM_PATH}/lib -- TBD: Remove duplicate install
install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT runtime NAMELINK_SKIP)
install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT dev NAMELINK_ONLY)
install(TARGETS ${PROJECT_NAME} LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT asan)
# install include files -- {ROCM_PATH}/include/mivisionx/
# install MIVisionX include files -- {ROCM_PATH}/include/mivisionx/
install(FILES include/vx_amd_custom.h DESTINATION ${CMAKE_INSTALL_INCLUDEDIR}/mivisionx COMPONENT dev)
else()
message("-- ${Red}WARNING:${PROJECT_NAME} -- CPU backend not supported${ColourReset}")
endif()
52 changes: 10 additions & 42 deletions amd_openvx_extensions/amd_custom/custom_lib/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -23,50 +23,18 @@ project(custom_lib)

set(CMAKE_CXX_STANDARD 14)

# ROCm Path
set(ROCM_PATH /opt/rocm CACHE PATH "Default ROCm installation path")
# avoid setting the default installation path to /usr/local
if(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_PREFIX ${ROCM_PATH} CACHE PATH "MIVisionX default installation path" FORCE)
endif(CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT)
set(CMAKE_INSTALL_RPATH_USE_LINK_PATH TRUE)

# Add Default libdir
set(CMAKE_INSTALL_LIBDIR "lib" CACHE STRING "Library install directory")
include(GNUInstallDirs)

# Find Modules
list(APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/../../cmake)

if(GPU_SUPPORT AND "${BACKEND}" STREQUAL "HIP" AND OpenMP_FOUND)
set(CUSTOM_LIB_SOURCES custom_api.cpp custom_copy_impl.cpp)
include_directories(${ROCM_PATH}/include)
link_directories(${HIP_PATH}/lib)

set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++14")

if(NOT DEFINED ENV{HIP_PATH})
set(HIP_PATH ${ROCM_PATH} CACHE PATH "Path to which HIP has been installed")
else()
set(HIP_PATH $ENV{HIP_PATH} CACHE PATH "Path to which HIP has been installed")
endif()
list(APPEND CMAKE_PREFIX_PATH ${ROCM_PATH} ${ROCM_PATH}/hip)
find_package(HIP QUIET)
list(APPEND PACKAGE_DEPENDS PACKAGE HIP)
include_directories(${ROCM_PATH}/include)
set(CUSTOM_LIB_SOURCES
custom_api.cpp
custom_copy_impl.cpp
)
add_library(${PROJECT_NAME} OBJECT ${CUSTOM_LIB_SOURCES})
target_compile_definitions(${PROJECT_NAME} PUBLIC ENABLE_HIP=${ENABLE_HIP})
target_compile_definitions(${PROJECT_NAME} PRIVATE __HIP_PLATFORM_AMD__)

if (HIP_FOUND)
set(ENABLE_HIP 1)
add_definitions(-DENABLE_HIP=${ENABLE_HIP} -D__HIP_PLATFORM_AMD__)
link_directories(${HIP_PATH}/lib)
add_library(${PROJECT_NAME} OBJECT ${CUSTOM_LIB_SOURCES})
else()
message("-- ${Red}WARNING: HIP Not Found -- ${PROJECT_NAME} not built${ColourReset}")
endif()
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -std=gnu++14")
else()
message("-- ${Green}${PROJECT_NAME} -- Building for CPU backend${ColourReset}")
set(ENABLE_HIP 0)
add_library(${PROJECT_NAME} OBJECT ${CUSTOM_LIB_SOURCES})
endif()
list(APPEND PACKAGE_DEPENDS PACKAGE HIP)

message("-- ${White}custom_lib -- CMAKE_CXX_FLAGS:${CMAKE_CXX_FLAGS}${ColourReset}")
message("-- ${White}${PROJECT_NAME} -- CMAKE_CXX_FLAGS:${CMAKE_CXX_FLAGS}${ColourReset}")
2 changes: 0 additions & 2 deletions amd_openvx_extensions/amd_nn/nn_hip/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,6 @@ set(NN_HIP_SOURCES

set_source_files_properties(${NN_HIP_SOURCES} PROPERTIES HIP_SOURCE_PROPERTY_FORMAT 1)
set(HIP_CXX_FLAGS -std=gnu++14)
set(COMPILER_FOR_HIP ${ROCM_PATH}/lib/llvm/bin/clang++)
set(CMAKE_CXX_COMPILER ${COMPILER_FOR_HIP})
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${HIP_CXX_FLAGS}")

add_library(${PROJECT_NAME} OBJECT ${NN_HIP_SOURCES})
Expand Down
2 changes: 1 addition & 1 deletion amd_openvx_extensions/amd_rpp/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ The following is a list of RPP functions that have been included in the vx_rpp m

* AMD OpenVX&trade; library
* [AMD RPP library](https://github.com/ROCm/rpp)
* CMake 3.5 or later
* CMake 3.10 or later
* OpenCL (optional)

### Build using CMake on Linux
Expand Down
2 changes: 1 addition & 1 deletion docs/install/amd_openvx-install.rst
Original file line number Diff line number Diff line change
Expand Up @@ -42,5 +42,5 @@ Build using Microsoft Visual Studio
Build using CMake
-----------------

* Install CMake 3.5 or later
* Install CMake 3.10 or later
* Use CMake to configure and generate Makefile
14 changes: 13 additions & 1 deletion docs/install/installation.rst
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ Hardware
.. note::
Some modules in MIVisionX can be built for CPU only. To take advantage of advanced features and modules we recommend using AMD GPUs or APUs.

Operating System
Operating Systems
------------------

* Linux
Expand All @@ -37,6 +37,18 @@ Operating System
* Windows 10 or 11
* macOS Ventura 13 or Sonoma 14

Libraries
------------------
* AMD Clang++
* CMake - Version 3.10 and above
* Half-precision floating-point(half) library - Version `1.12.0`
* MIOpen
* MIGraphX
* RPP
* OpenCV - Version 3.X or 4.X
* OpenMP
* pkg-config
* FFmpeg - Version 4.X

Linux installation
===========================
Expand Down
13 changes: 13 additions & 0 deletions model_compiler/python/nnir_to_zendnn.py
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,19 @@ def generateCMakeFiles(graph,outputFolder):
"""
cmake_minimum_required(VERSION 3.10)
# ROCM Path
if(DEFINED ENV{ROCM_PATH})
set(ROCM_PATH $ENV{ROCM_PATH} CACHE PATH "Default ROCm installation path")
elseif(ROCM_PATH)
message("-- INFO:ROCM_PATH Set -- ${ROCM_PATH}")
else()
set(ROCM_PATH /opt/rocm CACHE PATH "Default ROCm installation path")
endif()
# Set AMD Clang as default compiler
if (NOT DEFINED CMAKE_CXX_COMPILER AND EXISTS "${ROCM_PATH}/bin/amdclang++")
set(CMAKE_CXX_COMPILER ${ROCM_PATH}/bin/amdclang++)
endif()
# Set Default Compiler & Standard
# aocc-linux-compiler -- ENV:ZENDNN_AOCC_COMP_PATH
if(NOT DEFINED ZENDNN_AOCC_COMP_PATH)
Expand Down
13 changes: 13 additions & 0 deletions tests/zen_dnn_tests/conv/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,19 @@
#
################################################################################
cmake_minimum_required(VERSION 3.10)
# ROCM Path
if(DEFINED ENV{ROCM_PATH})
set(ROCM_PATH $ENV{ROCM_PATH} CACHE PATH "Default ROCm installation path")
elseif(ROCM_PATH)
message("-- INFO:ROCM_PATH Set -- ${ROCM_PATH}")
else()
set(ROCM_PATH /opt/rocm CACHE PATH "Default ROCm installation path")
endif()
# Set AMD Clang as default compiler
if (NOT DEFINED CMAKE_CXX_COMPILER AND EXISTS "${ROCM_PATH}/bin/amdclang++")
set(CMAKE_CXX_COMPILER ${ROCM_PATH}/bin/amdclang++)
endif()

# Set Default Compiler & Standard
# aocc-linux-compiler -- ENV:ZENDNN_AOCC_COMP_PATH
if(NOT DEFINED ZENDNN_AOCC_COMP_PATH)
Expand Down
13 changes: 13 additions & 0 deletions tests/zen_dnn_tests/mnist/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,19 @@
################################################################################
cmake_minimum_required(VERSION 3.10)

# ROCM Path
if(DEFINED ENV{ROCM_PATH})
set(ROCM_PATH $ENV{ROCM_PATH} CACHE PATH "Default ROCm installation path")
elseif(ROCM_PATH)
message("-- INFO:ROCM_PATH Set -- ${ROCM_PATH}")
else()
set(ROCM_PATH /opt/rocm CACHE PATH "Default ROCm installation path")
endif()
# Set AMD Clang as default compiler
if (NOT DEFINED CMAKE_CXX_COMPILER AND EXISTS "${ROCM_PATH}/bin/amdclang++")
set(CMAKE_CXX_COMPILER ${ROCM_PATH}/bin/amdclang++)
endif()

# Set Default Compiler & Standard
# aocc-linux-compiler -- ENV:ZENDNN_AOCC_COMP_PATH
if(NOT DEFINED ZENDNN_AOCC_COMP_PATH)
Expand Down
Loading

0 comments on commit b774bdb

Please sign in to comment.