Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[cmake][rocRAND] Updated toolchain-linux.cmake to have proper CMAKE_PREFIX_PATH definitions #587

Open
wants to merge 15 commits into
base: develop
Choose a base branch
from
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
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,15 @@ Documentation for rocRAND is available at

### Changed

* Removed a section in `cmake/Dependencies.cmake` that was forcing `DCMAKE_CXX_COMPILER` to be set to either `cl` or `g++` if the compiler was not `GNU`.
* `--test|-t` is no longer a required flag for `rtest.py`. Instead, the user can use either `--emulation|-e` or `--test|-t`, but not both.
* Removed TBB dependency for multi-core processing of host-side generation.

## Resolved issues

* Fixed an issue where `CMAKE_PREFIX_PATH` was not defined properly in `CMAKELists.txt` and `toolchain-linux.cmake`.
* Fixed an issue in `rmake.py` where `cmake_platform_opts` was sometimes a string instead of a list.

## rocRAND 3.2.0 for ROCm 6.3.0

### Added
Expand Down
58 changes: 34 additions & 24 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
# SOFTWARE.

cmake_minimum_required(VERSION 3.16 FATAL_ERROR)
cmake_policy(VERSION 3.16...3.25)

# Build options
include(CMakeDependentOption)
Expand All @@ -29,22 +30,48 @@ option(BUILD_FORTRAN_WRAPPER "Build Fortran wrapper" OFF)
option(BUILD_TEST "Build tests (requires googletest)" OFF)
option(BUILD_BENCHMARK "Build benchmarks" OFF)
cmake_dependent_option(BUILD_BENCHMARK_TUNING
"Build extra benchmarks for kernel configuration tuning" OFF "BUILD_BENCHMARK" OFF)
"Build extra benchmarks for kernel configuration tuning" OFF "BUILD_BENCHMARK" OFF)
option(BUILD_ADDRESS_SANITIZER "Build with address sanitizer enabled" OFF)
option(CODE_COVERAGE "Build with code coverage flags (clang only)" OFF)
option(DEPENDENCIES_FORCE_DOWNLOAD "Don't search the system for dependencies, always download them" OFF)
cmake_dependent_option(RUN_SLOW_TESTS "Run extra tests with CTest. These cover niche functionality and take long time" OFF "BUILD_TEST" OFF)


if (NOT DEFINED ENV{ROCM_PATH})
#Path to ROCm installation
set(ENV{ROCM_PATH} "/opt/rocm")
endif()

# Install prefix
set(CMAKE_INSTALL_PREFIX "/opt/rocm" CACHE PATH "Install path prefix, prepended onto install directories")
set(CMAKE_INSTALL_PREFIX "$ENV{ROCM_PATH}" CACHE PATH "Install path prefix, prepended onto install directories")

