diff --git a/projects/rocr-runtime/CMakeLists.txt b/projects/rocr-runtime/CMakeLists.txt index 44850dd7cf..4da29689d2 100644 --- a/projects/rocr-runtime/CMakeLists.txt +++ b/projects/rocr-runtime/CMakeLists.txt @@ -43,7 +43,6 @@ cmake_minimum_required(VERSION 3.7) -# Set the project name project("rocr") set( CORE_TARGET "hsa-rocr" ) set( BUILD_ENABLE_LINTIAN_OVERRIDES ON CACHE BOOL "Enable/Disable Lintian Overrides" ) diff --git a/projects/rocr-runtime/libhsakmt/CMakeLists.txt b/projects/rocr-runtime/libhsakmt/CMakeLists.txt index 25b3af4af8..be539e2553 100644 --- a/projects/rocr-runtime/libhsakmt/CMakeLists.txt +++ b/projects/rocr-runtime/libhsakmt/CMakeLists.txt @@ -25,6 +25,9 @@ cmake_minimum_required ( VERSION 3.6.3 ) +if (WIN_SDK) + include(${CMAKE_CURRENT_SOURCE_DIR}/CMakeLists_wsl.txt) +else () set(CMAKE_VERBOSE_MAKEFILE ON) set ( HSAKMT "hsakmt" ) @@ -319,3 +322,4 @@ endif() ########################### # Use component packaging set ( ENABLE_LDCONFIG ON CACHE BOOL "Set library links and caches using ldconfig.") +endif() diff --git a/projects/rocr-runtime/libhsakmt/CMakeLists_wsl.txt b/projects/rocr-runtime/libhsakmt/CMakeLists_wsl.txt new file mode 100644 index 0000000000..e07f9f9932 --- /dev/null +++ b/projects/rocr-runtime/libhsakmt/CMakeLists_wsl.txt @@ -0,0 +1,309 @@ +################################################################################ +## +## Copyright (c) 2016 Advanced Micro Devices, Inc. All rights reserved. +## +## MIT LICENSE: +## 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. +## +################################################################################ + +cmake_minimum_required ( VERSION 3.15 ) + +set(CMAKE_VERBOSE_MAKEFILE ON) + +set ( ROCDXG "rocdxg" ) +set ( ROCDXG_PACKAGE "rocdxg-roct" ) +set ( ROCDXG_COMPONENT "lib${ROCDXG}" ) +set ( ROCDXG_TARGET "${ROCDXG}" ) +set ( ROCDXG_VERSION "1.1.0") + +project ( ${ROCDXG_TARGET} VERSION ${ROCDXG_VERSION} ) +# Project/version initialized; expose version to code via target defs below + +# Optionally, build ROCDXG with ccache. +set(ROCM_CCACHE_BUILD OFF CACHE BOOL "Set to ON for a ccache enabled build") +if (ROCM_CCACHE_BUILD) + find_program(CCACHE_PROGRAM ccache) + if (CCACHE_PROGRAM) + set_property(GLOBAL PROPERTY RULE_LAUNCH_COMPILE ${CCACHE_PROGRAM}) + else() + message(WARNING "Unable to find ccache. Falling back to real compiler") + endif() # if (CCACHE_PROGRAM) +endif() # if (ROCM_CCACHE_BUILD) + +list( PREPEND CMAKE_MODULE_PATH "${CMAKE_CURRENT_SOURCE_DIR}/cmake_modules" ) + +## Include common cmake modules +include ( utils ) +include ( GNUInstallDirs ) + +## Setup the package version. +get_version ( "${ROCDXG_VERSION}" ) + +set ( BUILD_VERSION_MAJOR ${VERSION_MAJOR} ) +set ( BUILD_VERSION_MINOR ${VERSION_MINOR} ) +set ( BUILD_VERSION_PATCH ${VERSION_PATCH} ) + +set ( LIB_VERSION_MAJOR ${VERSION_MAJOR}) +set ( LIB_VERSION_MINOR ${VERSION_MINOR}) +set ( LIB_VERSION_PATCH ${VERSION_PATCH}) + +set ( LIB_VERSION_STRING "${LIB_VERSION_MAJOR}.${LIB_VERSION_MINOR}.${LIB_VERSION_PATCH}" ) + +if ( DEFINED VERSION_BUILD AND NOT ${VERSION_BUILD} STREQUAL "" ) + message ( "VERSION BUILD DEFINED ${VERSION_BUILD}" ) + set ( BUILD_VERSION_PATCH "${BUILD_VERSION_PATCH}-${VERSION_BUILD}" ) +endif () +set ( BUILD_VERSION_STRING "${BUILD_VERSION_MAJOR}.${BUILD_VERSION_MINOR}.${BUILD_VERSION_PATCH}" ) + +## Compiler flags +set (ROCDXG_CXX_FLAGS -fPIC -include ${CMAKE_CURRENT_SOURCE_DIR}/src/dxg/librocdxg.h) + +if ( CMAKE_COMPILER_IS_GNUCC ) + set ( ROCDXG_CXX_FLAGS "${ROCDXG_CXX_FLAGS}" -Wlogical-op) +endif () +if ( ${ROCDXG_WERROR} ) + set ( ROCDXG_CXX_FLAGS "${ROCDXG_CXX_FLAGS}" -Werror ) +endif () +if ( "${CMAKE_BUILD_TYPE}" STREQUAL Release ) + set ( ROCDXG_CXX_FLAGS "${ROCDXG_CXX_FLAGS}" -O2 ) +else () + set ( ROCDXG_CXX_FLAGS "${ROCDXG_CXX_FLAGS}" -g ) +endif () + +set ( ROCDXG_LINKER_SCRIPT "${CMAKE_CURRENT_SOURCE_DIR}/src/dxg/librocdxg.ver" ) + +## Linker Flags +## Add --enable-new-dtags to generate DT_RUNPATH +set (ROCDXG_LINK_FLAGS "${ROCDXG_LINK_FLAGS} -Wl,--enable-new-dtags -Wl,--version-script=${ROCDXG_LINKER_SCRIPT} -Wl,-soname=${ROCDXG_COMPONENT}.so.${LIB_VERSION_MAJOR} -Wl,-z,nodelete") + +## Linker undefined symbol handling +if ( CMAKE_COMPILER_IS_GNUCC ) + set ( ROCDXG_LINK_FLAGS "${ROCDXG_LINK_FLAGS} -Wl,-no-undefined" ) +else () + set ( ROCDXG_LINK_FLAGS "${ROCDXG_LINK_FLAGS} -Wl,-undefined,error" ) +endif () + +## Source files +set ( ROCDXG_SRC "src/dxg/debug.cpp" + "src/dxg/events.cpp" + "src/dxg/memory.cpp" + "src/dxg/libdrm.cpp" + "src/dxg/hsa.cpp" + "src/dxg/openclose.cpp" + "src/dxg/perfctr.cpp" + "src/dxg/queues.cpp" + "src/dxg/time.cpp" + "src/dxg/topology.cpp" + "src/dxg/spm.cpp" + "src/dxg/version.cpp" + "src/dxg/svm.cpp" + "src/dxg/pc_sampling.cpp" + "src/dxg/hsakmtmodel.cpp" + "src/dxg/dxcore_loader.cpp" + "src/dxg/ais.cpp" + "src/dxg/wddm/device.cpp" + "src/dxg/wddm/gpu_memory.cpp" + "src/dxg/wddm/va_mgr.cpp" + "src/dxg/wddm/queue.cpp" + "src/dxg/wddm/cmd_util.cpp" ) + +## Declare the library target name +add_library (${ROCDXG_TARGET} SHARED "") + +## Add sources +target_sources ( ${ROCDXG_TARGET} PRIVATE ${ROCDXG_SRC} ) + +## Add headers. The public headers need to point at their location in both build and install +## directory layouts. This declaration allows publishing library use data to downstream clients. +target_include_directories( ${ROCDXG_TARGET} + PUBLIC + $ + $ + PRIVATE + ${WIN_SDK} + ${CMAKE_CURRENT_SOURCE_DIR}/src/dxg ) + +add_compile_definitions(LINUX __AMD64__ LITTLEENDIAN_CPU HSA_LARGE_MODEL) + +# Ensure version macro is defined for this target +target_compile_definitions(${ROCDXG_TARGET} PRIVATE ROCDXG_VERSION="${ROCDXG_VERSION}") + +target_link_directories(${ROCDXG_TARGET} PRIVATE ${CMAKE_CURRENT_SOURCE_DIR}/src/dxg/thunk_proxy) +target_link_libraries(${ROCDXG_TARGET} PRIVATE thunk_proxy) + +set_property(TARGET ${ROCDXG_TARGET} PROPERTY LINK_FLAGS ${ROCDXG_LINK_FLAGS}) + +## Set the VERSION and SOVERSION values +set_property ( TARGET ${ROCDXG_TARGET} PROPERTY VERSION "${LIB_VERSION_STRING}" ) +set_property ( TARGET ${ROCDXG_TARGET} PROPERTY SOVERSION "${LIB_VERSION_MAJOR}" ) + +find_package(PkgConfig) +# get OS-info for OS-specific build dependencies +get_os_info() +# Check for libraries required for building +find_library(LIBC NAMES c REQUIRED) +message(STATUS "LIBC:" ${LIBC}) + +target_link_libraries ( ${ROCDXG_TARGET} + PRIVATE pthread rt c ${CMAKE_DL_LIBS} +) + +target_compile_options(${ROCDXG_TARGET} PRIVATE ${ROCDXG_CXX_FLAGS}) + +## Define default paths and packages. +if( CMAKE_INSTALL_PREFIX_INITIALIZED_TO_DEFAULT ) + set ( CMAKE_INSTALL_PREFIX "/opt/rocm" ) +endif() +set ( CMAKE_INSTALL_PREFIX ${CMAKE_INSTALL_PREFIX} CACHE STRING "Default installation directory." FORCE ) +set ( CPACK_PACKAGING_INSTALL_PREFIX "${CMAKE_INSTALL_PREFIX}" CACHE STRING "Default packaging prefix." ) +set ( CPACK_GENERATOR "DEB" CACHE STRING "Default packaging generators." ) + +# Installs binaries and exports the library usage data to ${ROCDXG_TARGET}Targets +install ( TARGETS ${ROCDXG_TARGET} EXPORT ${ROCDXG_TARGET}Targets + ARCHIVE DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT binary + LIBRARY DESTINATION ${CMAKE_INSTALL_LIBDIR} COMPONENT binary ) + +# Install public headers +#install ( DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/include/${ROCDXG_TARGET} DESTINATION ${CMAKE_INSTALL_INCLUDEDIR} +# COMPONENT dev PATTERN "*drm*" EXCLUDE ) + +# Record our usage data for clients find_package calls. +install ( EXPORT ${ROCDXG_TARGET}Targets + FILE ${ROCDXG_TARGET}Targets.cmake + NAMESPACE ${ROCDXG_TARGET}:: + DESTINATION ${CMAKE_INSTALL_LIBDIR}/cmake/${ROCDXG_TARGET} + COMPONENT dev ) + +# Adds the target alias rocdxg::rocdxg to the local cmake cache. +# This isn't necessary today. It's harmless preparation for some +# hypothetical future in which the we might be included by add_subdirectory() +# in some other project's cmake file. It allows uniform use of find_package +# and target_link_library() without regard to whether a target is external or +# a subdirectory of the current build. +add_library( ${ROCDXG_TARGET}::${ROCDXG_TARGET} ALIAS ${ROCDXG_TARGET} ) + +# Create cmake configuration files +include(CMakePackageConfigHelpers) + +configure_package_config_file(${ROCDXG_TARGET}-config.cmake.in + ${ROCDXG_TARGET}-config.cmake + INSTALL_DESTINATION + ${CMAKE_INSTALL_LIBDIR}/cmake/${ROCDXG_TARGET} ) + +write_basic_package_version_file(${ROCDXG_TARGET}-config-version.cmake + VERSION ${BUILD_VERSION_STRING} + COMPATIBILITY + AnyNewerVersion) + +install(FILES + ${CMAKE_CURRENT_BINARY_DIR}/${ROCDXG_TARGET}-config.cmake + ${CMAKE_CURRENT_BINARY_DIR}/${ROCDXG_TARGET}-config-version.cmake + DESTINATION + ${CMAKE_INSTALL_LIBDIR}/cmake/${ROCDXG_TARGET} + COMPONENT dev ) + +# Optionally record the package's find module in the user's package cache. +if ( NOT DEFINED EXPORT_TO_USER_PACKAGE_REGISTRY ) + set ( EXPORT_TO_USER_PACKAGE_REGISTRY "off" ) +endif() +set ( EXPORT_TO_USER_PACKAGE_REGISTRY ${EXPORT_TO_USER_PACKAGE_REGISTRY} + CACHE BOOL "Add cmake package config location to the user's cmake package registry.") +if(${EXPORT_TO_USER_PACKAGE_REGISTRY}) + # Enable writing to the registry + set(CMAKE_EXPORT_PACKAGE_REGISTRY ON) + # Generate a target file for the build + export(TARGETS ${ROCDXG_TARGET} NAMESPACE ${ROCDXG_TARGET}:: FILE ${ROCDXG_TARGET}Targets.cmake) + # Record the package in the user's cache. + export(PACKAGE ${ROCDXG_TARGET}) +endif() + +# Since librocdxg.pc and libhsakmt.pc are installed to the same pkgconfig directory, +# we can directly use libhsakmt's header file path in the includedir. +# This allows librocdxg to reference the same header files as libhsakmt without +# duplicating header installation. +configure_file ( librocdxg.pc.in librocdxg.pc @ONLY ) + +install ( FILES ${CMAKE_CURRENT_BINARY_DIR}/librocdxg.pc DESTINATION ${CMAKE_INSTALL_LIBDIR}/pkgconfig COMPONENT dev ) + +install(CODE "execute_process(COMMAND ldconfig)" COMPONENT binary) + +########################### +# Packaging directives +########################### +# Use component packaging +set(CPACK_COMPONENTS_GROUPING IGNORE) +set(CPACK_DEB_COMPONENT_INSTALL ON) +set(CPACK_PACKAGE_VENDOR "Advanced Micro Devices, Inc.") +set(CPACK_PACKAGE_VERSION_MAJOR ${VERSION_MAJOR}) +set(CPACK_PACKAGE_VERSION_MINOR ${VERSION_MINOR}) +set(CPACK_PACKAGE_VERSION_PATCH ${VERSION_PATCH}) +set(CPACK_PACKAGE_CONTACT "AMD GFX mailing list ") +set(CPACK_RESOURCE_FILE_LICENSE "${CMAKE_CURRENT_SOURCE_DIR}/LICENSE.md") +set(CPACK_COMPONENT_DESCRIPTION "ROCDXG development package.\n This package includes the user-mode API interfaces\nused to interact with the ROCm driver.\n This package contains the libraries and cmake files for the ROCDXG package.") +set ( ENABLE_LDCONFIG ON CACHE BOOL "Set library links and caches using ldconfig.") + +# Install License file +install ( FILES ${CPACK_RESOURCE_FILE_LICENSE} DESTINATION ${CMAKE_INSTALL_DOCDIR} COMPONENT binary ) + +# Prepare final version for the CPACK use +set(PACKAGE_VERSION_STR "${CPACK_PACKAGE_VERSION_MAJOR}.${CPACK_PACKAGE_VERSION_MINOR}.${CPACK_PACKAGE_VERSION_PATCH}") +set(CPACK_PACKAGE_VERSION "${PACKAGE_VERSION_STR}") + +# Debian package specific variables +set(CPACK_DEBIAN_PACKAGE_NAME "rocdxg-roct") + +# Debian binary package specific variables (runtime package) +set(CPACK_DEBIAN_BINARY_PACKAGE_NAME "rocdxg-roct") +set(CPACK_DEBIAN_BINARY_PACKAGE_DESCRIPTION "ROCDXG runtime package containing libraries") + +# Debian dev package specific variables +set(CPACK_DEBIAN_DEV_PACKAGE_NAME "rocdxg-roct-dev") +set(CPACK_DEBIAN_DEV_PACKAGE_DESCRIPTION "ROCDXG development package containing pkgconfig and cmake files") + +## Process the Debian install/remove scripts to update the CPACK variables +configure_file ( ${CMAKE_CURRENT_SOURCE_DIR}/DEBIAN/postinst.in DEBIAN/postinst @ONLY ) +configure_file ( ${CMAKE_CURRENT_SOURCE_DIR}/DEBIAN/prerm.in DEBIAN/prerm @ONLY ) +set(CPACK_DEBIAN_PACKAGE_CONTROL_EXTRA "DEBIAN/postinst;DEBIAN/prerm") + +# Setting package dependencies +set(CPACK_DEBIAN_PACKAGE_DEPENDS "rocm-core") +set(CPACK_DEBIAN_BINARY_PACKAGE_DEPENDS "rocm-core") +set(CPACK_DEBIAN_DEV_PACKAGE_DEPENDS "rocdxg-roct (= ${PACKAGE_VERSION_STR}), rocm-core") + +# Set the names now using CPACK utility +set(CPACK_DEBIAN_FILE_NAME "DEB-DEFAULT") + +# Remove dependency on rocm-core if -DROCM_DEP_ROCMCORE=ON not given to cmake +if(NOT ROCM_DEP_ROCMCORE) + string(REGEX REPLACE ",? ?rocm-core" "" CPACK_DEBIAN_PACKAGE_DEPENDS ${CPACK_DEBIAN_PACKAGE_DEPENDS}) + string(REGEX REPLACE ",? ?rocm-core" "" CPACK_DEBIAN_BINARY_PACKAGE_DEPENDS ${CPACK_DEBIAN_BINARY_PACKAGE_DEPENDS}) + string(REGEX REPLACE ",? ?rocm-core" "" CPACK_DEBIAN_DEV_PACKAGE_DEPENDS ${CPACK_DEBIAN_DEV_PACKAGE_DEPENDS}) +endif() + +include(CPack) + +# Add component descriptions +cpack_add_component(binary + DISPLAY_NAME "Runtime" + DESCRIPTION "ROCDXG runtime libraries") + +cpack_add_component(dev + DISPLAY_NAME "Development" + DESCRIPTION "ROCDXG development files (pkgconfig and cmake)") diff --git a/projects/rocr-runtime/libhsakmt/include/hsakmt/hsakmt.h b/projects/rocr-runtime/libhsakmt/include/hsakmt/hsakmt.h index 88ab70ae93..e19441b5a8 100644 --- a/projects/rocr-runtime/libhsakmt/include/hsakmt/hsakmt.h +++ b/projects/rocr-runtime/libhsakmt/include/hsakmt/hsakmt.h @@ -398,6 +398,12 @@ hsaKmtGetQueueInfo( HsaQueueInfo *QueueInfo //IN ); +HSAKMT_STATUS +HSAKMTAPI +hsaKmtQueueRingDoorbell( + HSA_QUEUEID QueueId +); + /** Allows an HSA process to set/change the default and alternate memory coherency, before starting to dispatch. */ diff --git a/projects/rocr-runtime/libhsakmt/include/hsakmt/hsakmt_drm.h b/projects/rocr-runtime/libhsakmt/include/hsakmt/hsakmt_drm.h new file mode 100644 index 0000000000..af9658cf6d --- /dev/null +++ b/projects/rocr-runtime/libhsakmt/include/hsakmt/hsakmt_drm.h @@ -0,0 +1,33 @@ +/* + * Copyright © 2024 Advanced Micro Devices, Inc. + * + * 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 (including + * the next paragraph) 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. + */ + +#ifndef _HSAKMT_DRM_H_ +#define _HSAKMT_DRM_H_ + +#include "drm/xf86drm.h" +#include "drm/amdgpu.h" +#include "drm/amdgpu_drm.h" + +#endif diff --git a/projects/rocr-runtime/libhsakmt/librocdxg.pc.in b/projects/rocr-runtime/libhsakmt/librocdxg.pc.in new file mode 100755 index 0000000000..d9b362399d --- /dev/null +++ b/projects/rocr-runtime/libhsakmt/librocdxg.pc.in @@ -0,0 +1,11 @@ +prefix=${pcfiledir}/../../.. +exec_prefix=${prefix} +libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@ +includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ + +Name: librocdxg +Description: HSA Kernel Mode Thunk library for WSL support +Version: @LIB_VERSION_STRING@ + +Libs: -L${libdir} -lrocdxg +Cflags: -I${includedir} diff --git a/projects/rocr-runtime/libhsakmt/rocdxg-config.cmake.in b/projects/rocr-runtime/libhsakmt/rocdxg-config.cmake.in new file mode 100644 index 0000000000..5f2ab41f37 --- /dev/null +++ b/projects/rocr-runtime/libhsakmt/rocdxg-config.cmake.in @@ -0,0 +1,14 @@ +@PACKAGE_INIT@ + +include( CMakeFindDependencyMacro ) + +# Locate dependent packages here. Finding them propagates usage requirements, +# if any, to our clients and ensures that their target names are in scope for +# the build. rocdxg has no cmake project dependencies so there is nothing to +# find. If we switch to use find_package with external (to ROCm) library +# dependencies (ie libnuma) then those packages should be located here using +# find_dependencies as shown below. +#find_dependency(Bar, 2.0) + +include( "${CMAKE_CURRENT_LIST_DIR}/@ROCDXG_TARGET@Targets.cmake" ) +