Skip to content

Commit

Permalink
HIP SDK spaces support, plus previous benchmark fixes (#225) (#226)
Browse files Browse the repository at this point in the history
* HIP SDK spaces support, plus previous benchmark fixes

* Better fix for Windows

* Update cmake_path function for rmake.py

* Update copyright
  • Loading branch information
stanleytsang-amd authored Jan 9, 2023
1 parent ce87098 commit 9c22ca3
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 11 deletions.
11 changes: 6 additions & 5 deletions benchmark/benchmark_utils.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,16 +43,17 @@

namespace benchmark_utils
{

const size_t default_max_random_size = 1024 * 1024;
// get_random_data() generates only part of sequence and replicates it,
// because benchmarks usually do not need "true" random sequence.
template<class T>
inline auto get_random_data(size_t size, T min, T max, size_t max_random_size = 1024 * 1024)
inline auto get_random_data(size_t size, T min, T max, size_t max_random_size = default_max_random_size)
-> typename std::enable_if<std::is_integral<T>::value, std::vector<T>>::type
{
std::random_device rd;
std::default_random_engine gen(rd());
std::uniform_int_distribution<T> distribution(min, max);
using distribution_type = typename std::conditional<(sizeof(T)==1), short, T>::type;
std::uniform_int_distribution<distribution_type> distribution(min, max);
std::vector<T> data(size);
std::generate(
data.begin(), data.begin() + std::min(size, max_random_size),
Expand All @@ -66,7 +67,7 @@ inline auto get_random_data(size_t size, T min, T max, size_t max_random_size =
}

template<class T>
inline auto get_random_data(size_t size, T min, T max, size_t max_random_size = 1024 * 1024)
inline auto get_random_data(size_t size, T min, T max, size_t max_random_size = default_max_random_size)
-> typename std::enable_if<std::is_floating_point<T>::value, std::vector<T>>::type
{
std::random_device rd;
Expand All @@ -85,7 +86,7 @@ inline auto get_random_data(size_t size, T min, T max, size_t max_random_size =
}

template<class T>
inline std::vector<T> get_random_data01(size_t size, float p, size_t max_random_size = 1024 * 1024)
inline std::vector<T> get_random_data01(size_t size, float p, size_t max_random_size = default_max_random_size)
{
std::random_device rd;
std::default_random_engine gen(rd());
Expand Down
7 changes: 7 additions & 0 deletions benchmark/cmdparser.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,13 @@ namespace cli {
return std::stoul(elements[0]);
}

static unsigned long long parse(const std::vector<std::string>& elements, const unsigned long long&) {
if (elements.size() != 1)
throw std::bad_cast();

return std::stoull(elements[0]);
}

static long parse(const std::vector<std::string>& elements, const long&) {
if (elements.size() != 1)
throw std::bad_cast();
Expand Down
1 change: 1 addition & 0 deletions benchmark/common_benchmark_header.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
#include <limits>
#include <cmath>
#include <cstdlib>
#include <numeric>

// Google Benchmark
#include "benchmark/benchmark.h"
Expand Down
8 changes: 6 additions & 2 deletions cmake/Dependencies.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -161,7 +161,11 @@ if(BUILD_BENCHMARK)
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
set(COMPILER_OVERRIDE "-DCMAKE_CXX_COMPILER=g++")
if(WIN32)
set(COMPILER_OVERRIDE "-DCMAKE_CXX_COMPILER=cl")
else()
set(COMPILER_OVERRIDE "-DCMAKE_CXX_COMPILER=g++")
endif()
endif()

download_project(
Expand All @@ -170,7 +174,7 @@ if(BUILD_BENCHMARK)
GIT_TAG v1.6.1
GIT_SHALLOW TRUE
INSTALL_DIR ${GOOGLEBENCHMARK_ROOT}
CMAKE_ARGS -DCMAKE_BUILD_TYPE=RELEASE -DBENCHMARK_ENABLE_TESTING=OFF -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR> ${COMPILER_OVERRIDE}
CMAKE_ARGS -DCMAKE_BUILD_TYPE=RELEASE -DBENCHMARK_ENABLE_TESTING=OFF -DBUILD_SHARED_LIBS=ON -DCMAKE_INSTALL_PREFIX=<INSTALL_DIR> -DCMAKE_CXX_STANDARD=14 ${COMPILER_OVERRIDE}
LOG_DOWNLOAD TRUE
LOG_CONFIGURE TRUE
LOG_BUILD TRUE
Expand Down
14 changes: 11 additions & 3 deletions rmake.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#!/usr/bin/python3
"""Copyright 2020-2021 Advanced Micro Devices, Inc.
"""Copyright 2020-2023 Advanced Micro Devices, Inc.
Manage build and installation"""

import re
Expand Down Expand Up @@ -72,6 +72,12 @@ def delete_dir(dir_path) :
linux_path = pathlib.Path(dir_path).absolute()
#print( linux_path )
run_cmd( "rm" , f"-rf {linux_path}")

def cmake_path(os_path):
if OS_info["ID"] == "windows":
return os_path.replace("\\", "/")
else:
return os.path.realpath(os_path)

def config_cmd():
global args
Expand All @@ -85,7 +91,9 @@ def config_cmd():
cmake_platform_opts = []
if (OS_info["ID"] == 'windows'):
# we don't have ROCM on windows but have hip, ROCM can be downloaded if required
rocm_path = os.getenv( 'ROCM_PATH', "C:/hipsdk/rocm-cmake-master") #C:/hip") # rocm/Utils/cmake-rocm4.2.0"
# CMAKE_PREFIX_PATH set to rocm_path and HIP_PATH set BY SDK Installer
raw_rocm_path = cmake_path(os.getenv('HIP_PATH', "C:/hip"))
rocm_path = f'"{raw_rocm_path}"' # guard against spaces in path
cmake_executable = "cmake.exe"
toolchain = os.path.join( src_path, "toolchain-windows.cmake" )
#set CPACK_PACKAGING_INSTALL_PREFIX= defined as blank as it is appended to end of path for archive creation
Expand Down Expand Up @@ -143,7 +151,7 @@ def config_cmd():
cmake_options.append( f"-DROCM_DISABLE_LDCONFIG=ON" )

if args.build_clients:
cmake_options.append( f"-DBUILD_TEST=ON -DBUILD_DIR={build_dir}" )
cmake_options.append( f"-DBUILD_TEST=ON -DBUILD_BENCHMARK=ON -DBUILD_DIR={build_dir}" )

cmake_options.append( f"-DAMDGPU_TARGETS={args.gpu_architecture}" )

Expand Down
5 changes: 4 additions & 1 deletion toolchain-windows.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,10 @@
# Ninja doesn't support platform
#set(CMAKE_GENERATOR_PLATFORM x64)

if (DEFINED ENV{HIP_DIR})
if (DEFINED ENV{HIP_PATH})
file(TO_CMAKE_PATH "$ENV{HIP_PATH}" HIP_DIR)
set(rocm_bin "${HIP_DIR}/bin")
elseif (DEFINED ENV{HIP_DIR})
file(TO_CMAKE_PATH "$ENV{HIP_DIR}" HIP_DIR)
set(rocm_bin "${HIP_DIR}/bin")
else()
Expand Down

0 comments on commit 9c22ca3

Please sign in to comment.