if(WIN32)
set(CPACK_SOURCE_GENERATOR "ZIP")
set(CPACK_GENERATOR "ZIP")
set(CMAKE_INSTALL_PREFIX "C:/hipSDK" CACHE PATH "Install path")
set(INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
set(CPACK_SET_DESTDIR OFF)
set(CPACK_PACKAGE_INSTALL_DIRECTORY "${CMAKE_INSTALL_PREFIX}")
set(CPACK_PACKAGING_INSTALL_PREFIX "")
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF)
else()
set(CMAKE_INSTALL_PREFIX "$ENV{ROCM_PATH}" CACHE PATH "Install path prefix, prepended onto install directories")
#Adding CMAKE_PREFIX_PATH
if(NOT DEFINED CMAKE_PREFIX_PATH)
list( APPEND CMAKE_PREFIX_PATH $ENV{ROCM_PATH}/llvm $ENV{ROCM_PATH})
endif()
if(NOT CPACK_PACKAGING_INSTALL_PREFIX)
set(CPACK_PACKAGING_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
endif()
endif()

# CMake modules
list(APPEND CMAKE_MODULE_PATH
${CMAKE_CURRENT_SOURCE_DIR}/cmake
${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules
$ENV{ROCM_PATH}/lib/cmake/hip
${HIP_PATH}/cmake $ENV{ROCM_PATH}/hip/cmake # FindHIP.cmake
$ENV{ROCM_PATH}/llvm
${CMAKE_CURRENT_SOURCE_DIR}/cmake
${CMAKE_CURRENT_SOURCE_DIR}/cmake/Modules
$ENV{ROCM_PATH}/lib/cmake/hip
${HIP_PATH}/cmake $ENV{ROCM_PATH}/hip/cmake # FindHIP.cmake
$ENV{ROCM_PATH}/llvm
)

#
Expand Down Expand Up @@ -192,23 +219,6 @@ endif()
# Package (make package)
set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.txt")
set(CPACK_RPM_PACKAGE_LICENSE "MIT")
if(WIN32)
set(CPACK_SOURCE_GENERATOR "ZIP")
set(CPACK_GENERATOR "ZIP")
set(CMAKE_INSTALL_PREFIX "C:/hipSDK" CACHE PATH "Install path")
set(INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
set(CPACK_SET_DESTDIR OFF)
set(CPACK_PACKAGE_INSTALL_DIRECTORY "${CMAKE_INSTALL_PREFIX}")
set(CPACK_PACKAGING_INSTALL_PREFIX "")
set(CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF)
else()
set(CMAKE_INSTALL_PREFIX "$ENV{ROCM_PATH}" CACHE PATH "Install path prefix, prepended onto install directories")
#Adding CMAKE_PREFIX_PATH
list( APPEND CMAKE_PREFIX_PATH $ENV{ROCM_PATH}/llvm $ENV{ROCM_PATH} )
if(NOT CPACK_PACKAGING_INSTALL_PREFIX)
set(CPACK_PACKAGING_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}")
endif()
endif()

if( HIP_RUNTIME_LOWER STREQUAL "rocclr" )
if(BUILD_ADDRESS_SANITIZER)
Expand Down
15 changes: 0 additions & 15 deletions benchmark/custom_csv_formater.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -152,20 +152,13 @@ inline void customCSVReporter::ReportRuns(const std::vector<Run>& reports)
inline void customCSVReporter::PrintRunData(const Run& run)
{
std::ostream& Out = GetOutputStream();
std::ostream& Err = GetErrorStream();

//get the name of the engine and distribution:

std::string temp = run.benchmark_name();

std::string deviceName = std::string(temp.begin(), temp.begin() + temp.find("<"));

temp.erase(0, temp.find("<") + 1);

std::string engineName = std::string(temp.begin(), temp.begin() + temp.find(","));

temp.erase(0, engineName.size() + 1);

std::string mode = "default";

if(deviceName != "device_kernel")
Expand All @@ -174,7 +167,6 @@ inline void customCSVReporter::PrintRunData(const Run& run)
temp.erase(0, temp.find(",") + 1);
}
std::string disName = std::string(temp.begin(), temp.begin() + temp.find(">"));

std::string lambda = "";

size_t ePos = disName.find("=");
Expand All @@ -186,13 +178,6 @@ inline void customCSVReporter::PrintRunData(const Run& run)

Out << engineName << "," << disName << "," << mode << ",";
Out << CsvEscape(run.benchmark_name()) << ",";
if(run.error_occurred)
{
Err << std::string(elements.size() - 3, ',');
Err << "true,";
Err << CsvEscape(run.error_message) << "\n";
return;
}

// Do not print iteration on bigO and RMS report
if(!run.report_big_o && !run.report_rms)
Expand Down
16 changes: 5 additions & 11 deletions cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,6 @@ if(BUILD_TEST)
endif()
endif()


# Benchmark dependencies
if(BUILD_BENCHMARK)
if(NOT DEPENDENCIES_FORCE_DOWNLOAD)
Expand All @@ -94,19 +93,12 @@ if(BUILD_BENCHMARK)
message(FATAL_ERROR "DownloadProject.cmake doesn't support multi-configuration generators.")
endif()
set(GOOGLEBENCHMARK_ROOT ${CMAKE_CURRENT_BINARY_DIR}/deps/googlebenchmark CACHE PATH "")
if(NOT (CMAKE_CXX_COMPILER_ID STREQUAL "GNU"))
# hip-clang cannot compile googlebenchmark for some reason
if(WIN32)
set(COMPILER_OVERRIDE "-DCMAKE_CXX_COMPILER=cl")
else()
set(COMPILER_OVERRIDE "-DCMAKE_CXX_COMPILER=g++")
endif()
endif()

option(BENCHMARK_ENABLE_TESTING "Enable testing of the benchmark library." OFF)
option(BENCHMARK_ENABLE_INSTALL "Enable installation of benchmark." OFF)
download_project(
PROJ googlebenchmark
GIT_REPOSITORY https://github.com/google/benchmark.git
GIT_TAG v1.6.1
GIT_TAG v1.8.0
INSTALL_DIR ${GOOGLEBENCHMARK_ROOT}
CMAKE_ARGS -DCMAKE_BUILD_TYPE=${CMAKE_BUILD_TYPE} -DBUILD_SHARED_LIBS=OFF -DBENCHMARK_ENABLE_TESTING=OFF -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR> -DCMAKE_CXX_STANDARD=14 ${COMPILER_OVERRIDE}
LOG_DOWNLOAD TRUE
Expand All @@ -116,6 +108,8 @@ if(BUILD_BENCHMARK)
BUILD_PROJECT TRUE
UPDATE_DISCONNECTED TRUE
)
set(HAVE_STD_REGEX ON)
set(RUN_HAVE_STD_REGEX 1)
endif()
find_package(benchmark REQUIRED CONFIG PATHS ${GOOGLEBENCHMARK_ROOT} NO_DEFAULT_PATH)
endif()
Expand Down
10 changes: 6 additions & 4 deletions rmake.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
import ctypes
import pathlib
from fnmatch import fnmatchcase
import shutil

args = {}
param = {}
Expand Down Expand Up @@ -109,10 +110,11 @@ def config_cmd():
cmake_options.append( generator )
else:
rocm_path = os.getenv( 'ROCM_PATH', "/opt/rocm")
if (OS_info["ID"] in ['centos', 'rhel']):
cmake_executable = "cmake3"
else:
cmake_executable = "cmake"

cmake_executable = 'cmake'
if shutil.which('cmake3') is not None:
cmake_executable = 'cmake3'

toolchain = "toolchain-linux.cmake"
cmake_platform_opts = [f"-DROCM_DIR:PATH={rocm_path}", f"-DCPACK_PACKAGING_INSTALL_PREFIX={rocm_path}"]

Expand Down
16 changes: 11 additions & 5 deletions toolchain-linux.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,18 @@
#set(CMAKE_GENERATOR "Ninja")
# Ninja doesn't support platform
#set(CMAKE_GENERATOR_PLATFORM x64)
if (NOT python)
set(python "python3") # default for linux
endif()

if (DEFINED ENV{ROCM_PATH})
set(rocm_bin "$ENV{ROCM_PATH}/bin")
else()
set(ROCM_PATH "/opt/rocm" CACHE PATH "Path to the ROCm installation.")
set(rocm_bin "/opt/rocm/bin")

if (NOT DEFINED ENV{ROCM_PATH})
set(ENV{ROCM_PATH} "/opt/rocm" CACHE PATH "Path to the ROCm installation.")
endif()

set(rocm_bin "$ENV{ROCM_PATH}/bin")
if (NOT DEFINED CMAKE_PREFIX_PATH)
list( APPEND CMAKE_PREFIX_PATH $ENV{ROCM_PATH}/llvm $ENV{ROCM_PATH})
endif()

if (NOT DEFINED ENV{CXX})
Expand Down