pax_global_header00006660000000000000000000000064147172537550014532gustar00rootroot0000000000000052 comment=7c1566ba4628e777b91511242899b6df48555d04 hipBLAS-common-rocm-6.4.0/000077500000000000000000000000001471725375500152075ustar00rootroot00000000000000hipBLAS-common-rocm-6.4.0/.azuredevops/000077500000000000000000000000001471725375500176345ustar00rootroot00000000000000hipBLAS-common-rocm-6.4.0/.azuredevops/rocm-ci.yml000066400000000000000000000010301471725375500217020ustar00rootroot00000000000000resources: repositories: - repository: pipelines_repo type: github endpoint: ROCm name: ROCm/ROCm variables: - group: common - template: /.azuredevops/variables-global.yml@pipelines_repo trigger: batch: true branches: include: - develop - mainline paths: exclude: - '*.md' pr: autoCancel: true branches: include: - develop - mainline paths: exclude: - '*.md' drafts: false jobs: - template: ${{ variables.CI_COMPONENT_PATH }}/hipBLAS-common.yml@pipelines_repo hipBLAS-common-rocm-6.4.0/CMakeLists.txt000066400000000000000000000104311471725375500177460ustar00rootroot00000000000000# ######################################################################## # Copyright (C) 2016-2024 Advanced Micro Devices, Inc. All rights reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell cop- # ies of the Software, and to permit persons to whom the Software is furnished # to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IM- # PLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNE- # CTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # ######################################################################## cmake_minimum_required( VERSION 3.11 ) # Build documentation option(BUILD_DOCS "Build documentation" OFF) # Consider removing this in the future # This should appear before the project command, because it does not use FORCE if( WIN32 ) set( CMAKE_INSTALL_PREFIX "${PROJECT_BINARY_DIR}/package" CACHE PATH "Install path prefix, prepended onto install directories" ) else( ) set( CMAKE_INSTALL_PREFIX "/opt/rocm" CACHE PATH "Install path prefix, prepended onto install directories" ) endif( ) # This has to be initialized before the project() command appears # Set the default of CMAKE_BUILD_TYPE to be release, unless user specifies with -D. MSVC_IDE does not use CMAKE_BUILD_TYPE if( NOT DEFINED CMAKE_CONFIGURATION_TYPES AND NOT DEFINED CMAKE_BUILD_TYPE ) set( CMAKE_BUILD_TYPE Release CACHE STRING "Choose the type of build, options are: None Debug Release RelWithDebInfo MinSizeRel." ) endif() project( hipblas-common LANGUAGES CXX ) # Append our library helper cmake path and the cmake path for hip (for convenience) # Users may override HIP path by specifying their own in CMAKE_MODULE_PATH list( APPEND CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/cmake ${ROCM_PATH}/lib/cmake/hip /opt/rocm/lib/cmake/hip ${HIP_DIR}/cmake ) # NOTE: workaround until hip cmake modules fixes symlink logic in their config files; remove when fixed list( APPEND CMAKE_PREFIX_PATH ${ROCM_PATH}/lib/cmake/hip /opt/rocm /opt/rocm/llvm /opt/rocm/hip ) # This finds the rocm-cmake project, and installs it if not found # rocm-cmake contains common cmake code for rocm projects to help setup and install include(dependencies) set ( VERSION_STRING "1.0.0" ) rocm_setup_version( VERSION ${VERSION_STRING} ) option( BUILD_VERBOSE "Output additional build information" OFF ) add_subdirectory( library ) # Build docs if(BUILD_DOCS) add_subdirectory(docs) endif() # The following code is setting variables to control the behavior of CPack to generate our if( WIN32 ) set( CPACK_SOURCE_GENERATOR "ZIP" ) set( CPACK_GENERATOR "ZIP" ) endif( ) set( CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.md" ) set( CPACK_RPM_PACKAGE_LICENSE "MIT") if (WIN32) SET( CMAKE_INSTALL_PREFIX "C:/hipSDK" CACHE PATH "Install path" FORCE ) SET( INSTALL_PREFIX "C:/hipSDK" ) SET( CPACK_SET_DESTDIR FALSE ) SET( CPACK_PACKAGE_INSTALL_DIRECTORY "C:/hipSDK" ) SET( CPACK_PACKAGING_INSTALL_PREFIX "" ) set( CPACK_INCLUDE_TOPLEVEL_DIRECTORY OFF ) else() if( NOT CPACK_PACKAGING_INSTALL_PREFIX ) set( CPACK_PACKAGING_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" ) endif() endif( ) set( CPACK_RPM_EXCLUDE_FROM_AUTO_FILELIST_ADDITION "\${CPACK_PACKAGING_INSTALL_PREFIX}" ) set( package_name hipblas-common ) set( HIPBLAS_CONFIG_DIR "\${CPACK_PACKAGING_INSTALL_PREFIX}/${CMAKE_INSTALL_LIBDIR}" CACHE PATH "Path placed into ldconfig file" ) rocm_create_package( NAME ${package_name} DESCRIPTION "Common files for hipBLAS libraries" MAINTAINER "hipBLAS Maintainer " LDCONFIG LDCONFIG_DIR ${HIPBLAS_CONFIG_DIR} HEADER_ONLY ) hipBLAS-common-rocm-6.4.0/LICENSE.md000066400000000000000000000020651471725375500166160ustar00rootroot00000000000000MIT License Copyright (c) 2024 AMD ROCmâ„¢ Software Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. hipBLAS-common-rocm-6.4.0/README.md000066400000000000000000000004751471725375500164740ustar00rootroot00000000000000# hipBLAS-common Common files shared by hipBLAS and hipBLASLt ## Build Instructions There are 2 ways to build the hipblas-common package: ### rmake script Simply run the rmake script: `python3 ./rmake.py --install` ### Calling cmake and make directly ``` mkdir build cd build cmake .. make package install ``` hipBLAS-common-rocm-6.4.0/cmake/000077500000000000000000000000001471725375500162675ustar00rootroot00000000000000hipBLAS-common-rocm-6.4.0/cmake/dependencies.cmake000066400000000000000000000043271471725375500217250ustar00rootroot00000000000000# MIT License # # Copyright (C) 2023-2024 Advanced Micro Devices, Inc. All rights reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell # copies of the Software, and to permit persons to whom the Software is # furnished to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE # SOFTWARE. # ########################### # ROCm dependencies # ########################### include(FetchContent) find_package(ROCM 0.11.0 CONFIG QUIET PATHS "${ROCM_PATH}") # First version with Sphinx doc gen improvement if(NOT ROCM_FOUND) message(STATUS "ROCm CMake not found. Fetching...") set(rocm_cmake_tag "c044bb52ba85058d28afe2313be98d9fed02e293" # develop@2023.09.12. (move to 6.0 tag when released) CACHE STRING "rocm-cmake tag to download") FetchContent_Declare( rocm-cmake GIT_REPOSITORY https://github.com/ROCm/rocm-cmake.git GIT_TAG ${rocm_cmake_tag} SOURCE_SUBDIR "DISABLE ADDING TO BUILD" # We don't really want to consume the build and test targets of ROCm CMake. ) FetchContent_MakeAvailable(rocm-cmake) find_package(ROCM CONFIG REQUIRED NO_DEFAULT_PATH PATHS "${rocm-cmake_SOURCE_DIR}") else() find_package(ROCM 0.11.0 CONFIG REQUIRED PATHS "${ROCM_PATH}") endif() include(ROCMSetupVersion) include(ROCMCreatePackage) include(ROCMInstallTargets) include(ROCMPackageConfigHelpers) include(ROCMInstallSymlinks) include(ROCMClients) include(ROCMHeaderWrapper) hipBLAS-common-rocm-6.4.0/cmake/get-cli-arguments.cmake000066400000000000000000000020001471725375500226100ustar00rootroot00000000000000# Attempt (best effort) to return a list of user specified parameters cmake was invoked with # NOTE: Even if the user specifies CMAKE_INSTALL_PREFIX on the command line, the parameter is # not returned because it does not have the matching helpstring function( append_cmake_cli_arguments initial_cli_args return_cli_args ) # Retrieves the contents of CMakeCache.txt get_cmake_property( cmake_properties CACHE_VARIABLES ) foreach( property ${cmake_properties} ) get_property(help_string CACHE ${property} PROPERTY HELPSTRING ) # Properties specified on the command line have boilerplate text if( help_string MATCHES "variable specified on the command line" ) # message( STATUS "property: ${property}") # message( STATUS "value: ${${property}}") list( APPEND cli_args "-D${property}=${${property}}") endif( ) endforeach( ) # message( STATUS "get_command_line_arguments: ${cli_args}") set( ${return_cli_args} ${${initial_cli_args}} ${cli_args} PARENT_SCOPE ) endfunction( ) hipBLAS-common-rocm-6.4.0/library/000077500000000000000000000000001471725375500166535ustar00rootroot00000000000000hipBLAS-common-rocm-6.4.0/library/CMakeLists.txt000066400000000000000000000062431471725375500214200ustar00rootroot00000000000000# ######################################################################## # Copyright (C) 2016-2024 Advanced Micro Devices, Inc. All rights reserved. # # Permission is hereby granted, free of charge, to any person obtaining a copy # of this software and associated documentation files (the "Software"), to deal # in the Software without restriction, including without limitation the rights # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell cop- # ies of the Software, and to permit persons to whom the Software is furnished # to do so, subject to the following conditions: # # The above copyright notice and this permission notice shall be included in all # copies or substantial portions of the Software. # # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IM- # PLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS # FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR # COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER # IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNE- # CTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. # ######################################################################## list( APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake ) # This option only works for make/nmake and the ninja generators, but no reason it shouldn't be on all the time # This tells cmake to create a compile_commands.json file that can be used with clang tooling or vim set( CMAKE_EXPORT_COMPILE_COMMANDS ON ) # Print out compiler flags for viewing/debug if( BUILD_VERBOSE ) message( STATUS "hipblas_VERSION: ${hipblas_VERSION}" ) message( STATUS "\t==>CMAKE_BUILD_TYPE: ${CMAKE_BUILD_TYPE}" ) message( STATUS "\t==>BUILD_SHARED_LIBS: ${BUILD_SHARED_LIBS}" ) message( STATUS "\t==>CMAKE_INSTALL_PREFIX link: " ${CMAKE_INSTALL_PREFIX} ) message( STATUS "\t==>CMAKE_MODULE_PATH link: " ${CMAKE_MODULE_PATH} ) message( STATUS "\t==>CMAKE_PREFIX_PATH link: " ${CMAKE_PREFIX_PATH} ) message( STATUS "\t==>CMAKE_CXX_COMPILER flags: " ${CMAKE_CXX_FLAGS} ) message( STATUS "\t==>CMAKE_CXX_COMPILER debug flags: " ${CMAKE_CXX_FLAGS_DEBUG} ) message( STATUS "\t==>CMAKE_CXX_COMPILER release flags: " ${CMAKE_CXX_FLAGS_RELEASE} ) message( STATUS "\t==>CMAKE_CXX_COMPILER relwithdebinfo flags: " ${CMAKE_CXX_FLAGS_RELWITHDEBINFO} ) message( STATUS "\t==>CMAKE_EXE_LINKER link flags: " ${CMAKE_EXE_LINKER_FLAGS} ) endif( ) # Copy Public Headers to Build Dir configure_file( "${CMAKE_CURRENT_SOURCE_DIR}/include/hipblas-common.h" "${PROJECT_BINARY_DIR}/include/hipblas-common/hipblas-common.h" COPYONLY) set( hipblas_headers_public include/hipblas-common.h ) source_group( "Header Files\\Public" FILES ${hipblas_headers_public} ) add_library( hipblas-common INTERFACE ) target_include_directories( hipblas-common INTERFACE $ $ ) rocm_install_targets( TARGETS hipblas-common INCLUDE ${CMAKE_BINARY_DIR}/include ) rocm_export_targets(TARGETS roc::hipblas-common NAMESPACE roc::) hipBLAS-common-rocm-6.4.0/library/include/000077500000000000000000000000001471725375500202765ustar00rootroot00000000000000hipBLAS-common-rocm-6.4.0/library/include/hipblas-common.h000066400000000000000000000117021471725375500233600ustar00rootroot00000000000000/* ************************************************************************ * Copyright (C) 2016-2024 Advanced Micro Devices, Inc. All rights reserved. * * Permission is hereby granted, free of charge, to any person obtaining a copy * of this software and associated documentation files (the "Software"), to deal * in the Software without restriction, including without limitation the rights * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell * copies of the Software, and to permit persons to whom the Software is * furnished to do so, subject to the following conditions: * * The above copyright notice and this permission notice shall be included in * all copies or substantial portions of the Software. * * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE * SOFTWARE. * * ************************************************************************ */ //! HIP = Heterogeneous-compute Interface for Portability //! //! Define an extremely thin runtime layer that allows source code to be compiled unmodified //! through either AMD HCC or NVCC. Key features tend to be in the spirit //! and terminology of CUDA, but with a portable path to other accelerators as well. //! //! This is the master include file for hipblas-common, providing shared functionality //! between hipBLAS and hipBLASLt. #ifndef HIPBLAS_COMMON_H #define HIPBLAS_COMMON_H /*! \brief hipblas status codes definition */ typedef enum { HIPBLAS_STATUS_SUCCESS = 0, /**< Function succeeds */ HIPBLAS_STATUS_NOT_INITIALIZED = 1, /**< HIPBLAS library not initialized */ HIPBLAS_STATUS_ALLOC_FAILED = 2, /**< resource allocation failed */ HIPBLAS_STATUS_INVALID_VALUE = 3, /**< unsupported numerical value was passed to function */ HIPBLAS_STATUS_MAPPING_ERROR = 4, /**< access to GPU memory space failed */ HIPBLAS_STATUS_EXECUTION_FAILED = 5, /**< GPU program failed to execute */ HIPBLAS_STATUS_INTERNAL_ERROR = 6, /**< an internal HIPBLAS operation failed */ HIPBLAS_STATUS_NOT_SUPPORTED = 7, /**< function not implemented */ HIPBLAS_STATUS_ARCH_MISMATCH = 8, /**< architecture mismatch */ HIPBLAS_STATUS_HANDLE_IS_NULLPTR = 9, /**< hipBLAS handle is null pointer */ HIPBLAS_STATUS_INVALID_ENUM = 10, /**< unsupported enum value was passed to function */ HIPBLAS_STATUS_UNKNOWN = 11, /**< back-end returned an unsupported status code */ } hipblasStatus_t; #ifndef HIPBLAS_OPERATION_DECLARED #define HIPBLAS_OPERATION_DECLARED /*! \brief Used to specify whether the matrix is to be transposed or not. */ typedef enum { HIPBLAS_OP_N = 111, /**< Operate with the matrix. */ HIPBLAS_OP_T = 112, /**< Operate with the transpose of the matrix. */ HIPBLAS_OP_C = 113 /**< Operate with the conjugate transpose of the matrix. */ } hipblasOperation_t; #elif __cplusplus >= 201103L static_assert(HIPBLAS_OP_N == 111, "Inconsistent declaration of HIPBLAS_OP_N"); static_assert(HIPBLAS_OP_T == 112, "Inconsistent declaration of HIPBLAS_OP_T"); static_assert(HIPBLAS_OP_C == 113, "Inconsistent declaration of HIPBLAS_OP_C"); #endif // HIPBLAS_OPERATION_DECLARED /*! \brief The compute type to be used. Currently only used with GemmEx with the HIPBLAS_V2 interface. * Note that support for compute types is largely dependent on backend. */ typedef enum { // Note that these types are taken from cuBLAS. With the rocBLAS backend, currently hipBLAS will // convert to rocBLAS types to get equivalent functionality where supported. HIPBLAS_COMPUTE_16F = 0, /**< compute will be at least 16-bit precision */ HIPBLAS_COMPUTE_16F_PEDANTIC = 1, /**< compute will be exactly 16-bit precision */ HIPBLAS_COMPUTE_32F = 2, /**< compute will be at least 32-bit precision */ HIPBLAS_COMPUTE_32F_PEDANTIC = 3, /**< compute will be exactly 32-bit precision */ HIPBLAS_COMPUTE_32F_FAST_16F = 4, /**< 32-bit input can use 16-bit compute */ HIPBLAS_COMPUTE_32F_FAST_16BF = 5, /**< 32-bit input can is bf16 compute */ HIPBLAS_COMPUTE_32F_FAST_TF32 = 6, /**< 32-bit input can use tensor cores w/ TF32 compute. Only supported with cuBLAS and hipBLASLT backend currently */ HIPBLAS_COMPUTE_64F = 7, /**< compute will be at least 64-bit precision */ HIPBLAS_COMPUTE_64F_PEDANTIC = 8, /**< compute will be exactly 64-bit precision */ HIPBLAS_COMPUTE_32I = 9, /**< compute will be at least 32-bit integer precision */ HIPBLAS_COMPUTE_32I_PEDANTIC = 10, /**< compute will be exactly 32-bit integer precision */ } hipblasComputeType_t; #endif hipBLAS-common-rocm-6.4.0/rmake.py000077500000000000000000000132561471725375500166720ustar00rootroot00000000000000#!/usr/bin/python3 """Copyright (C) 2020-2024 Advanced Micro Devices, Inc. All rights reserved. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell cop- ies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IM- PLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNE- CTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. """ import os import platform import subprocess import argparse import pathlib args = {} OS_info = {} # yapf: disable def parse_args(): """Parse command-line arguments""" global OS_info parser = argparse.ArgumentParser(description="""Checks build arguments""") general_opts = parser.add_argument_group('General Build Options') general_opts.add_argument( '--build_dir', type=str, required=False, default = "build", help='Specify path to configure & build process output directory.(optional, default: ./build)') general_opts.add_argument('-i', '--install', required=False, default=False, dest='install', action='store_true', help='Generate and install library package after build. Windows only. Linux use install.sh (optional, default: False)') return parser.parse_args() # yapf: enable def os_detect(): global OS_info if os.name == "nt": OS_info["ID"] = platform.system() else: inf_file = "/etc/os-release" if os.path.exists(inf_file): with open(inf_file) as f: for line in f: if "=" in line: k, v = line.strip().split("=") OS_info[k] = v.replace('"', '') def create_dir(dir_path): full_path = "" if os.path.isabs(dir_path): full_path = dir_path else: full_path = os.path.join(os.getcwd(), dir_path) pathlib.Path(full_path).mkdir(parents=True, exist_ok=True) return def delete_dir(dir_path): if (not os.path.exists(dir_path)): return if os.name == "nt": run_cmd("RMDIR", f"/S /Q {dir_path}") else: run_cmd("rm", f"-rf {dir_path}") def cmake_path(os_path): if os.name == "nt": return os_path.replace("\\", "/") else: return os.path.realpath(os_path) def config_cmd(): global args global OS_info cwd_path = os.getcwd() cmake_executable = "cmake" cmake_options = [] src_path = cmake_path(cwd_path) cmake_platform_opts = [] if os.name == "nt": generator = f"-G Ninja" cmake_options.append(generator) # 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 # CPACK_PACKAGING_INSTALL_PREFIX= defined as blank as it is appended to end of path for archive creation cmake_platform_opts.append(f"-DCPACK_PACKAGING_INSTALL_PREFIX=") cmake_platform_opts.append(f'-DCMAKE_INSTALL_PREFIX="C:/hipSDK"') else: rocm_raw_path = os.getenv('ROCM_PATH', "/opt/rocm") rocm_path = rocm_raw_path cmake_platform_opts.append(f"-DROCM_DIR:PATH={rocm_path} -DCPACK_PACKAGING_INSTALL_PREFIX={rocm_path}") print(f"Build source path: {src_path}") cmake_options.extend(cmake_platform_opts) cmake_base_options = f"-DROCM_PATH={rocm_path} -DCMAKE_PREFIX_PATH:PATH={rocm_path}" cmake_options.append(cmake_base_options) # packaging options cmake_pack_options = f"-DCPACK_SET_DESTDIR=OFF" cmake_options.append(cmake_pack_options) # build type cmake_config = "" build_path = os.path.realpath(args.build_dir) # clean delete_dir(build_path) create_dir(os.path.join(build_path)) os.chdir(build_path) cmake_options.append(f"{src_path}") cmd_opts = " ".join(cmake_options) return cmake_executable, cmd_opts def make_cmd(): global args global OS_info make_options = [] if os.name == "nt": make_executable = f"ninja.exe" make_options.append("all") # for cmake "--target all" ) if args.install: make_options.append("package install") # for cmake "--target package --target install" ) else: make_executable = f"make package" if args.install: make_options.append("install") cmd_opts = " ".join(make_options) return make_executable, cmd_opts def run_cmd(exe, opts): program = f"{exe} {opts}" print(program) proc = subprocess.run(program, check=True, stderr=subprocess.STDOUT, shell=True) return proc.returncode def main(): global args os_detect() args = parse_args() print(OS_info) root_dir = os.curdir # configure exe, opts = config_cmd() if run_cmd(exe, opts): fatal("Configuration failed. Not continuing.") # make exe, opts = make_cmd() if run_cmd(exe, opts): fatal("Build failed. Not continuing.") if __name__ == '__main__': main()