├── tests ├── kfdtest │ ├── .gitignore │ ├── README.txt │ ├── src │ │ ├── RDMAUtil.hpp │ │ ├── KFDASMTest.hpp │ │ ├── KFDPMTest.hpp │ │ ├── RDMATest.hpp │ │ ├── KFDDBGTest.hpp │ │ ├── KFDGWSTest.hpp │ │ ├── KFDGraphicsInterop.hpp │ │ ├── KFDPCSamplingTest.hpp │ │ ├── KFDLocalMemoryTest.hpp │ │ ├── XgmiOptimizedSDMAQueue.hpp │ │ ├── KFDCWSRTest.hpp │ │ ├── KFDHWSTest.hpp │ │ ├── KFDSVMRangeTest.hpp │ │ ├── KFDTopologyTest.hpp │ │ ├── KFDEventTest.hpp │ │ ├── AqlQueue.cpp │ │ ├── KFDPerfCounters.hpp │ │ ├── KFDOpenCloseKFDTest.hpp │ │ ├── AqlQueue.hpp │ │ ├── BasePacket.hpp │ │ ├── KFDRASTest.hpp │ │ ├── BasePacket.cpp │ │ ├── KFDQMTest.hpp │ │ ├── KFDMemoryTest.hpp │ │ ├── KFDASMTest.cpp │ │ ├── KFDEvictTest.hpp │ │ ├── RDMAUtil.cpp │ │ ├── KFDMultiProcessTest.hpp │ │ ├── IndirectBuffer.cpp │ │ ├── Dispatch.hpp │ │ ├── IndirectBuffer.hpp │ │ ├── ShaderStore.hpp │ │ ├── SDMAQueue.hpp │ │ ├── PM4Queue.hpp │ │ ├── KFDExceptionTest.hpp │ │ ├── KFDTestUtilQueue.hpp │ │ ├── KFDTestFlags.hpp │ │ ├── KFDMultiProcessTest.cpp │ │ ├── GoogleTestExtension.cpp │ │ ├── KFDSVMEvictTest.hpp │ │ ├── BaseDebug.hpp │ │ ├── KFDOpenCloseKFDTest.cpp │ │ ├── PM4Queue.cpp │ │ ├── Assemble.hpp │ │ ├── KFDPMTest.cpp │ │ ├── SDMAQueue.cpp │ │ ├── GoogleTestExtension.hpp │ │ ├── KFDTestMain.cpp │ │ ├── OSWrapper.hpp │ │ ├── KFDGWSTest.cpp │ │ ├── KFDHWSTest.cpp │ │ ├── KFDIPCTest.hpp │ │ └── KFDBaseComponentTest.hpp │ ├── include │ │ ├── amdp2ptest.h │ │ ├── pm4_pkt_struct_ci.h │ │ ├── kfd_pm4_opcodes.h │ │ └── pm4_pkt_struct_nv.h │ └── LICENSE.kfdtest ├── reopen │ ├── CMakeLists.txt │ └── kmtreopen.c └── rdma │ └── simple │ ├── drv │ ├── Makefile │ └── amdp2ptest.h │ └── app │ └── CMakeLists.txt ├── DEBIAN ├── x86_64-libhsakmt.conf ├── control ├── prerm.in └── postinst.in ├── .gitignore ├── RPM ├── post.in ├── postun.in ├── libhsakmt.spec └── hsakmt-roct-devel.spec.in ├── .github └── CODEOWNERS ├── libhsakmt.pc.in ├── .azuredevops └── rocm-ci.yml ├── src ├── libhsakmt.c ├── globals.c ├── version.c ├── time.c ├── libhsakmt.ver ├── pmc_table.h ├── rbtree.h ├── spm.c ├── rbtree_amd.h └── fmm.h ├── hsakmt-config.cmake.in ├── LICENSE.md ├── README.md └── hsakmt-backward-compat.cmake /tests/kfdtest/.gitignore: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /DEBIAN/x86_64-libhsakmt.conf: -------------------------------------------------------------------------------- 1 | /opt/rocm/lib 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .* 2 | 3 | # 4 | # git files that we don't want to ignore even it they are dot-files 5 | # 6 | !.gitignore 7 | !.mailmap 8 | .github* 9 | patches-* 10 | build/ 11 | outgoing/ 12 | Makefile 13 | -------------------------------------------------------------------------------- /DEBIAN/control: -------------------------------------------------------------------------------- 1 | Package: hsakmt-rocm-dev 2 | Architecture: $arch 3 | Maintainer: Advanced Micro Devices Inc. 4 | Depends:libpci3, libnuma1 5 | Priority: optional 6 | Version: $version 7 | Description: Thunk library for AMD KFD 8 | 9 | -------------------------------------------------------------------------------- /RPM/post.in: -------------------------------------------------------------------------------- 1 | # left-hand term originates from ENABLE_LDCONFIG = ON/OFF at package build 2 | if [ "@ENABLE_LDCONFIG@" == "ON" ]; then 3 | echo -e "@CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@" > /@CMAKE_INSTALL_SYSCONFDIR@/ld.so.conf.d/x86_64-libhsakmt.conf 4 | ldconfig 5 | fi 6 | -------------------------------------------------------------------------------- /tests/reopen/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 2.6) 2 | 3 | project (kmtreopen) 4 | 5 | link_directories($ENV{ROOT_OF_ROOTS}/out/lib) 6 | 7 | include_directories($ENV{LIBHSAKMT_ROOT}/include) 8 | 9 | add_executable(kmtreopen kmtreopen.c) 10 | target_link_libraries(kmtreopen libdl.so) 11 | 12 | -------------------------------------------------------------------------------- /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | # Default code owners 2 | @kentrussell @fxkamd @dayatsin-amd 3 | 4 | *.md @ROCm/rocm-documentation @kentrussell @dayatsin-amd 5 | *.rst @ROCm/rocm-documentation @kentrussell @dayatsin-amd 6 | 7 | # Header directory for Doxygen documentation 8 | inc/* @ROCm/rocm-documentation @kentrussell @fxkamd @dayatsin-amd 9 | -------------------------------------------------------------------------------- /RPM/postun.in: -------------------------------------------------------------------------------- 1 | # second term originates from ENABLE_LDCONFIG = ON/OFF at package build 2 | if [ $1 -le 1 ] && [ "@ENABLE_LDCONFIG@" == "ON" ]; then 3 | # perform the below actions for rpm remove($1=0) or upgrade($1=1) operations 4 | rm -f /@CMAKE_INSTALL_SYSCONFDIR@/ld.so.conf.d/x86_64-libhsakmt.conf 5 | ldconfig 6 | fi 7 | -------------------------------------------------------------------------------- /libhsakmt.pc.in: -------------------------------------------------------------------------------- 1 | prefix=${pcfiledir}/../.. 2 | exec_prefix=${prefix} 3 | libdir=${prefix}/@CMAKE_INSTALL_LIBDIR@ 4 | includedir=${prefix}/@CMAKE_INSTALL_INCLUDEDIR@ 5 | 6 | Name: libhsakmt 7 | Description: HSA Kernel Mode Thunk library for AMD KFD support 8 | Version: @LIB_VERSION_STRING@ 9 | 10 | Libs: -L${libdir} -lhsakmt 11 | Cflags: -I${includedir} 12 | -------------------------------------------------------------------------------- /DEBIAN/prerm.in: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | # left-hand term originates from ENABLE_LDCONFIG = ON/OFF at package build 6 | rm_ldconfig() { 7 | if [ "@ENABLE_LDCONFIG@" == "ON" ]; then 8 | rm -f /@CMAKE_INSTALL_SYSCONFDIR@/ld.so.conf.d/x86_64-libhsakmt.conf && ldconfig 9 | fi 10 | } 11 | 12 | case "$1" in 13 | ( remove | upgrade ) 14 | rm_ldconfig 15 | ;; 16 | ( purge ) 17 | ;; 18 | ( * ) 19 | exit 0 20 | ;; 21 | esac 22 | -------------------------------------------------------------------------------- /DEBIAN/postinst.in: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | set -e 4 | 5 | # left-hand term originates from ENABLE_LDCONFIG = ON/OFF at package build 6 | do_ldconfig() { 7 | if [ "@ENABLE_LDCONFIG@" == "ON" ]; then 8 | echo @CPACK_PACKAGING_INSTALL_PREFIX@/@CMAKE_INSTALL_LIBDIR@ > /@CMAKE_INSTALL_SYSCONFDIR@/ld.so.conf.d/x86_64-libhsakmt.conf 9 | ldconfig 10 | fi 11 | } 12 | 13 | case "$1" in 14 | ( configure ) 15 | do_ldconfig 16 | ;; 17 | ( abort-upgrade | abort-remove | abort-deconfigure ) 18 | echo "$1" 19 | ;; 20 | ( * ) 21 | exit 0 22 | ;; 23 | esac 24 | -------------------------------------------------------------------------------- /.azuredevops/rocm-ci.yml: -------------------------------------------------------------------------------- 1 | resources: 2 | repositories: 3 | - repository: pipelines_repo 4 | type: github 5 | endpoint: ROCm 6 | name: ROCm/ROCm 7 | 8 | variables: 9 | - group: common 10 | - template: /.azuredevops/variables-global.yml@pipelines_repo 11 | 12 | trigger: 13 | batch: true 14 | branches: 15 | include: 16 | - master 17 | paths: 18 | exclude: 19 | - '*.md' 20 | 21 | pr: 22 | autoCancel: true 23 | branches: 24 | include: 25 | - master 26 | paths: 27 | exclude: 28 | - '*.md' 29 | drafts: false 30 | 31 | jobs: 32 | - template: ${{ variables.CI_COMPONENT_PATH }}/ROCT-Thunk-Interface.yml@pipelines_repo 33 | -------------------------------------------------------------------------------- /src/libhsakmt.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | 5 | #include "libhsakmt.h" 6 | 7 | /* Call ioctl, restarting if it is interrupted */ 8 | int kmtIoctl(int fd, unsigned long request, void *arg) 9 | { 10 | int ret; 11 | 12 | do { 13 | ret = ioctl(fd, request, arg); 14 | } while (ret == -1 && (errno == EINTR || errno == EAGAIN)); 15 | 16 | if (ret == -1 && errno == EBADF) { 17 | /* In case pthread_atfork didn't catch it, this will 18 | * make any subsequent hsaKmt calls fail in CHECK_KFD_OPEN. 19 | */ 20 | pr_err("KFD file descriptor not valid in this process\n"); 21 | is_forked_child(); 22 | } 23 | 24 | return ret; 25 | } 26 | -------------------------------------------------------------------------------- /tests/kfdtest/README.txt: -------------------------------------------------------------------------------- 1 | 1. Note on building kfdtest 2 | 3 | To build this kfdtest application, the following libraries should be already 4 | installed on the building machine: 5 | libdrm libdrm_amdgpu libhsakmt 6 | 7 | If libhsakmt is not installed, but the headers and libraries are present 8 | locally, you can specify its directory by 9 | export LIBHSAKMT_PATH=/*your local libhsakmt folder*/ 10 | With that, the headers and libraries are searched under 11 | LIBHSAKMT_PATH/include and LIBHSAKMT_PATH/lib respectively. 12 | 13 | 14 | 2. How to run kfdtest 15 | 16 | Just run "./run_kfdtest.sh" under the building output folder. You may need 17 | to specify library path through: 18 | export LD_LIBRARY_PATH=/*your library path containing libhsakmt*/ 19 | 20 | Note: you can use "run_kfdtest.sh -h" to see more options. 21 | -------------------------------------------------------------------------------- /RPM/libhsakmt.spec: -------------------------------------------------------------------------------- 1 | %define name hsakmt-rocm-dev 2 | %define version %{getenv:PACKAGE_VER} 3 | %define packageroot %{getenv:PACKAGE_DIR} 4 | 5 | Name: %{name} 6 | Version: %{version} 7 | Release: 1 8 | Summary: Thunk libraries for AMD KFD 9 | 10 | Group: System Environment/Libraries 11 | License: Advanced Micro Devices Inc. 12 | 13 | %if 0%{?centos} == 6 14 | Requires: numactl 15 | %else 16 | Requires: numactl-libs 17 | %endif 18 | 19 | 20 | %description 21 | This package includes the libhsakmt (Thunk) libraries 22 | for AMD KFD 23 | 24 | %prep 25 | %setup -T -D -c -n %{name} 26 | 27 | %install 28 | cp -R %packageroot $RPM_BUILD_ROOT 29 | find $RPM_BUILD_ROOT \! -type d | sed "s|$RPM_BUILD_ROOT||"> thunk.list 30 | 31 | %post 32 | ldconfig 33 | 34 | %postun 35 | ldconfig 36 | 37 | %clean 38 | rm -rf $RPM_BUILD_ROOT 39 | 40 | %files -f thunk.list 41 | 42 | %defattr(-,root,root,-) 43 | -------------------------------------------------------------------------------- /tests/rdma/simple/drv/Makefile: -------------------------------------------------------------------------------- 1 | 2 | ifeq ($(src),) 3 | src := $$PWD 4 | endif 5 | 6 | ifneq ($(KERNELRELEASE),) 7 | 8 | ifeq ("$(wildcard $(RDMA_HEADER_DIR)/drm/amd_rdma.h)","") 9 | $(error amd_rdma.h not found, please export RDMA_HEADER_DIR=/usr/src/amdgpu-x.x.x/include) 10 | endif 11 | 12 | obj-m += amdp2ptest.o 13 | 14 | ccflags-y += -I $(RDMA_HEADER_DIR) 15 | 16 | else 17 | 18 | KDIR ?= /lib/modules/$(shell uname -r)/build 19 | 20 | all: default 21 | 22 | 23 | default: 24 | @ $(MAKE) -C $(KDIR) M=$$PWD modules 25 | 26 | install: 27 | $(MAKE) -C $(KDIR) M=$$PWD modules_install 28 | 29 | help: 30 | $(MAKE) -C $(KDIR) M=$$PWD help 31 | 32 | clean: 33 | rm -rf *.o *.ko* *.mod* .*.cmd Module.symvers modules.order .tmp_versions/ *~ core .depend TAGS 34 | 35 | TAGS: 36 | find $(KERNELDIR) -follow -name \*.h -o -name \*.c |xargs etags 37 | 38 | .PHONY: clean all help install default linksyms 39 | 40 | endif 41 | -------------------------------------------------------------------------------- /hsakmt-config.cmake.in: -------------------------------------------------------------------------------- 1 | @PACKAGE_INIT@ 2 | 3 | include( CMakeFindDependencyMacro ) 4 | 5 | # Locate dependent packages here. Finding them propagates usage requirements, 6 | # if any, to our clients and ensures that their target names are in scope for 7 | # the build. hsakmt has no cmake project dependencies so there is nothing to 8 | # find. If we switch to use find_package with external (to ROCm) library 9 | # dependencies (ie libnuma) then those packages should be located here using 10 | # find_dependencies as shown below. 11 | #find_dependency(Bar, 2.0) 12 | 13 | # If the option is ON link other dependent libraries dynamically 14 | # If the option is OFF, then link libdrm and libdrm_amdgpu statically 15 | option(BUILD_SHARED_LIBS "Build using shared libraries" ON) 16 | 17 | if(BUILD_SHARED_LIBS) 18 | include( "${CMAKE_CURRENT_LIST_DIR}/@HSAKMT_TARGET@Targets.cmake" ) 19 | else() 20 | include( "${CMAKE_CURRENT_LIST_DIR}/@HSAKMT_STATIC_DRM_TARGET@Targets.cmake" ) 21 | endif() 22 | -------------------------------------------------------------------------------- /tests/rdma/simple/app/CMakeLists.txt: -------------------------------------------------------------------------------- 1 | cmake_minimum_required (VERSION 2.6) 2 | 3 | project (rdma_test) 4 | 5 | find_package(PkgConfig) 6 | pkg_check_modules(DRM REQUIRED libdrm) 7 | pkg_check_modules(DRM_AMDGPU REQUIRED libdrm_amdgpu) 8 | include_directories(${DRM_AMDGPU_INCLUDE_DIRS}) 9 | 10 | if( DEFINED ENV{LIBHSAKMT_PATH} ) 11 | set ( LIBHSAKMT_PATH $ENV{LIBHSAKMT_PATH} ) 12 | message ( "LIBHSAKMT_PATH environment variable is set" ) 13 | else() 14 | if ( ${ROCM_INSTALL_PATH} ) 15 | set ( ENV{PKG_CONFIG_PATH} ${ROCM_INSTALL_PATH}/lib/pkgconfig ) 16 | else() 17 | set ( ENV{PKG_CONFIG_PATH} /opt/rocm/lib/pkgconfig ) 18 | endif() 19 | 20 | pkg_check_modules(HSAKMT libhsakmt) 21 | 22 | if( NOT HSAKMT_FOUND ) 23 | set ( LIBHSAKMT_PATH $ENV{OUT_DIR} ) 24 | endif() 25 | endif() 26 | 27 | if( DEFINED LIBHSAKMT_PATH ) 28 | set ( HSAKMT_LIBRARY_DIRS ${LIBHSAKMT_PATH}/lib ) 29 | set ( HSAKMT_LIBRARIES hsakmt ) 30 | endif() 31 | 32 | 33 | link_directories(${HSAKMT_LIBRARY_DIRS}) 34 | 35 | include_directories($ENV{LIBHSAKMT_ROOT}/include) 36 | include_directories(../drv) 37 | 38 | add_executable(rdma_test rdma_test.cpp) 39 | target_link_libraries(rdma_test libhsakmt.a dl pthread numa drm drm_amdgpu) 40 | -------------------------------------------------------------------------------- /tests/kfdtest/src/RDMAUtil.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016-2018 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #ifndef __RDMA__UTIL__H__ 25 | #define __RDMA__UTIL__H__ 26 | 27 | class LocalMemoryAccess { 28 | public: 29 | int fd; 30 | void Open(void); 31 | void Close(void); 32 | int GetPages(uint64_t, uint64_t); 33 | void *MMap(uint64_t, size_t); 34 | void UnMap(void *, size_t); 35 | }; 36 | 37 | #endif // __RDMA__UTIL__H__ 38 | -------------------------------------------------------------------------------- /tests/kfdtest/src/KFDASMTest.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #ifndef __KFD_ASM_TEST__H__ 25 | #define __KFD_ASM_TEST__H__ 26 | 27 | #include 28 | 29 | class KFDASMTest : public testing::Test { 30 | public: 31 | KFDASMTest() {} 32 | ~KFDASMTest() {} 33 | 34 | protected: 35 | virtual void SetUp(); 36 | virtual void TearDown(); 37 | }; 38 | 39 | #endif // __KFD_ASM_TEST__H__ 40 | -------------------------------------------------------------------------------- /tests/kfdtest/src/KFDPMTest.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2018 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #ifndef __KFDPMTEST_HPP__ 25 | #define __KFDPMTEST_HPP__ 26 | 27 | #include 28 | #include "KFDBaseComponentTest.hpp" 29 | 30 | class KFDPMTest : public KFDBaseComponentTest { 31 | public: 32 | KFDPMTest() {} 33 | ~KFDPMTest() {} 34 | 35 | protected: 36 | virtual void SetUp(); 37 | virtual void TearDown(); 38 | }; 39 | 40 | #endif // __KFDPMTEST_HPP__ 41 | -------------------------------------------------------------------------------- /tests/kfdtest/src/RDMATest.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2018 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #ifndef __RDMA_TEST__H__ 25 | #define __RDMA_TEST__H__ 26 | 27 | #include 28 | 29 | #include "KFDBaseComponentTest.hpp" 30 | 31 | class RDMATest : public KFDBaseComponentTest { 32 | public: 33 | RDMATest() {} 34 | ~RDMATest() {} 35 | 36 | protected: 37 | virtual void SetUp(); 38 | virtual void TearDown(); 39 | }; 40 | 41 | #endif // __RDMA_TEST__H__ 42 | -------------------------------------------------------------------------------- /tests/kfdtest/src/KFDDBGTest.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016-2018 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #ifndef __KFD_DBG_TEST__H__ 25 | #define __KFD_DBG_TEST__H__ 26 | 27 | #include 28 | 29 | #include "KFDBaseComponentTest.hpp" 30 | 31 | class KFDDBGTest : public KFDBaseComponentTest { 32 | public: 33 | KFDDBGTest() {} 34 | ~KFDDBGTest() {} 35 | 36 | protected: 37 | virtual void SetUp(); 38 | virtual void TearDown(); 39 | }; 40 | 41 | #endif // __KFD_DBG_TEST__H__ 42 | -------------------------------------------------------------------------------- /tests/kfdtest/src/KFDGWSTest.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2019 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #ifndef __KFD_GWS_TEST__H__ 25 | #define __KFD_GWS_TEST__H__ 26 | 27 | #include 28 | 29 | #include "KFDBaseComponentTest.hpp" 30 | 31 | class KFDGWSTest : public KFDBaseComponentTest { 32 | public: 33 | KFDGWSTest() {} 34 | ~KFDGWSTest() {} 35 | 36 | protected: 37 | virtual void SetUp(); 38 | virtual void TearDown(); 39 | }; 40 | 41 | #endif // __KFD_GWS_TEST__H__ 42 | -------------------------------------------------------------------------------- /tests/kfdtest/src/KFDGraphicsInterop.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016-2018 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #include "KFDMemoryTest.hpp" 25 | 26 | #ifndef __KFD_GRAPHICS_INTEROP_TEST__H__ 27 | #define __KFD_GRAPHICS_INTEROP_TEST__H__ 28 | 29 | // @class KFDGraphicsInteropTest 30 | // Adds access to graphics device for interoperability testing 31 | class KFDGraphicsInterop : public KFDMemoryTest { 32 | public: 33 | KFDGraphicsInterop(void) {} 34 | ~KFDGraphicsInterop(void) {} 35 | }; 36 | 37 | #endif 38 | -------------------------------------------------------------------------------- /tests/kfdtest/src/KFDPCSamplingTest.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #ifndef __KFD_PCSAMPLING_TEST__H__ 25 | #define __KFD_PCSAMPLING_TEST__H__ 26 | 27 | #include "KFDMultiProcessTest.hpp" 28 | 29 | class KFDPCSamplingTest : public KFDMultiProcessTest { 30 | public: 31 | KFDPCSamplingTest(void) {} 32 | ~KFDPCSamplingTest(void) {} 33 | protected: 34 | virtual void SetUp(); 35 | virtual void TearDown(); 36 | 37 | protected: 38 | }; 39 | 40 | #endif // __KFD_PCSAMPLING_TEST__H__ 41 | -------------------------------------------------------------------------------- /tests/kfdtest/src/KFDLocalMemoryTest.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2018 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #ifndef __KFD_LOCALMEMORY_TEST__H__ 25 | #define __KFD_LOCALMEMORY_TEST__H__ 26 | 27 | #include 28 | 29 | #include "KFDBaseComponentTest.hpp" 30 | 31 | class KFDLocalMemoryTest : public KFDBaseComponentTest { 32 | public: 33 | KFDLocalMemoryTest() {} 34 | ~KFDLocalMemoryTest() {} 35 | 36 | protected: 37 | virtual void SetUp(); 38 | virtual void TearDown(); 39 | }; 40 | 41 | #endif // __KFD_LOCALMEMORY_TEST__H__ 42 | -------------------------------------------------------------------------------- /tests/kfdtest/src/XgmiOptimizedSDMAQueue.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2019 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #ifndef __KFD_XGMI_OPTIMIZED_SDMA_QUEUE__H__ 25 | #define __KFD_XGMI_OPTIMIZED_SDMA_QUEUE__H__ 26 | 27 | #include "SDMAQueue.hpp" 28 | 29 | class XgmiOptimizedSDMAQueue : public SDMAQueue { 30 | public: 31 | XgmiOptimizedSDMAQueue(void) {CMD_NOP = 0;} 32 | virtual ~XgmiOptimizedSDMAQueue(void) {} 33 | protected: 34 | virtual _HSA_QUEUE_TYPE GetQueueType() { return HSA_QUEUE_SDMA_XGMI; } 35 | }; 36 | 37 | #endif // __KFD_XGMI_OPTIMIZED_SDMA_QUEUE__H__ 38 | -------------------------------------------------------------------------------- /src/globals.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014 Advanced Micro Devices, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, copy, 8 | * modify, merge, publish, distribute, sublicense, and/or sell copies 9 | * of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice (including 13 | * the next paragraph) shall be included in all copies or substantial 14 | * portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "libhsakmt.h" 27 | 28 | // HSAKMT global data 29 | 30 | int kfd_fd = -1; 31 | unsigned long kfd_open_count; 32 | unsigned long system_properties_count; 33 | pthread_mutex_t hsakmt_mutex = PTHREAD_MUTEX_INITIALIZER; 34 | bool is_dgpu; 35 | 36 | #ifndef PAGE_SIZE 37 | int PAGE_SIZE; 38 | #endif 39 | 40 | int PAGE_SHIFT; 41 | 42 | /* whether to check all dGPUs in the topology support SVM API */ 43 | bool is_svm_api_supported; 44 | /* zfb is mainly used during emulation */ 45 | int zfb_support; 46 | -------------------------------------------------------------------------------- /tests/kfdtest/src/KFDCWSRTest.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2015-2018 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #ifndef __KFD_CWSR_TEST__H__ 25 | #define __KFD_CWSR_TEST__H__ 26 | 27 | #include 28 | 29 | #include "PM4Queue.hpp" 30 | #include "KFDBaseComponentTest.hpp" 31 | 32 | class KFDCWSRTest : public KFDBaseComponentTest, 33 | public ::testing::WithParamInterface> { 34 | public: 35 | KFDCWSRTest() {} 36 | ~KFDCWSRTest() {} 37 | 38 | protected: 39 | virtual void SetUp(); 40 | virtual void TearDown(); 41 | }; 42 | 43 | #endif // __KFD_CWSR_TEST__H__ 44 | -------------------------------------------------------------------------------- /tests/kfdtest/src/KFDHWSTest.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #ifndef __KFD_HWS_TEST__H__ 25 | #define __KFD_HWS_TEST__H__ 26 | 27 | #include 28 | 29 | #include "PM4Queue.hpp" 30 | #include "KFDMultiProcessTest.hpp" 31 | #include "Dispatch.hpp" 32 | 33 | class KFDHWSTest : public KFDMultiProcessTest { 34 | public: 35 | KFDHWSTest() {} 36 | ~KFDHWSTest() {} 37 | 38 | protected: 39 | virtual void SetUp(); 40 | virtual void TearDown(); 41 | 42 | void RunTest(unsigned nProcesses, unsigned nQueues, unsigned nLoops); 43 | }; 44 | 45 | #endif // __KFD_QCM_TEST__H__ 46 | -------------------------------------------------------------------------------- /tests/kfdtest/src/KFDSVMRangeTest.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #ifndef __KFD_SVMRANGE_TEST__H__ 25 | #define __KFD_SVMRANGE_TEST__H__ 26 | 27 | #include 28 | 29 | #include "KFDBaseComponentTest.hpp" 30 | 31 | class KFDSVMRangeTest : public KFDBaseComponentTest, 32 | public ::testing::WithParamInterface { 33 | public: 34 | KFDSVMRangeTest() {} 35 | ~KFDSVMRangeTest() {} 36 | void SplitRangeTest(int defaultGPUNode, int prefetch_location); 37 | 38 | protected: 39 | virtual void SetUp(); 40 | virtual void TearDown(); 41 | }; 42 | 43 | #endif // __KFD_LOCALMEMORY_TEST__H__ 44 | -------------------------------------------------------------------------------- /tests/kfdtest/src/KFDTopologyTest.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2018 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #include "KFDBaseComponentTest.hpp" 25 | 26 | #ifndef __KFD_TOPOLOGY_TEST__H__ 27 | #define __KFD_TOPOLOGY_TEST__H__ 28 | 29 | /* @class KFDTopologyTest 30 | * This class has no additional features to KFDBaseComponentTest 31 | * The separation was made so we are able to group all topology tests together 32 | */ 33 | class KFDTopologyTest : public KFDBaseComponentTest { 34 | public: 35 | KFDTopologyTest(void) {} 36 | ~KFDTopologyTest(void) {} 37 | static const HSAuint64 c_4Gigabyte; 38 | static const HSAuint64 c_40BitAddressSpace; 39 | }; 40 | 41 | #endif // __KFD_TOPOLOGY_TEST__H__ 42 | -------------------------------------------------------------------------------- /tests/kfdtest/src/KFDEventTest.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2018 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #include "KFDBaseComponentTest.hpp" 25 | 26 | #ifndef __KFD_EVENT_TEST__H__ 27 | #define __KFD_EVENT_TEST__H__ 28 | 29 | class KFDEventTest : public KFDBaseComponentTest { 30 | public: 31 | KFDEventTest(void) {} 32 | ~KFDEventTest(void) {} 33 | 34 | // @brief Executed before every test in KFDEventTest. 35 | virtual void SetUp(); 36 | // @brief Executed after every test in KFDEventTest. 37 | virtual void TearDown(); 38 | 39 | protected: 40 | static const unsigned int EVENT_TIMEOUT = 5000; // 5 seconds 41 | HsaEvent* m_pHsaEvent; 42 | }; 43 | 44 | #endif // __KFD_EVENT_TEST__H__ 45 | -------------------------------------------------------------------------------- /tests/kfdtest/src/AqlQueue.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2018 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #include "AqlQueue.hpp" 25 | #include "GoogleTestExtension.hpp" 26 | 27 | 28 | AqlQueue::AqlQueue(void) { 29 | } 30 | 31 | 32 | AqlQueue::~AqlQueue(void) { 33 | } 34 | 35 | unsigned int AqlQueue::Wptr() { 36 | return *m_Resources.Queue_write_ptr; 37 | } 38 | 39 | unsigned int AqlQueue::Rptr() { 40 | return *m_Resources.Queue_read_ptr; 41 | } 42 | 43 | unsigned int AqlQueue::RptrWhenConsumed() { 44 | return Wptr(); 45 | } 46 | 47 | void AqlQueue::SubmitPacket() { 48 | // m_pending Wptr is in dwords 49 | *m_Resources.Queue_write_ptr = m_pendingWptr; 50 | *(m_Resources.Queue_DoorBell) = Wptr(); 51 | } 52 | 53 | -------------------------------------------------------------------------------- /tests/kfdtest/src/KFDPerfCounters.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2018 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #ifndef __KFDPERFCOUNTERS_HPP__ 25 | #define __KFDPERFCOUNTERS_HPP__ 26 | 27 | #include 28 | #include "KFDBaseComponentTest.hpp" 29 | 30 | class KFDPerfCountersTest : public KFDBaseComponentTest { 31 | public: 32 | KFDPerfCountersTest() {} 33 | ~KFDPerfCountersTest() {} 34 | 35 | static const unsigned int START_STOP_DELAY = 10000; // 10 sec tracing 36 | 37 | protected: 38 | virtual void SetUp(); 39 | virtual void TearDown(); 40 | void GetBlockName(HSA_UUID uuid, char *name, uint32_t name_len, 41 | char *uuid_str, uint32_t uuid_str_len); 42 | }; 43 | 44 | #endif // __KFDPERFCOUNTERS_HPP__ 45 | -------------------------------------------------------------------------------- /tests/kfdtest/src/KFDOpenCloseKFDTest.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2018 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #include 25 | #include "hsakmt/hsakmt.h" 26 | 27 | #ifndef __KFD_OPEN_CLOSE_KFD_TEST__H__ 28 | #define __KFD_OPEN_CLOSE_KFD_TEST__H__ 29 | 30 | // @class KFDOpenCloseKFDTest 31 | class KFDOpenCloseKFDTest : public testing::Test { 32 | public: 33 | KFDOpenCloseKFDTest(void) {} 34 | ~KFDOpenCloseKFDTest(void) {} 35 | 36 | protected: 37 | // @brief Executed before every test that uses KFDOpenCloseKFDTest class, sets all common settings for the tests. 38 | virtual void SetUp(); 39 | // @brief Executed after every test that uses KFDOpenCloseKFDTest class 40 | virtual void TearDown(); 41 | }; 42 | 43 | #endif // __KFD_OPEN_CLOSE_KFD_TEST__H__ 44 | -------------------------------------------------------------------------------- /src/version.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014 Advanced Micro Devices, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, copy, 8 | * modify, merge, publish, distribute, sublicense, and/or sell copies 9 | * of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice (including 13 | * the next paragraph) shall be included in all copies or substantial 14 | * portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "libhsakmt.h" 27 | #include 28 | #include 29 | #include "hsakmt/linux/kfd_ioctl.h" 30 | 31 | HsaVersionInfo kfd_version_info; 32 | 33 | HSAKMT_STATUS HSAKMTAPI hsaKmtGetVersion(HsaVersionInfo *VersionInfo) 34 | { 35 | CHECK_KFD_OPEN(); 36 | 37 | *VersionInfo = kfd_version_info; 38 | 39 | return HSAKMT_STATUS_SUCCESS; 40 | } 41 | 42 | HSAKMT_STATUS init_kfd_version(void) 43 | { 44 | struct kfd_ioctl_get_version_args args = {0}; 45 | 46 | if (kmtIoctl(kfd_fd, AMDKFD_IOC_GET_VERSION, &args) == -1) 47 | return HSAKMT_STATUS_ERROR; 48 | 49 | kfd_version_info.KernelInterfaceMajorVersion = args.major_version; 50 | kfd_version_info.KernelInterfaceMinorVersion = args.minor_version; 51 | 52 | if (args.major_version != 1) 53 | return HSAKMT_STATUS_DRIVER_MISMATCH; 54 | 55 | return HSAKMT_STATUS_SUCCESS; 56 | } 57 | -------------------------------------------------------------------------------- /tests/kfdtest/src/AqlQueue.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2018 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #ifndef __KFD_AQL_QUEUE__H__ 25 | #define __KFD_AQL_QUEUE__H__ 26 | 27 | #include "BaseQueue.hpp" 28 | 29 | class AqlQueue : public BaseQueue { 30 | public: 31 | AqlQueue(); 32 | virtual ~AqlQueue(); 33 | 34 | // @brief Updates queue write pointer and sets the queue doorbell to the queue write pointer 35 | virtual void SubmitPacket(); 36 | 37 | // @return Read pointer in dwords 38 | virtual unsigned int Rptr(); 39 | // @return Write pointer in dwords 40 | virtual unsigned int Wptr(); 41 | // @return Expected m_Resources.Queue_read_ptr when all packets are consumed 42 | virtual unsigned int RptrWhenConsumed(); 43 | 44 | protected: 45 | virtual PACKETTYPE PacketTypeSupported() { return PACKETTYPE_AQL; } 46 | 47 | virtual _HSA_QUEUE_TYPE GetQueueType() { return HSA_QUEUE_COMPUTE_AQL; } 48 | }; 49 | 50 | #endif // __KFD_AQL_QUEUE__H__ 51 | -------------------------------------------------------------------------------- /src/time.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014 Advanced Micro Devices, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, copy, 8 | * modify, merge, publish, distribute, sublicense, and/or sell copies 9 | * of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice (including 13 | * the next paragraph) shall be included in all copies or substantial 14 | * portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "libhsakmt.h" 27 | #include "hsakmt/linux/kfd_ioctl.h" 28 | 29 | HSAKMT_STATUS HSAKMTAPI hsaKmtGetClockCounters(HSAuint32 NodeId, 30 | HsaClockCounters *Counters) 31 | { 32 | HSAKMT_STATUS result; 33 | uint32_t gpu_id; 34 | struct kfd_ioctl_get_clock_counters_args args = {0}; 35 | int err; 36 | 37 | CHECK_KFD_OPEN(); 38 | 39 | result = validate_nodeid(NodeId, &gpu_id); 40 | if (result != HSAKMT_STATUS_SUCCESS) 41 | return result; 42 | 43 | args.gpu_id = gpu_id; 44 | 45 | err = kmtIoctl(kfd_fd, AMDKFD_IOC_GET_CLOCK_COUNTERS, &args); 46 | if (err < 0) { 47 | result = HSAKMT_STATUS_ERROR; 48 | } else { 49 | /* At this point the result is already HSAKMT_STATUS_SUCCESS */ 50 | Counters->GPUClockCounter = args.gpu_clock_counter; 51 | Counters->CPUClockCounter = args.cpu_clock_counter; 52 | Counters->SystemClockCounter = args.system_clock_counter; 53 | Counters->SystemClockFrequencyHz = args.system_clock_freq; 54 | } 55 | 56 | return result; 57 | } 58 | -------------------------------------------------------------------------------- /tests/kfdtest/src/BasePacket.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2018 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #ifndef __KFD_BASE_PACKET__H__ 25 | #define __KFD_BASE_PACKET__H__ 26 | 27 | /** 28 | * All packets profiles must be defined here 29 | * Every type defined here has sub-types 30 | */ 31 | enum PACKETTYPE { 32 | PACKETTYPE_PM4, 33 | PACKETTYPE_SDMA, 34 | PACKETTYPE_AQL 35 | }; 36 | 37 | // @class BasePacket 38 | class BasePacket { 39 | public: 40 | BasePacket(void); 41 | virtual ~BasePacket(void); 42 | 43 | // @returns Packet type 44 | virtual PACKETTYPE PacketType() const = 0; 45 | // @returns Pointer to the packet 46 | virtual const void *GetPacket() const = 0; 47 | // @returns Packet size in bytes 48 | virtual unsigned int SizeInBytes() const = 0; 49 | // @returns Packet size in dwordS 50 | unsigned int SizeInDWords() const { return SizeInBytes()/sizeof(unsigned int); } 51 | 52 | void Dump() const; 53 | 54 | protected: 55 | unsigned int m_FamilyId; 56 | void *m_packetAllocation; 57 | 58 | void *AllocPacket(void); 59 | }; 60 | 61 | #endif // __KFD_BASE_PACKET__H__ 62 | -------------------------------------------------------------------------------- /tests/kfdtest/src/KFDRASTest.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #include "KFDBaseComponentTest.hpp" 25 | 26 | #ifndef __KFD_RAS_TEST__H__ 27 | #define __KFD_RAS_TEST__H__ 28 | 29 | // To be removed when amdgpu_drm.h updated with those definitions 30 | #ifndef AMDGPU_INFO_RAS_ENABLED_FEATURES 31 | #define AMDGPU_INFO_RAS_ENABLED_FEATURES 0x20 32 | 33 | #define AMDGPU_INFO_RAS_ENABLED_UMC (1 << 0) 34 | #define AMDGPU_INFO_RAS_ENABLED_SDMA (1 << 1) 35 | #define AMDGPU_INFO_RAS_ENABLED_GFX (1 << 2) 36 | #endif 37 | 38 | class KFDRASTest : public KFDBaseComponentTest { 39 | public: 40 | KFDRASTest(void) {} 41 | ~KFDRASTest(void) {} 42 | 43 | // @brief Executed before every test in KFDRASTest. 44 | virtual void SetUp(); 45 | // @brief Executed after every test in KFDRASTest. 46 | virtual void TearDown(); 47 | 48 | protected: 49 | static const unsigned int EVENT_TIMEOUT = 5000; // 5 seconds 50 | HsaEvent* m_pRasEvent; 51 | HSAint32 m_defaultGPUNode; 52 | FILE* m_pFile; 53 | bool m_setupStatus; 54 | }; 55 | 56 | #endif // __KFD_RAS_TEST__H__ 57 | -------------------------------------------------------------------------------- /tests/kfdtest/src/BasePacket.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017-2018 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #include "BasePacket.hpp" 25 | #include "KFDTestUtil.hpp" 26 | #include "KFDBaseComponentTest.hpp" 27 | 28 | BasePacket::BasePacket(void): m_packetAllocation(NULL) { 29 | m_FamilyId = g_baseTest->GetFamilyIdFromDefaultNode(); 30 | } 31 | 32 | BasePacket::~BasePacket(void) { 33 | if (m_packetAllocation) 34 | free(m_packetAllocation); 35 | } 36 | 37 | void BasePacket::Dump() const { 38 | unsigned int size = SizeInDWords(); 39 | const HSAuint32 *packet = (const HSAuint32 *)GetPacket(); 40 | std::ostream &log = LOG(); 41 | unsigned int i; 42 | 43 | log << "Packet dump:" << std::hex; 44 | for (i = 0; i < size; i++) 45 | log << " " << std::setw(8) << std::setfill('0') << packet[i]; 46 | log << std::endl; 47 | } 48 | 49 | void *BasePacket::AllocPacket(void) { 50 | unsigned int size = SizeInBytes(); 51 | 52 | EXPECT_NE(0, size); 53 | if (!size) 54 | return NULL; 55 | 56 | m_packetAllocation = calloc(1, size); 57 | EXPECT_NOTNULL(m_packetAllocation); 58 | 59 | return m_packetAllocation; 60 | } 61 | -------------------------------------------------------------------------------- /tests/kfdtest/src/KFDQMTest.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2018 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #ifndef __KFD_QCM_TEST__H__ 25 | #define __KFD_QCM_TEST__H__ 26 | 27 | #include 28 | 29 | #include "PM4Queue.hpp" 30 | #include "KFDBaseComponentTest.hpp" 31 | #include "Dispatch.hpp" 32 | 33 | class KFDQMTest : public KFDBaseComponentTest { 34 | public: 35 | KFDQMTest() {} 36 | 37 | ~KFDQMTest() {} 38 | 39 | protected: 40 | virtual void SetUp(); 41 | virtual void TearDown(); 42 | 43 | void SyncDispatch(const HsaMemoryBuffer& isaBuffer, void* pSrcBuf, void* pDstBuf, int node = -1); 44 | HSAint64 TimeConsumedwithCUMask(int node, uint32_t *mask, uint32_t mask_count); 45 | HSAint64 GetAverageTimeConsumedwithCUMask(int node, uint32_t *mask, uint32_t mask_count, int iterations); 46 | void testQueuePriority(bool isSamePipe); 47 | protected: // Members 48 | /* Acceptable performance for CU Masking should be within 5% of linearly-predicted performance */ 49 | const double CuVariance = 0.15; 50 | const double CuNegVariance = 1.0 - CuVariance; 51 | const double CuPosVariance = 1.0 + CuVariance; 52 | }; 53 | 54 | #endif // __KFD_QCM_TEST__H__ 55 | -------------------------------------------------------------------------------- /tests/kfdtest/src/KFDMemoryTest.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2018 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #include "KFDBaseComponentTest.hpp" 25 | 26 | #ifndef __KFD_MEMORY_TEST__H__ 27 | #define __KFD_MEMORY_TEST__H__ 28 | 29 | /* @class KFDTopologyTest 30 | * This class has no additional features to KFDBaseComponentTest 31 | * The separation was made so we are able to group all memory tests together 32 | */ 33 | class KFDMemoryTest : public KFDBaseComponentTest { 34 | public: 35 | KFDMemoryTest(void) {} 36 | ~KFDMemoryTest(void) {} 37 | protected: 38 | virtual void SetUp(); 39 | virtual void TearDown(); 40 | 41 | protected: 42 | void SearchLargestBuffer(int allocNode, const HsaMemFlags &memFlags, 43 | HSAuint64 highMB, int nodeToMap, 44 | HSAuint64 *lastSizeMB); 45 | void AcquireReleaseTestRunCPU(HSAuint32 acquireNode, bool scalar); 46 | void AcquireReleaseTestRun(HSAuint32 acquireNode, HSAuint32 releaseNode, 47 | bool localToRemote, bool scalar); 48 | void AcquireReleaseTest(bool withinGPU, bool localToRemote, bool scalar); 49 | }; 50 | 51 | #endif // __KFD_MEMORY_TEST__H__ 52 | -------------------------------------------------------------------------------- /tests/kfdtest/src/KFDASMTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2022 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #include "GoogleTestExtension.hpp" 25 | #include "KFDASMTest.hpp" 26 | #include "ShaderStore.hpp" 27 | #include "Assemble.hpp" 28 | 29 | void KFDASMTest::SetUp() {} 30 | void KFDASMTest::TearDown() {} 31 | 32 | static const std::vector TargetList = { 33 | 0x080001, 34 | 0x080002, 35 | 0x080003, 36 | 0x080005, 37 | 0x080100, 38 | 0x090000, 39 | 0x090002, 40 | 0x090004, 41 | 0x090006, 42 | 0x090008, 43 | 0x090009, 44 | 0x09000a, 45 | 0x09000c, 46 | 0x090400, 47 | 0x0a0100, 48 | 0x0a0101, 49 | 0x0a0102, 50 | 0x0a0103, 51 | 0x0a0300, 52 | 0x0a0301, 53 | 0x0a0302, 54 | 0x0a0303, 55 | 0x0a0304, 56 | 0x0a0305, 57 | 0x0a0306, 58 | }; 59 | 60 | TEST_F(KFDASMTest, AssembleShaders) { 61 | TEST_START(TESTPROFILE_RUNALL) 62 | 63 | for (auto &t : TargetList) { 64 | Assembler asmblr(t); 65 | 66 | LOG() << "Running ASM test for target " << asmblr.GetTargetAsic() << std::endl; 67 | 68 | for (auto &s : ShaderList) { 69 | EXPECT_SUCCESS(asmblr.RunAssemble(s)); 70 | } 71 | } 72 | 73 | TEST_END 74 | } 75 | -------------------------------------------------------------------------------- /tests/kfdtest/src/KFDEvictTest.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017-2018 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #ifndef __KFD_EVICT_TEST__H__ 25 | #define __KFD_EVICT_TEST__H__ 26 | 27 | #include 28 | #include 29 | #include "KFDMultiProcessTest.hpp" 30 | #include "PM4Queue.hpp" 31 | 32 | // @class KFDEvictTest 33 | // Test eviction and restore procedure using two processes 34 | class KFDEvictTest : public KFDMultiProcessTest { 35 | public: 36 | KFDEvictTest(void) {} 37 | ~KFDEvictTest(void) {} 38 | 39 | protected: 40 | virtual void SetUp(); 41 | virtual void TearDown(); 42 | 43 | void AllocBuffers(HSAuint32 defaultGPUNode, HSAuint32 count, HSAuint64 vramBufSize, 44 | std::vector &pBuffers); 45 | void FreeBuffers(std::vector &pBuffers, HSAuint64 vramBufSize); 46 | void AllocAmdgpuBo(int rn, HSAuint64 vramBufSize, amdgpu_bo_handle &handle); 47 | void FreeAmdgpuBo(amdgpu_bo_handle handle); 48 | void AmdgpuCommandSubmissionSdmaNop(int rn, amdgpu_bo_handle handle, 49 | PM4Queue *computeQueue); 50 | 51 | protected: // Members 52 | HsaMemFlags m_Flags; 53 | void* m_pBuf; 54 | }; 55 | 56 | #endif // __KFD_EVICT_TEST__H__ 57 | -------------------------------------------------------------------------------- /tests/kfdtest/src/RDMAUtil.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2016-2018 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include "amdp2ptest.h" 34 | #include "RDMAUtil.hpp" 35 | 36 | void LocalMemoryAccess::Open() { 37 | fd = open(AMDP2PTEST_DEVICE_PATH, O_RDWR); 38 | } 39 | 40 | void LocalMemoryAccess::Close() { 41 | close(fd); 42 | fd = -1; 43 | } 44 | 45 | int LocalMemoryAccess::GetPages(uint64_t gpu_va_addr, uint64_t size) { 46 | struct AMDRDMA_IOCTL_GET_PAGES_PARAM param = {0}; 47 | 48 | if (fd <= 0) 49 | return -1; 50 | 51 | param.addr = gpu_va_addr; 52 | param.length = size; 53 | 54 | return ioctl(fd, AMD2P2PTEST_IOCTL_GET_PAGES, ¶m); 55 | } 56 | 57 | void *LocalMemoryAccess::MMap(uint64_t offset, size_t size) { 58 | void *gpuAddr; 59 | 60 | if (fd <= 0) 61 | return NULL; 62 | 63 | gpuAddr = mmap(NULL, size, PROT_READ, MAP_SHARED, fd, offset); 64 | return gpuAddr; 65 | } 66 | 67 | void LocalMemoryAccess::UnMap(void *offset, size_t size) { 68 | munmap(offset, size); 69 | } 70 | -------------------------------------------------------------------------------- /tests/kfdtest/src/KFDMultiProcessTest.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #ifndef __KFD_MULTI_PROCESS_TEST__H__ 25 | #define __KFD_MULTI_PROCESS_TEST__H__ 26 | 27 | #include 28 | #include 29 | #include "KFDBaseComponentTest.hpp" 30 | 31 | // @class KFDMultiProcessTest 32 | // Base class for tests forking multiple child processes 33 | class KFDMultiProcessTest : public KFDBaseComponentTest { 34 | public: 35 | KFDMultiProcessTest(void): m_ChildStatus(HSAKMT_STATUS_ERROR), m_IsParent(true) {} 36 | 37 | ~KFDMultiProcessTest(void) { 38 | if (!m_IsParent) { 39 | /* Child process has to exit 40 | * otherwise gtest will continue other tests 41 | */ 42 | exit(m_ChildStatus); 43 | } 44 | 45 | try { 46 | WaitChildProcesses(); 47 | } catch (...) {} 48 | } 49 | 50 | protected: 51 | void ForkChildProcesses(int nprocesses); 52 | void WaitChildProcesses(); 53 | 54 | protected: // Members 55 | std::string m_psName; 56 | int m_ProcessIndex; 57 | std::vector m_ChildPids; 58 | HSAKMT_STATUS m_ChildStatus; 59 | bool m_IsParent; 60 | }; 61 | 62 | #endif // __KFD_MULTI_PROCESS_TEST__H__ 63 | -------------------------------------------------------------------------------- /src/libhsakmt.ver: -------------------------------------------------------------------------------- 1 | HSAKMT_1 2 | { 3 | global: 4 | hsaKmtOpenKFD; 5 | hsaKmtCloseKFD; 6 | hsaKmtGetVersion; 7 | hsaKmtAcquireSystemProperties; 8 | hsaKmtReleaseSystemProperties; 9 | hsaKmtGetNodeProperties; 10 | hsaKmtGetNodeMemoryProperties; 11 | hsaKmtGetNodeCacheProperties; 12 | hsaKmtGetNodeIoLinkProperties; 13 | hsaKmtCreateEvent; 14 | hsaKmtDestroyEvent; 15 | hsaKmtSetEvent; 16 | hsaKmtResetEvent; 17 | hsaKmtQueryEventState; 18 | hsaKmtWaitOnEvent; 19 | hsaKmtWaitOnMultipleEvents; 20 | hsaKmtCreateQueue; 21 | hsaKmtUpdateQueue; 22 | hsaKmtDestroyQueue; 23 | hsaKmtSetQueueCUMask; 24 | hsaKmtSetMemoryPolicy; 25 | hsaKmtAllocMemory; 26 | hsaKmtFreeMemory; 27 | hsaKmtAvailableMemory; 28 | hsaKmtRegisterMemory; 29 | hsaKmtRegisterMemoryToNodes; 30 | hsaKmtRegisterMemoryWithFlags; 31 | hsaKmtRegisterGraphicsHandleToNodes; 32 | hsaKmtShareMemory; 33 | hsaKmtRegisterSharedHandle; 34 | hsaKmtRegisterSharedHandleToNodes; 35 | hsaKmtProcessVMRead; 36 | hsaKmtProcessVMWrite; 37 | hsaKmtDeregisterMemory; 38 | hsaKmtMapMemoryToGPU; 39 | hsaKmtMapMemoryToGPUNodes; 40 | hsaKmtUnmapMemoryToGPU; 41 | hsaKmtDbgRegister; 42 | hsaKmtDbgUnregister; 43 | hsaKmtDbgWavefrontControl; 44 | hsaKmtDbgAddressWatch; 45 | hsaKmtDbgEnable; 46 | hsaKmtDbgDisable; 47 | hsaKmtDbgGetDeviceData; 48 | hsaKmtDbgGetQueueData; 49 | hsaKmtGetClockCounters; 50 | hsaKmtPmcGetCounterProperties; 51 | hsaKmtPmcRegisterTrace; 52 | hsaKmtPmcUnregisterTrace; 53 | hsaKmtPmcAcquireTraceAccess; 54 | hsaKmtPmcReleaseTraceAccess; 55 | hsaKmtPmcStartTrace; 56 | hsaKmtPmcQueryTrace; 57 | hsaKmtPmcStopTrace; 58 | hsaKmtMapGraphicHandle; 59 | hsaKmtUnmapGraphicHandle; 60 | hsaKmtSetTrapHandler; 61 | hsaKmtGetTileConfig; 62 | hsaKmtQueryPointerInfo; 63 | hsaKmtSetMemoryUserData; 64 | hsaKmtGetQueueInfo; 65 | hsaKmtAllocQueueGWS; 66 | hsaKmtRuntimeEnable; 67 | hsaKmtRuntimeDisable; 68 | hsaKmtCheckRuntimeDebugSupport; 69 | hsaKmtGetRuntimeCapabilities; 70 | hsaKmtDebugTrapIoctl; 71 | hsaKmtSPMAcquire; 72 | hsaKmtSPMRelease; 73 | hsaKmtSPMSetDestBuffer; 74 | hsaKmtSVMSetAttr; 75 | hsaKmtSVMGetAttr; 76 | hsaKmtSetXNACKMode; 77 | hsaKmtGetXNACKMode; 78 | hsaKmtOpenSMI; 79 | hsaKmtExportDMABufHandle; 80 | hsaKmtWaitOnEvent_Ext; 81 | hsaKmtWaitOnMultipleEvents_Ext; 82 | hsaKmtReplaceAsanHeaderPage; 83 | hsaKmtReturnAsanHeaderPage; 84 | hsaKmtGetAMDGPUDeviceHandle; 85 | hsaKmtPcSamplingQueryCapabilities; 86 | hsaKmtPcSamplingCreate; 87 | hsaKmtPcSamplingDestroy; 88 | hsaKmtPcSamplingStart; 89 | hsaKmtPcSamplingStop; 90 | 91 | local: *; 92 | }; 93 | 94 | -------------------------------------------------------------------------------- /tests/rdma/simple/drv/amdp2ptest.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015 Advanced Micro Devices, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | #ifndef AMDP2PTEST_H_ 23 | #define AMDP2PTEST_H_ 24 | 25 | #include 26 | 27 | #define AMDP2PTEST_IOCTL_MAGIC 'A' 28 | 29 | 30 | #define AMDP2PTEST_DEVICE_NAME "amdp2ptest" 31 | #define AMDP2PTEST_DEVICE_PATH "/dev/amdp2ptest" 32 | 33 | struct AMDRDMA_IOCTL_GET_PAGE_SIZE_PARAM { 34 | /* Input parameters */ 35 | uint64_t addr; 36 | uint64_t length; 37 | 38 | /* Output parameters */ 39 | uint64_t page_size; 40 | }; 41 | 42 | struct AMDRDMA_IOCTL_GET_PAGES_PARAM { 43 | /* Input parameters */ 44 | uint64_t addr; 45 | uint64_t length; 46 | uint64_t is_local; /* 1 if this is the pointer to local 47 | allocation */ 48 | 49 | /* Output parameters */ 50 | uint64_t cpu_ptr; 51 | }; 52 | 53 | 54 | struct AMDRDMA_IOCTL_PUT_PAGES_PARAM { 55 | /* Input parameters */ 56 | uint64_t addr; 57 | uint64_t length; 58 | }; 59 | 60 | 61 | #define AMD2P2PTEST_IOCTL_GET_PAGE_SIZE \ 62 | _IOWR(AMDP2PTEST_IOCTL_MAGIC, 1, struct AMDRDMA_IOCTL_GET_PAGE_SIZE_PARAM *) 63 | 64 | #define AMD2P2PTEST_IOCTL_GET_PAGES \ 65 | _IOWR(AMDP2PTEST_IOCTL_MAGIC, 2, struct AMDRDMA_IOCTL_GET_PAGES_PARAM *) 66 | 67 | #define AMD2P2PTEST_IOCTL_PUT_PAGES \ 68 | _IOW(AMDP2PTEST_IOCTL_MAGIC, 3, struct AMDRDMA_IOCTL_PUT_PAGES_PARAM *) 69 | 70 | 71 | #endif /* AMDP2PTEST_H */ 72 | -------------------------------------------------------------------------------- /tests/kfdtest/include/amdp2ptest.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2015-2024 Advanced Micro Devices, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | */ 22 | #ifndef AMDP2PTEST_H_ 23 | #define AMDP2PTEST_H_ 24 | 25 | #include 26 | 27 | #define AMDP2PTEST_IOCTL_MAGIC 'A' 28 | 29 | 30 | #define AMDP2PTEST_DEVICE_NAME "amdp2ptest" 31 | #define AMDP2PTEST_DEVICE_PATH "/dev/amdp2ptest" 32 | 33 | struct AMDRDMA_IOCTL_GET_PAGE_SIZE_PARAM { 34 | /* Input parameters */ 35 | uint64_t addr; 36 | uint64_t length; 37 | 38 | /* Output parameters */ 39 | uint64_t page_size; 40 | }; 41 | 42 | struct AMDRDMA_IOCTL_GET_PAGES_PARAM { 43 | /* Input parameters */ 44 | uint64_t addr; 45 | uint64_t length; 46 | uint64_t is_local; /* 1 if this is the pointer to local 47 | allocation */ 48 | 49 | /* Output parameters */ 50 | uint64_t cpu_ptr; 51 | }; 52 | 53 | 54 | struct AMDRDMA_IOCTL_PUT_PAGES_PARAM { 55 | /* Input parameters */ 56 | uint64_t addr; 57 | uint64_t length; 58 | }; 59 | 60 | 61 | #define AMD2P2PTEST_IOCTL_GET_PAGE_SIZE \ 62 | _IOWR(AMDP2PTEST_IOCTL_MAGIC, 1, struct AMDRDMA_IOCTL_GET_PAGE_SIZE_PARAM *) 63 | 64 | #define AMD2P2PTEST_IOCTL_GET_PAGES \ 65 | _IOWR(AMDP2PTEST_IOCTL_MAGIC, 2, struct AMDRDMA_IOCTL_GET_PAGES_PARAM *) 66 | 67 | #define AMD2P2PTEST_IOCTL_PUT_PAGES \ 68 | _IOW(AMDP2PTEST_IOCTL_MAGIC, 3, struct AMDRDMA_IOCTL_PUT_PAGES_PARAM *) 69 | 70 | 71 | #endif /* AMDP2PTEST_H */ 72 | -------------------------------------------------------------------------------- /tests/kfdtest/src/IndirectBuffer.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2018 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #include "IndirectBuffer.hpp" 25 | #include "GoogleTestExtension.hpp" 26 | #include "pm4_pkt_struct_common.h" 27 | #include "PM4Packet.hpp" 28 | 29 | 30 | IndirectBuffer::IndirectBuffer(PACKETTYPE type, unsigned int sizeInDWords, unsigned int NodeId) 31 | :m_NumOfPackets(0), m_MaxSize(sizeInDWords), m_ActualSize(0), m_PacketTypeAllowed(type) { 32 | m_IndirectBuf = new HsaMemoryBuffer(sizeInDWords*sizeof(unsigned int), NodeId, true/*zero*/, 33 | false/*local*/, true/*exec*/, false/*isScratch*/, 34 | false/*isReadOnly*/, true/*isUncached*/); 35 | } 36 | 37 | IndirectBuffer::~IndirectBuffer(void) { 38 | delete m_IndirectBuf; 39 | } 40 | 41 | uint32_t *IndirectBuffer::AddPacket(const BasePacket &packet) { 42 | EXPECT_EQ(packet.PacketType(), m_PacketTypeAllowed) << "Cannot add a packet since packet type doesn't match queue"; 43 | 44 | unsigned int writePtr = m_ActualSize; 45 | 46 | EXPECT_GE(m_MaxSize, packet.SizeInDWords() + writePtr) << "Cannot add a packet, not enough room"; 47 | 48 | memcpy(m_IndirectBuf->As() + writePtr , packet.GetPacket(), packet.SizeInBytes()); 49 | m_ActualSize += packet.SizeInDWords(); 50 | m_NumOfPackets++; 51 | 52 | return m_IndirectBuf->As() + writePtr; 53 | } 54 | -------------------------------------------------------------------------------- /src/pmc_table.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014 Advanced Micro Devices, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, copy, 8 | * modify, merge, publish, distribute, sublicense, and/or sell copies 9 | * of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice (including 13 | * the next paragraph) shall be included in all copies or substantial 14 | * portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef PMC_TABLE_H 27 | #define PMC_TABLE_H 28 | 29 | #include "libhsakmt.h" 30 | 31 | enum perf_block_id { 32 | PERFCOUNTER_BLOCKID__FIRST = 0, 33 | /* non-privileged */ 34 | PERFCOUNTER_BLOCKID__CB = PERFCOUNTER_BLOCKID__FIRST, 35 | PERFCOUNTER_BLOCKID__CPC, 36 | PERFCOUNTER_BLOCKID__CPF, 37 | PERFCOUNTER_BLOCKID__CPG, 38 | PERFCOUNTER_BLOCKID__DB, 39 | PERFCOUNTER_BLOCKID__GDS, 40 | PERFCOUNTER_BLOCKID__GRBM, 41 | PERFCOUNTER_BLOCKID__GRBMSE, 42 | PERFCOUNTER_BLOCKID__IA, 43 | PERFCOUNTER_BLOCKID__MC, 44 | PERFCOUNTER_BLOCKID__PASC, 45 | PERFCOUNTER_BLOCKID__PASU, 46 | PERFCOUNTER_BLOCKID__SPI, 47 | PERFCOUNTER_BLOCKID__SRBM, 48 | PERFCOUNTER_BLOCKID__SQ, 49 | PERFCOUNTER_BLOCKID__SX, 50 | PERFCOUNTER_BLOCKID__TA, 51 | PERFCOUNTER_BLOCKID__TCA, 52 | PERFCOUNTER_BLOCKID__TCC, 53 | PERFCOUNTER_BLOCKID__TCP, 54 | PERFCOUNTER_BLOCKID__TCS, 55 | PERFCOUNTER_BLOCKID__TD, 56 | PERFCOUNTER_BLOCKID__VGT, 57 | PERFCOUNTER_BLOCKID__WD, 58 | /* privileged */ 59 | PERFCOUNTER_BLOCKID__MAX 60 | }; 61 | 62 | struct perf_counter_block { 63 | uint32_t num_of_slots; 64 | uint32_t num_of_counters; 65 | uint32_t *counter_ids; 66 | uint32_t counter_size_in_bits; 67 | uint64_t counter_mask; 68 | }; 69 | 70 | HSAKMT_STATUS get_block_properties(uint32_t node_id, 71 | enum perf_block_id block_id, 72 | struct perf_counter_block *block); 73 | 74 | #endif // PMC_TABLE_H 75 | -------------------------------------------------------------------------------- /RPM/hsakmt-roct-devel.spec.in: -------------------------------------------------------------------------------- 1 | # Restore old style debuginfo creation for rpm >= 4.14. 2 | %undefine _debugsource_packages 3 | %undefine _debuginfo_subpackages 4 | 5 | # -*- rpm-spec -*- 6 | BuildRoot: %_topdir/@CPACK_PACKAGE_FILE_NAME@@CPACK_RPM_PACKAGE_COMPONENT_PART_PATH@ 7 | Summary: @CPACK_RPM_PACKAGE_SUMMARY@ 8 | Name: @CPACK_RPM_PACKAGE_NAME@ 9 | Version: @CPACK_RPM_PACKAGE_VERSION@ 10 | Release: @CPACK_RPM_PACKAGE_RELEASE@ 11 | License: @CPACK_RPM_PACKAGE_LICENSE@ 12 | Group: @CPACK_RPM_PACKAGE_GROUP@ 13 | Vendor: @CPACK_RPM_PACKAGE_VENDOR@ 14 | 15 | @TMP_RPM_URL@ 16 | @TMP_RPM_REQUIRES@ 17 | @TMP_RPM_REQUIRES_PRE@ 18 | @TMP_RPM_REQUIRES_POST@ 19 | @TMP_RPM_REQUIRES_PREUN@ 20 | @TMP_RPM_REQUIRES_POSTUN@ 21 | @TMP_RPM_PROVIDES@ 22 | @TMP_RPM_OBSOLETES@ 23 | @TMP_RPM_CONFLICTS@ 24 | @TMP_RPM_SUGGESTS@ 25 | @TMP_RPM_AUTOPROV@ 26 | @TMP_RPM_AUTOREQ@ 27 | @TMP_RPM_AUTOREQPROV@ 28 | @TMP_RPM_BUILDARCH@ 29 | @TMP_RPM_PREFIXES@ 30 | @TMP_RPM_EPOCH@ 31 | 32 | # Modifications to allow recommends to be used (not implemented in cpack): 33 | %if "@CPACK_RPM_PACKAGE_RECOMMENDS@" != "" 34 | Recommends: @CPACK_RPM_PACKAGE_RECOMMENDS@ 35 | %endif 36 | # End of modifications 37 | 38 | @TMP_RPM_DEBUGINFO@ 39 | 40 | %define _rpmdir %_topdir/RPMS 41 | %define _srcrpmdir %_topdir/SRPMS 42 | @FILE_NAME_DEFINE@ 43 | %define _unpackaged_files_terminate_build 0 44 | @TMP_RPM_SPEC_INSTALL_POST@ 45 | @CPACK_RPM_SPEC_MORE_DEFINE@ 46 | @CPACK_RPM_COMPRESSION_TYPE_TMP@ 47 | 48 | %description 49 | @CPACK_RPM_PACKAGE_DESCRIPTION@ 50 | 51 | # This is a shortcutted spec file generated by CMake RPM generator 52 | # we skip _install step because CPack does that for us. 53 | # We do only save CPack installed tree in _prepr 54 | # and then restore it in build. 55 | %prep 56 | mv $RPM_BUILD_ROOT %_topdir/tmpBBroot 57 | 58 | %install 59 | if [ -e $RPM_BUILD_ROOT ]; 60 | then 61 | rm -rf $RPM_BUILD_ROOT 62 | fi 63 | mv %_topdir/tmpBBroot $RPM_BUILD_ROOT 64 | 65 | @TMP_RPM_DEBUGINFO_INSTALL@ 66 | 67 | %clean 68 | 69 | %post 70 | @RPM_SYMLINK_POSTINSTALL@ 71 | @CPACK_RPM_SPEC_POSTINSTALL@ 72 | 73 | %posttrans 74 | @CPACK_RPM_SPEC_POSTTRANS@ 75 | 76 | %postun 77 | @CPACK_RPM_SPEC_POSTUNINSTALL@ 78 | 79 | %pre 80 | @CPACK_RPM_SPEC_PREINSTALL@ 81 | 82 | %pretrans 83 | @CPACK_RPM_SPEC_PRETRANS@ 84 | 85 | %preun 86 | @CPACK_RPM_SPEC_PREUNINSTALL@ 87 | 88 | %files 89 | %defattr(@TMP_DEFAULT_FILE_PERMISSIONS@,@TMP_DEFAULT_USER@,@TMP_DEFAULT_GROUP@,@TMP_DEFAULT_DIR_PERMISSIONS@) 90 | @CPACK_RPM_INSTALL_FILES@ 91 | @CPACK_RPM_ABSOLUTE_INSTALL_FILES@ 92 | @CPACK_RPM_USER_INSTALL_FILES@ 93 | 94 | %changelog 95 | @CPACK_RPM_SPEC_CHANGELOG@ 96 | 97 | @TMP_OTHER_COMPONENTS@ 98 | -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 1 | ROCT-Thunk Interface LICENSE 2 | 3 | Copyright (c) 2016 Advanced Micro Devices, Inc. All rights reserved. 4 | 5 | MIT LICENSE: 6 | Permission is hereby granted, free of charge, to any person obtaining 7 | a copy of this software and associated documentation files (the 8 | "Software"), to deal in the Software without restriction, including 9 | without limitation the rights to use, copy, modify, merge, publish, 10 | distribute, sublicense, and/or sell copies of the Software, and to 11 | permit persons to whom the Software is furnished to do so, subject to 12 | the following conditions: 13 | 14 | The above copyright notice and this permission notice shall be 15 | included in all copies or substantial portions of the Software. 16 | 17 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 18 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 19 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 20 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 21 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 22 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 23 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 24 | 25 | This product contains software provided by Nginx, Inc. and its contributors. 26 | 27 | Copyright (C) 2002-2018 Igor Sysoev 28 | Copyright (C) 2011-2018 Nginx, Inc. 29 | All rights reserved. 30 | 31 | Redistribution and use in source and binary forms, with or without 32 | modification, are permitted provided that the following conditions 33 | are met: 34 | 1. Redistributions of source code must retain the above copyright 35 | notice, this list of conditions and the following disclaimer. 36 | 2. Redistributions in binary form must reproduce the above copyright 37 | notice, this list of conditions and the following disclaimer in the 38 | documentation and/or other materials provided with the distribution. 39 | 40 | THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 41 | ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 42 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 43 | ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 44 | FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 45 | DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 46 | OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 47 | HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 48 | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 49 | OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 50 | SUCH DAMAGE. 51 | -------------------------------------------------------------------------------- /tests/kfdtest/src/Dispatch.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2018 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #ifndef __KFD_DISPATCH__H__ 25 | #define __KFD_DISPATCH__H__ 26 | #include "KFDTestUtil.hpp" 27 | #include "IndirectBuffer.hpp" 28 | #include "BaseQueue.hpp" 29 | 30 | class Dispatch { 31 | public: 32 | Dispatch(const HsaMemoryBuffer& isaBuf, const bool eventAutoReset = false); 33 | ~Dispatch(); 34 | 35 | void SetArgs(void* pArg1, void* pArg2); 36 | 37 | void SetDim(unsigned int x, unsigned int y, unsigned int z); 38 | 39 | void Submit(BaseQueue& queue); 40 | 41 | void Sync(unsigned int timeout = HSA_EVENTTIMEOUT_INFINITE); 42 | 43 | int SyncWithStatus(unsigned int timeout); 44 | 45 | void SetScratch(int numWaves, int waveSize, HSAuint64 scratch_base); 46 | 47 | void SetSpiPriority(unsigned int priority); 48 | 49 | void SetPriv(bool priv); 50 | 51 | HsaEvent *GetHsaEvent() { return m_pEop; } 52 | 53 | private: 54 | void BuildIb(); 55 | 56 | private: 57 | const HsaMemoryBuffer& m_IsaBuf; 58 | 59 | IndirectBuffer m_IndirectBuf; 60 | 61 | unsigned int m_DimX; 62 | unsigned int m_DimY; 63 | unsigned int m_DimZ; 64 | 65 | void* m_pArg1; 66 | void* m_pArg2; 67 | 68 | HsaEvent* m_pEop; 69 | 70 | bool m_ScratchEn; 71 | unsigned int m_ComputeTmpringSize; 72 | 73 | HSAuint64 m_scratch_base; 74 | unsigned int m_SpiPriority; 75 | unsigned int m_FamilyId; 76 | bool m_NeedCwsrWA; 77 | }; 78 | 79 | #endif // __KFD_DISPATCH__H__ 80 | -------------------------------------------------------------------------------- /tests/kfdtest/src/IndirectBuffer.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2018 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #ifndef __INDIRECT_BUFFER__H__ 25 | #define __INDIRECT_BUFFER__H__ 26 | 27 | #include "BasePacket.hpp" 28 | #include "KFDTestUtil.hpp" 29 | 30 | /** @class IndirectBuffer 31 | * When working with an indirect buffer, create IndirectBuffer, fill it with all the packets you want, 32 | * create an indirect packet to point to it, and submit the packet to queue 33 | */ 34 | class IndirectBuffer { 35 | public: 36 | // @param[size] Queue max size in DWords 37 | // @param[type] Packet type allowed in queue 38 | IndirectBuffer(PACKETTYPE type, unsigned int sizeInDWords, unsigned int NodeId); 39 | ~IndirectBuffer(void); 40 | 41 | // @brief Add packet to queue, all validations are done with gtest ASSERT and EXPECT 42 | uint32_t *AddPacket(const BasePacket &packet); 43 | // @returns Actual size of the indirect queue in DWords, equivalent to write pointer 44 | unsigned int SizeInDWord() { return m_ActualSize; } 45 | // @returns Indirect queue address 46 | unsigned int *Addr() { return m_IndirectBuf->As(); } 47 | 48 | protected: 49 | // Number of packets in the queue 50 | unsigned int m_NumOfPackets; 51 | // Max size of queue in DWords 52 | unsigned int m_MaxSize; 53 | // Current size of queue in DWords 54 | unsigned int m_ActualSize; 55 | HsaMemoryBuffer *m_IndirectBuf; 56 | // What packets are supported in this queue 57 | PACKETTYPE m_PacketTypeAllowed; 58 | }; 59 | 60 | #endif // __INDIRECT_BUFFER__H__ 61 | -------------------------------------------------------------------------------- /tests/kfdtest/src/ShaderStore.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2021 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #ifndef _SHADERSTORE_H_ 25 | #define _SHADERSTORE_H_ 26 | 27 | #include 28 | 29 | /* KFDASMTest List */ 30 | extern const std::vector ShaderList; 31 | 32 | /* Common */ 33 | extern const char *NoopIsa; 34 | extern const char *CopyDwordIsa; 35 | extern const char *InfiniteLoopIsa; 36 | extern const char *AtomicIncIsa; 37 | 38 | /* KFDMemoryTest */ 39 | extern const char *ScratchCopyDwordIsa; 40 | extern const char *PollMemoryIsa; 41 | extern const char *PollNCMemoryIsa; 42 | extern const char *CopyOnSignalIsa; 43 | extern const char *PollAndCopyIsa; 44 | extern const char *WriteFlagAndValueIsa; 45 | extern const char *WriteAndSignalIsa; 46 | extern const char *WriteReleaseVectorIsa; 47 | extern const char *WriteReleaseScalarIsa; 48 | extern const char *ReadAcquireVectorIsa; 49 | extern const char *ReadAcquireScalarIsa; 50 | extern const char *FlushBufferForAcquireReleaseIsa; 51 | 52 | /* KFDQMTest */ 53 | extern const char *LoopIsa; 54 | 55 | /* KFDCWSRTest */ 56 | extern const char *PersistentIterateIsa; 57 | 58 | /* KFDEvictTest */ 59 | extern const char *ReadMemoryIsa; 60 | 61 | /* KFDGWSTest */ 62 | extern const char *GwsInitIsa; 63 | extern const char *GwsAtomicIncreaseIsa; 64 | 65 | /* HitTrapEvent */ 66 | extern const char *JumpToTrapIsa; 67 | extern const char *TrapHandlerIsa; 68 | 69 | /* HitWatchPointEvent */ 70 | extern const char *WatchReadIsa; 71 | extern const char *WatchWriteIsa; 72 | extern const char *WatchAtomicIsa; 73 | 74 | #endif // _SHADERSTORE_H_ 75 | -------------------------------------------------------------------------------- /tests/kfdtest/src/SDMAQueue.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2018 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #ifndef __KFD_SDMA_QUEUE__H__ 25 | #define __KFD_SDMA_QUEUE__H__ 26 | 27 | #include "BaseQueue.hpp" 28 | 29 | class SDMAQueue : public BaseQueue { 30 | public: 31 | SDMAQueue(void); 32 | virtual ~SDMAQueue(void); 33 | 34 | // @brief Update queue write pointer and set the queue doorbell to the queue write pointer 35 | virtual void SubmitPacket(); 36 | 37 | /** Wait for all the packets submitted to the queue to be consumed. (i.e. wait until RPTR=WPTR). 38 | * Note that all packets being consumed is not the same as all packets being processed. 39 | * If event is set, wait all packets being processed. 40 | * And we can benefit from that as it has 41 | * 1) Less CPU usage (process can sleep, waiting for interrupt). 42 | * 2) Lower latency (GPU only updates RPTR in memory periodically). 43 | */ 44 | virtual void Wait4PacketConsumption(HsaEvent *event = NULL, unsigned int timeOut = g_TestTimeOut); 45 | 46 | protected: 47 | // @ return Write pointer modulo queue size in dwords 48 | virtual unsigned int Wptr(); 49 | // @ return Read pointer modulo queue size in dwords 50 | virtual unsigned int Rptr(); 51 | // @ return Expected m_Resources.Queue_read_ptr when all packets are consumed 52 | virtual unsigned int RptrWhenConsumed(); 53 | 54 | virtual PACKETTYPE PacketTypeSupported() { return PACKETTYPE_SDMA; } 55 | 56 | virtual _HSA_QUEUE_TYPE GetQueueType() { return HSA_QUEUE_SDMA; } 57 | }; 58 | 59 | #endif // __KFD_SDMA_QUEUE__H__ 60 | -------------------------------------------------------------------------------- /tests/kfdtest/src/PM4Queue.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2018 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #ifndef __KFD_PM4_QUEUE__H__ 25 | #define __KFD_PM4_QUEUE__H__ 26 | 27 | #include "BaseQueue.hpp" 28 | #include "PM4Packet.hpp" 29 | 30 | class PM4Queue : public BaseQueue { 31 | public: 32 | PM4Queue(void); 33 | virtual ~PM4Queue(void); 34 | 35 | // @brief update queue write pointer and sets the queue doorbell to the queue write pointer 36 | virtual void SubmitPacket(); 37 | 38 | // @ return read pointer modulo queue size in dwords 39 | virtual unsigned int Rptr(); 40 | // @ return write pointer modulo queue size in dwords 41 | virtual unsigned int Wptr(); 42 | // @ return expected m_Resources.Queue_read_ptr when all packets consumed 43 | virtual unsigned int RptrWhenConsumed(); 44 | /** Wait for all the packets submitted to the queue to be consumed. (i.e. wait until RPTR=WPTR). 45 | * Note that all packets being consumed is not the same as all packets being processed. 46 | * If event is set, wait all packets being processed. 47 | * And we can benefit from that as it has 48 | * 1) Less CPU usage (process can sleep, waiting for interrupt). 49 | * 2) Lower latency (GPU only updates RPTR in memory periodically). 50 | */ 51 | virtual void Wait4PacketConsumption(HsaEvent *event = NULL, unsigned int timeOut = g_TestTimeOut); 52 | 53 | protected: 54 | virtual PACKETTYPE PacketTypeSupported() { return PACKETTYPE_PM4; } 55 | 56 | virtual _HSA_QUEUE_TYPE GetQueueType() { return HSA_QUEUE_COMPUTE; } 57 | }; 58 | 59 | #endif // __KFD_PM4_QUEUE__H__ 60 | -------------------------------------------------------------------------------- /tests/kfdtest/src/KFDExceptionTest.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2018 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #ifndef __KFD_EXCEPTION_TEST__H__ 25 | #define __KFD_EXCEPTION_TEST__H__ 26 | 27 | #include 28 | 29 | #include "KFDBaseComponentTest.hpp" 30 | 31 | class KFDExceptionTest : public KFDBaseComponentTest { 32 | public: 33 | KFDExceptionTest() : m_ChildPid(-1) { 34 | /* Because there could be early return before m_ChildPid is set 35 | * by fork(), we should initialize m_ChildPid to a non-zero value 36 | * to avoid possible exit of the main process. 37 | */ 38 | } 39 | 40 | ~KFDExceptionTest() { 41 | /* exit() is necessary for the child process. Otherwise when the 42 | * child process finishes, gtest assumes the test has finished and 43 | * starts the next test while the parent is still active. 44 | */ 45 | if (m_ChildPid == 0) { 46 | if (!m_ChildStatus && HasFatalFailure()) 47 | m_ChildStatus = HSAKMT_STATUS_ERROR; 48 | exit(m_ChildStatus); 49 | } 50 | } 51 | 52 | protected: 53 | virtual void SetUp(); 54 | virtual void TearDown(); 55 | 56 | void TestMemoryException(int defaultGPUNode, HSAuint64 pSrc, HSAuint64 pDst, 57 | unsigned int dimX = 1, unsigned int dimY = 1, 58 | unsigned int dimZ = 1); 59 | void TestSdmaException(int defaultGPUNode, void *pDst); 60 | 61 | protected: // Members 62 | pid_t m_ChildPid; 63 | HSAKMT_STATUS m_ChildStatus; 64 | }; 65 | 66 | #endif // __KFD_EXCEPTION_TEST__H__ 67 | -------------------------------------------------------------------------------- /tests/kfdtest/src/KFDTestUtilQueue.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2018 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #ifndef __KFD__TEST__UTIL__QUEUE__H__ 25 | #define __KFD__TEST__UTIL__QUEUE__H__ 26 | 27 | #include "hsakmt/hsakmt.h" 28 | #include 29 | 30 | typedef struct { 31 | HSAuint64 timestamp; 32 | HSAuint64 timeConsumption; 33 | HSAuint64 timeBegin; 34 | HSAuint64 timeEnd; 35 | } TimeStamp; 36 | 37 | /* We have three pattern to put timestamp packet, 38 | * NOTS: No timestamp packet insert. 39 | * ALLTS: Put timestamp packet around every packet. This is the default behavoir. 40 | * It will look like |timestamp|packet|timestamp|...|packet|timestamp| 41 | * HEAD_TAIL: Put timestmap packet at head and tail to measure the overhead of a bunch of packet. 42 | * It will look like |timestamp|packet|...|packet|timestamp| 43 | */ 44 | typedef enum { 45 | NOTS = 0, 46 | ALLTS = 1, 47 | HEAD_TAIL = 2, 48 | } TSPattern; 49 | 50 | typedef struct { 51 | /* input values*/ 52 | HSAuint32 node; 53 | void *src; 54 | void *dst; 55 | HSAuint64 size; 56 | /* input value for internal use.*/ 57 | HSAuint64 group; 58 | /* output value*/ 59 | HSAuint64 timeConsumption; 60 | HSAuint64 timeBegin; 61 | HSAuint64 timeEnd; 62 | /* private: Output values for internal use.*/ 63 | HSAuint64 queue_id; 64 | HSAuint64 packet_id; 65 | } SDMACopyParams; 66 | 67 | void sdma_multicopy(SDMACopyParams *array, int n, 68 | HSAuint64 *speedSmall = 0, HSAuint64 *speedLarge = 0, std::stringstream *s = 0); 69 | void sdma_multicopy(std::vector &array, int mashup = 1, TSPattern tsp = ALLTS); 70 | #endif //__KFD__TEST__UTIL__QUEUE__H__ 71 | -------------------------------------------------------------------------------- /tests/kfdtest/src/KFDTestFlags.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2018 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #ifndef __KFD_TEST_FLAGS__H__ 25 | #define __KFD_TEST_FLAGS__H__ 26 | 27 | extern unsigned int g_TestRunProfile; 28 | extern unsigned int g_TestENVCaps; 29 | extern unsigned int g_TestTimeOut; 30 | extern int g_TestNodeId; 31 | extern int g_TestDstNodeId; 32 | extern bool g_IsChildProcess; 33 | extern bool g_IsEmuMode; 34 | 35 | // Each test should call TEST_START with the test custom profile and HW scheduling 36 | enum TESTPROFILE{ 37 | TESTPROFILE_DEV = 0x1, 38 | TESTPROFILE_PROMO = 0x2, 39 | // 0x4 - 0x8000 - unused flags 40 | // Can add any flag that will mark only part of the tests to run 41 | TESTPROFILE_RUNALL = 0xFFFF 42 | }; 43 | 44 | enum ENVCAPS{ 45 | ENVCAPS_NOADDEDCAPS = 0x0, 46 | ENVCAPS_HWSCHEDULING = 0x1, 47 | ENVCAPS_16BITPASID = 0x2, 48 | ENVCAPS_32BITLINUX = 0x4, 49 | ENVCAPS_64BITLINUX = 0x8 50 | // 0x8 - 0x8000 - unused flags 51 | // Can add any flag that will mark specific hw limitation or capability 52 | }; 53 | 54 | enum KfdFamilyId { 55 | FAMILY_UNKNOWN = 0, 56 | FAMILY_CI, // Sea Islands: Hawaii (P), Maui (P), Bonaire (M) 57 | FAMILY_KV, // Fusion Kaveri: Spectre, Spooky; Fusion Kabini: Kalindi 58 | FAMILY_VI, // Volcanic Islands: Iceland (V), Tonga (M) 59 | FAMILY_CZ, // Carrizo, Nolan, Amur 60 | FAMILY_AI, // Arctic Islands 61 | FAMILY_RV, // Raven 62 | FAMILY_AR, // Arcturus 63 | FAMILY_AL, // Aldebaran 64 | FAMILY_AV, // Aqua Vanjaram 65 | FAMILY_NV, // Navi10 66 | FAMILY_GFX11, // GFX11 67 | FAMILY_GFX12, // GFX12 68 | }; 69 | 70 | #endif // __KFD_TEST_FLAGS__H__ 71 | -------------------------------------------------------------------------------- /tests/kfdtest/src/KFDMultiProcessTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #include "KFDMultiProcessTest.hpp" 25 | 26 | void KFDMultiProcessTest::ForkChildProcesses(int nprocesses) { 27 | int i; 28 | 29 | for (i = 0; i < nprocesses - 1; ++i) { 30 | pid_t pid = fork(); 31 | ASSERT_GE(pid, 0); 32 | 33 | if (pid == 0) { 34 | /* Child process */ 35 | /* Cleanup file descriptors copied from parent process 36 | * then call SetUp->hsaKmtOpenKFD to create new process 37 | */ 38 | m_psName = "Test process " + std::to_string(i) + " "; 39 | TearDown(); 40 | SetUp(); 41 | m_ChildPids.clear(); 42 | m_IsParent = false; 43 | m_ProcessIndex = i; 44 | return; 45 | } 46 | 47 | /* Parent process */ 48 | m_ChildPids.push_back(pid); 49 | } 50 | 51 | m_psName = "Test process " + std::to_string(i) + " "; 52 | m_ProcessIndex = i; 53 | } 54 | 55 | void KFDMultiProcessTest::WaitChildProcesses() { 56 | if (m_IsParent) { 57 | /* Only run by parent process */ 58 | int childStatus; 59 | int childExitOkNum = 0; 60 | int size = m_ChildPids.size(); 61 | 62 | for (HSAuint32 i = 0; i < size; i++) { 63 | pid_t pid = m_ChildPids.front(); 64 | 65 | waitpid(pid, &childStatus, 0); 66 | if (WIFEXITED(childStatus) == 1 && WEXITSTATUS(childStatus) == 0) 67 | childExitOkNum++; 68 | 69 | m_ChildPids.erase(m_ChildPids.begin()); 70 | } 71 | 72 | EXPECT_EQ(childExitOkNum, size); 73 | } 74 | 75 | /* Child process or parent process finished successfully */ 76 | m_ChildStatus = HSAKMT_STATUS_SUCCESS; 77 | } 78 | -------------------------------------------------------------------------------- /tests/kfdtest/src/GoogleTestExtension.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2018 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #include "GoogleTestExtension.hpp" 25 | #include "OSWrapper.hpp" 26 | 27 | bool Ok2Run(unsigned int testProfile) { 28 | bool testMatchProfile = true; 29 | if ((testProfile & g_TestRunProfile) == 0) { 30 | WARN() << "Test is skipped beacuse profile does not match current run mode" << std::endl; 31 | testMatchProfile = false; 32 | } 33 | 34 | return testMatchProfile; 35 | } 36 | 37 | // This predication is used when specific HW capabilities must exist for the test to succeed. 38 | bool TestReqEnvCaps(unsigned int envCaps) { 39 | bool testMatchEnv = true; 40 | if ((envCaps & g_TestENVCaps) != envCaps) { 41 | WARN() << "Test is skipped due to HW capability issues" << std::endl; 42 | testMatchEnv = false; 43 | } 44 | 45 | return testMatchEnv; 46 | } 47 | 48 | // This predication is used when specific HW capabilities must be absent for the test to succeed. 49 | // e.g Testing capabilities not supported by HW scheduling 50 | bool TestReqNoEnvCaps(unsigned int envCaps) { 51 | bool testMatchEnv = true; 52 | if ((envCaps & g_TestENVCaps) != 0) { 53 | WARN() << "Test is skipped due to HW capability issues" << std::endl; 54 | testMatchEnv = false; 55 | } 56 | 57 | return testMatchEnv; 58 | } 59 | 60 | std::ostream& operator<< (KFDLog log, LOGTYPE level) { 61 | const char *heading; 62 | 63 | if (level == LOGTYPE_WARNING) { 64 | SetConsoleTextColor(TEXTCOLOR_YELLOW); 65 | heading = "[----------] "; 66 | } else { 67 | SetConsoleTextColor(TEXTCOLOR_GREEN); 68 | heading = "[ ] "; 69 | } 70 | 71 | std::clog << heading; 72 | SetConsoleTextColor(TEXTCOLOR_WHITE); 73 | 74 | return std::clog; 75 | } 76 | 77 | -------------------------------------------------------------------------------- /tests/kfdtest/src/KFDSVMEvictTest.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2020 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #ifndef __KFD_SVM_EVICT_TEST__H__ 25 | #define __KFD_SVM_EVICT_TEST__H__ 26 | 27 | #include 28 | #include 29 | #include "KFDLocalMemoryTest.hpp" 30 | #include "KFDBaseComponentTest.hpp" 31 | 32 | // @class KFDEvictTest 33 | // Test eviction and restore procedure using two processes 34 | class KFDSVMEvictTest : public KFDLocalMemoryTest, 35 | public ::testing::WithParamInterface { 36 | public: 37 | KFDSVMEvictTest(void): m_ChildStatus(HSAKMT_STATUS_ERROR), m_IsParent(true) {} 38 | 39 | ~KFDSVMEvictTest(void) { 40 | if (!m_IsParent) { 41 | /* child process has to exit 42 | * otherwise gtest will continue other tests 43 | */ 44 | exit(m_ChildStatus); 45 | } 46 | 47 | try { 48 | WaitChildProcesses(); 49 | } catch (...) {} 50 | } 51 | 52 | protected: 53 | virtual void SetUp(); 54 | virtual void TearDown(); 55 | 56 | protected: 57 | std::string CreateShader(); 58 | void AllocBuffers(HSAuint32 defaultGPUNode, HSAuint32 count, HSAuint64 vramBufSize, 59 | std::vector &pBuffers, HSAuint32 Granularity); 60 | void FreeBuffers(std::vector &pBuffers, HSAuint64 vramBufSize); 61 | void ForkChildProcesses(int nprocesses); 62 | void WaitChildProcesses(); 63 | HSAint32 GetBufferCounter(HSAuint64 vramSize, HSAuint64 vramBufSize); 64 | HSAint64 GetBufferSize(HSAuint64 vramSize, HSAuint32 count, 65 | HSAint32 xnack_enable); 66 | 67 | protected: // members 68 | std::string m_psName; 69 | std::vector m_ChildPids; 70 | HSA_SVM_FLAGS m_Flags; 71 | void* m_pBuf; 72 | HSAKMT_STATUS m_ChildStatus; 73 | bool m_IsParent; 74 | }; 75 | 76 | #endif // __KFD_SVM_EVICT_TEST__H__ 77 | -------------------------------------------------------------------------------- /tests/kfdtest/src/BaseDebug.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2023 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #ifndef __KFD_BASE_DEBUG__H__ 25 | #define __KFD_BASE_DEBUG__H__ 26 | 27 | #include "hsakmt/hsakmt.h" 28 | #include 29 | #include 30 | 31 | // @class BaseDebug 32 | class BaseDebug { 33 | public: 34 | BaseDebug(void); 35 | virtual ~BaseDebug(void); 36 | 37 | HSAKMT_STATUS Attach(struct kfd_runtime_info *rInfo, 38 | int rInfoSize, 39 | unsigned int pid, 40 | uint64_t exceptionEnable); 41 | 42 | void Detach(void); 43 | HSAKMT_STATUS SendRuntimeEvent(uint64_t exceptions, int gpuId, int queueId); 44 | HSAKMT_STATUS QueryDebugEvent(uint64_t *exceptions, 45 | uint32_t *gpuId, uint32_t *queueId, 46 | int timeoutMsec); 47 | void SetExceptionsEnabled(uint64_t exceptions); 48 | HSAKMT_STATUS SuspendQueues(unsigned int *numQueues, HSA_QUEUEID *queues, uint32_t *queueIds, 49 | uint64_t exceptionsToClear); 50 | HSAKMT_STATUS ResumeQueues(unsigned int *numQueues, HSA_QUEUEID *queues, uint32_t *queueIds); 51 | HSAKMT_STATUS QueueSnapshot(uint64_t exceptionsToClear, uint64_t snapshotBufAddr, 52 | uint32_t *numSnapshots); 53 | HSAKMT_STATUS DeviceSnapshot(uint64_t exceptionsToClear, uint64_t snapshotBuffAddr, 54 | uint32_t *numSnapshots); 55 | HSAKMT_STATUS SetWaveLaunchOverride(int mode, uint32_t *enableMask, uint32_t *supportMask); 56 | HSAKMT_STATUS SetAddressWatch(uint64_t address, int mode, uint64_t mask, uint32_t gpuId, uint32_t *id); 57 | HSAKMT_STATUS ClearAddressWatch(uint32_t gpuId, uint32_t id); 58 | HSAKMT_STATUS SetFlags(uint32_t *flags); 59 | 60 | private: 61 | unsigned int m_Pid; 62 | struct pollfd m_Fd; 63 | const char *m_Fd_Name = "/tmp/dbg_fifo"; 64 | }; 65 | 66 | #endif // __KFD_BASE_DEBUG__H__ 67 | -------------------------------------------------------------------------------- /src/rbtree.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2002-2018 Igor Sysoev 3 | * Copyright (C) 2011-2018 Nginx, Inc. 4 | * All rights reserved. 5 | * 6 | * Redistribution and use in source and binary forms, with or without 7 | * modification, are permitted provided that the following conditions 8 | * are met: 9 | * 1. Redistributions of source code must retain the above copyright 10 | * notice, this list of conditions and the following disclaimer. 11 | * 2. Redistributions in binary form must reproduce the above copyright 12 | * notice, this list of conditions and the following disclaimer in the 13 | * documentation and/or other materials provided with the distribution. 14 | * 15 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND 16 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 17 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 18 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 19 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 20 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 21 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 22 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 23 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 24 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 25 | * SUCH DAMAGE. 26 | */ 27 | 28 | #ifndef _RBTREE_H_ 29 | #define _RBTREE_H_ 30 | 31 | #include 32 | #include 33 | #include 34 | #include 35 | #include 36 | #include 37 | #include 38 | #include 39 | #include 40 | #include 41 | #include "rbtree_amd.h" 42 | 43 | typedef struct rbtree_node_s rbtree_node_t; 44 | 45 | struct rbtree_node_s { 46 | rbtree_key_t key; 47 | rbtree_node_t *left; 48 | rbtree_node_t *right; 49 | rbtree_node_t *parent; 50 | unsigned char color; 51 | unsigned char data; 52 | }; 53 | 54 | typedef struct rbtree_s rbtree_t; 55 | 56 | struct rbtree_s { 57 | rbtree_node_t *root; 58 | rbtree_node_t sentinel; 59 | }; 60 | 61 | #define rbtree_init(tree) \ 62 | rbtree_sentinel_init(&(tree)->sentinel); \ 63 | (tree)->root = &(tree)->sentinel; 64 | 65 | void rbtree_insert(rbtree_t *tree, rbtree_node_t *node); 66 | void rbtree_delete(rbtree_t *tree, rbtree_node_t *node); 67 | rbtree_node_t *rbtree_prev(rbtree_t *tree, 68 | rbtree_node_t *node); 69 | rbtree_node_t *rbtree_next(rbtree_t *tree, 70 | rbtree_node_t *node); 71 | 72 | #define rbt_red(node) ((node)->color = 1) 73 | #define rbt_black(node) ((node)->color = 0) 74 | #define rbt_is_red(node) ((node)->color) 75 | #define rbt_is_black(node) (!rbt_is_red(node)) 76 | #define rbt_copy_color(n1, n2) (n1->color = n2->color) 77 | 78 | /* a sentinel must be black */ 79 | 80 | #define rbtree_sentinel_init(node) rbt_black(node) 81 | 82 | static inline rbtree_node_t * 83 | rbtree_min(rbtree_node_t *node, rbtree_node_t *sentinel) 84 | { 85 | while (node->left != sentinel) { 86 | node = node->left; 87 | } 88 | 89 | return node; 90 | } 91 | 92 | #include "rbtree_amd.h" 93 | 94 | #endif 95 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ROCt Library 2 | 3 | # NOTE: This repository has been deprecated. Please refer to https://github.com/ROCm/ROCR-Runtime for all future work on libhsakmt/ROCT/thunk. 4 | 5 | 6 | This repository includes the user-mode API interfaces used to interact with the ROCk driver. 7 | 8 | Starting at 1.7 release, ROCt uses drm render device. This requires the user to belong to video group. Add the user account to video group with "sudo usermod -a -G video _username_" command if the user if not part of video group yet. 9 | NOTE: Users of Ubuntu 20.04 will need to add the user to the new "render" group, as Ubuntu has changed the owner:group of /dev/kfd to render:render as of that release 10 | 11 | ## ROCk Driver 12 | 13 | The ROCt library is not a standalone product and requires that you have the correct ROCk driver installed, or are using a compatible upstream kernel. 14 | Please refer to under "Getting Started Guide" for a list of supported Operating Systems and kernel versions, as well as supported hardware. 15 | 16 | ## Building the Thunk 17 | 18 | A simple cmake-based system is available for building thunk. To build the thunk from the the ROCT-Thunk-Interface directory, execute: 19 | 20 | ```bash 21 | mkdir -p build 22 | cd build 23 | cmake .. 24 | make 25 | ``` 26 | 27 | If the hsakmt-roct and hsakmt-roct-dev packages are desired: 28 | 29 | ```bash 30 | mkdir -p build 31 | cd build 32 | cmake .. 33 | make package 34 | ``` 35 | 36 | If you choose not to build and install packages, manual installation of the binaries and header files can be done via: 37 | 38 | ```bash 39 | make install 40 | ``` 41 | 42 | NOTE: For older versions of the thunk where hsakmt-dev.txt is present, "make package-dev" and "make install-dev" are required to generate/install the developer packages. Currently, these are created via the "make package" and "make install" commands 43 | 44 | ## Disclaimer 45 | 46 | The information contained herein is for informational purposes only, and is subject to change without notice. While every precaution has been taken in the preparation of this document, it may contain technical inaccuracies, omissions and typographical errors, and AMD is under no obligation to update or otherwise correct this information. Advanced Micro Devices, Inc. makes no representations or warranties with respect to the accuracy or completeness of the contents of this document, and assumes no liability of any kind, including the implied warranties of noninfringement, merchantability or fitness for particular purposes, with respect to the operation or use of AMD hardware, software or other products described herein. No license, including implied or arising by estoppel, to any intellectual property rights is granted by this document. Terms and limitations applicable to the purchase or use of AMD's products are as set forth in a signed agreement between the parties or in AMD's Standard Terms and Conditions of Sale. 47 | 48 | AMD, the AMD Arrow logo, and combinations thereof are trademarks of Advanced Micro Devices, Inc. Other product names used in this publication are for identification purposes only and may be trademarks of their respective companies. 49 | 50 | Copyright (c) 2014-2023 Advanced Micro Devices, Inc. All rights reserved. 51 | -------------------------------------------------------------------------------- /tests/kfdtest/src/KFDOpenCloseKFDTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2018 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #include "KFDOpenCloseKFDTest.hpp" 25 | #include "KFDTestUtil.hpp" 26 | 27 | // Before every test from this class fixture, open KFD 28 | void KFDOpenCloseKFDTest::SetUp() { 29 | ROUTINE_START 30 | 31 | ASSERT_SUCCESS(hsaKmtOpenKFD() ); 32 | 33 | ROUTINE_END 34 | } 35 | 36 | // After every test from this class fixture, close KFD 37 | void KFDOpenCloseKFDTest::TearDown() { 38 | ROUTINE_START 39 | 40 | EXPECT_SUCCESS(hsaKmtCloseKFD() ); 41 | 42 | ROUTINE_END 43 | } 44 | 45 | /* This test does not use class KFDOpenCloseKFDTest but is placed here 46 | * since it's testing same topic as other test 47 | * Verify that calling hsaKmtCloseKFD on a closed KFD will return right status 48 | */ 49 | TEST(KFDCloseKFDTest, CloseAClosedKfd ) { 50 | TEST_START(TESTPROFILE_RUNALL) 51 | 52 | ASSERT_EQ(HSAKMT_STATUS_KERNEL_IO_CHANNEL_NOT_OPENED, hsaKmtCloseKFD()); 53 | 54 | TEST_END 55 | } 56 | 57 | // Verify that calling hsaKmtCloseKFD on an already opened KFD will return right status 58 | TEST_F(KFDOpenCloseKFDTest, OpenAlreadyOpenedKFD ) { 59 | TEST_START(TESTPROFILE_RUNALL) 60 | 61 | EXPECT_EQ(HSAKMT_STATUS_KERNEL_ALREADY_OPENED, hsaKmtOpenKFD()); 62 | 63 | EXPECT_SUCCESS(hsaKmtCloseKFD()); 64 | 65 | TEST_END 66 | } 67 | 68 | // Testing the normal scenario: open followed by close (done in the setup and teardown functions) 69 | TEST_F(KFDOpenCloseKFDTest, OpenCloseKFD ) { 70 | } 71 | 72 | TEST_F(KFDOpenCloseKFDTest, InvalidKFDHandleTest ) { 73 | TEST_START(TESTPROFILE_RUNALL) 74 | 75 | HsaVersionInfo m_VersionInfo; 76 | pid_t m_ChildPid = fork(); 77 | if (m_ChildPid == 0) { 78 | EXPECT_EQ(HSAKMT_STATUS_KERNEL_IO_CHANNEL_NOT_OPENED, hsaKmtGetVersion(&m_VersionInfo)); 79 | exit(0); 80 | } else { 81 | int childStatus; 82 | EXPECT_EQ(m_ChildPid, waitpid(m_ChildPid, &childStatus, 0)); 83 | EXPECT_NE(0, WIFEXITED(childStatus)); 84 | EXPECT_EQ(0, WEXITSTATUS(childStatus)); 85 | } 86 | TEST_END 87 | } 88 | -------------------------------------------------------------------------------- /tests/kfdtest/src/PM4Queue.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2018 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #include "PM4Queue.hpp" 25 | #include "pm4_pkt_struct_common.h" 26 | #include "GoogleTestExtension.hpp" 27 | #include "kfd_pm4_opcodes.h" 28 | 29 | 30 | PM4Queue::PM4Queue(void) { 31 | CMD_NOP = CMD_NOP_TYPE_3; 32 | } 33 | 34 | PM4Queue::~PM4Queue(void) { 35 | } 36 | 37 | unsigned int PM4Queue::Wptr() { 38 | /* Write pointer in dwords. Simulate 32-bit wptr that wraps at 39 | * queue size even on Vega10 and later chips with 64-bit wptr. 40 | */ 41 | return *m_Resources.Queue_write_ptr % (m_QueueBuf->Size() / 4); 42 | } 43 | 44 | unsigned int PM4Queue::Rptr() { 45 | /* CP read pointer in dwords. It's still 32-bit even on Vega10. */ 46 | return *m_Resources.Queue_read_ptr; 47 | } 48 | 49 | unsigned int PM4Queue::RptrWhenConsumed() { 50 | /* On PM4 queues Rptr is always 32-bit in dword units and wraps at 51 | * queue size. The expected value when all packets are consumed is 52 | * exactly the value returned by Wptr(). 53 | */ 54 | return Wptr(); 55 | } 56 | 57 | void PM4Queue::SubmitPacket() { 58 | // m_pending Wptr is in dwords 59 | if (m_FamilyId < FAMILY_AI) { 60 | // Pre-Vega10 uses 32-bit wptr and doorbell 61 | MemoryBarrier(); 62 | *m_Resources.Queue_write_ptr = m_pendingWptr; 63 | MemoryBarrier(); 64 | *(m_Resources.Queue_DoorBell) = m_pendingWptr; 65 | } else { 66 | // Vega10 and later uses 64-bit wptr and doorbell 67 | MemoryBarrier(); 68 | *m_Resources.Queue_write_ptr_aql = m_pendingWptr64; 69 | MemoryBarrier(); 70 | *(m_Resources.Queue_DoorBell_aql) = m_pendingWptr64; 71 | } 72 | } 73 | 74 | void PM4Queue::Wait4PacketConsumption(HsaEvent *event, unsigned int timeOut) { 75 | if (event) { 76 | PlaceAndSubmitPacket(PM4ReleaseMemoryPacket(m_FamilyId, 0, 77 | event->EventData.HWData2, 78 | event->EventId, 79 | true)); 80 | 81 | EXPECT_SUCCESS(hsaKmtWaitOnEvent(event, timeOut)); 82 | } else { 83 | BaseQueue::Wait4PacketConsumption(NULL, timeOut); 84 | } 85 | } 86 | -------------------------------------------------------------------------------- /src/spm.c: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2020 Advanced Micro Devices, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, copy, 8 | * modify, merge, publish, distribute, sublicense, and/or sell copies 9 | * of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice (including 13 | * the next paragraph) shall be included in all copies or substantial 14 | * portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #include "libhsakmt.h" 27 | #include "hsakmt/linux/kfd_ioctl.h" 28 | #include 29 | #include 30 | 31 | 32 | HSAKMT_STATUS HSAKMTAPI hsaKmtSPMAcquire(HSAuint32 PreferredNode) 33 | { 34 | int ret; 35 | struct kfd_ioctl_spm_args args = {0}; 36 | uint32_t gpu_id; 37 | 38 | ret = validate_nodeid(PreferredNode, &gpu_id); 39 | if (ret != HSAKMT_STATUS_SUCCESS) { 40 | pr_err("[%s] invalid node ID: %d\n", __func__, PreferredNode); 41 | return ret; 42 | } 43 | 44 | ret = HSAKMT_STATUS_SUCCESS; 45 | args.op = KFD_IOCTL_SPM_OP_ACQUIRE; 46 | args.gpu_id = gpu_id; 47 | 48 | ret = kmtIoctl(kfd_fd, AMDKFD_IOC_RLC_SPM, &args); 49 | 50 | return ret; 51 | } 52 | 53 | HSAKMT_STATUS HSAKMTAPI hsaKmtSPMSetDestBuffer(HSAuint32 PreferredNode, 54 | HSAuint32 SizeInBytes, 55 | HSAuint32 * timeout, 56 | HSAuint32 * SizeCopied, 57 | void *DestMemoryAddress, 58 | bool *isSPMDataLoss) 59 | { 60 | int ret; 61 | struct kfd_ioctl_spm_args args = {0}; 62 | uint32_t gpu_id; 63 | 64 | ret = HSAKMT_STATUS_SUCCESS; 65 | 66 | ret = validate_nodeid(PreferredNode, &gpu_id); 67 | 68 | args.timeout = *timeout; 69 | args.dest_buf = (uint64_t)DestMemoryAddress; 70 | args.buf_size = SizeInBytes; 71 | args.op = KFD_IOCTL_SPM_OP_SET_DEST_BUF; 72 | args.gpu_id = gpu_id; 73 | 74 | ret = kmtIoctl(kfd_fd, AMDKFD_IOC_RLC_SPM, &args); 75 | 76 | *SizeCopied = args.bytes_copied; 77 | *isSPMDataLoss = args.has_data_loss; 78 | *timeout = args.timeout; 79 | 80 | return ret; 81 | } 82 | 83 | HSAKMT_STATUS HSAKMTAPI hsaKmtSPMRelease(HSAuint32 PreferredNode) 84 | { 85 | int ret = HSAKMT_STATUS_SUCCESS; 86 | struct kfd_ioctl_spm_args args = {0}; 87 | uint32_t gpu_id; 88 | 89 | ret = validate_nodeid(PreferredNode, &gpu_id); 90 | if (ret != HSAKMT_STATUS_SUCCESS) { 91 | pr_err("[%s] invalid node ID: %d\n", __func__, PreferredNode); 92 | return ret; 93 | } 94 | 95 | args.op = KFD_IOCTL_SPM_OP_RELEASE; 96 | args.gpu_id = gpu_id; 97 | 98 | ret = kmtIoctl(kfd_fd, AMDKFD_IOC_RLC_SPM, &args); 99 | 100 | return ret; 101 | } 102 | 103 | 104 | -------------------------------------------------------------------------------- /tests/kfdtest/src/Assemble.hpp: -------------------------------------------------------------------------------- 1 | //////////////////////////////////////////////////////////////////////////////// 2 | // 3 | // The University of Illinois/NCSA 4 | // Open Source License (NCSA) 5 | // 6 | // Copyright (c) 2022, Advanced Micro Devices, Inc. All rights reserved. 7 | // 8 | // Developed by: 9 | // 10 | // AMD Research and AMD HSA Software Development 11 | // 12 | // Advanced Micro Devices, Inc. 13 | // 14 | // www.amd.com 15 | // 16 | // Permission is hereby granted, free of charge, to any person obtaining a copy 17 | // of this software and associated documentation files (the "Software"), to 18 | // deal with the Software without restriction, including without limitation 19 | // the rights to use, copy, modify, merge, publish, distribute, sublicense, 20 | // and/or sell copies of the Software, and to permit persons to whom the 21 | // Software is furnished to do so, subject to the following conditions: 22 | // 23 | // - Redistributions of source code must retain the above copyright notice, 24 | // this list of conditions and the following disclaimers. 25 | // - Redistributions in binary form must reproduce the above copyright 26 | // notice, this list of conditions and the following disclaimers in 27 | // the documentation and/or other materials provided with the distribution. 28 | // - Neither the names of Advanced Micro Devices, Inc, 29 | // nor the names of its contributors may be used to endorse or promote 30 | // products derived from this Software without specific prior written 31 | // permission. 32 | // 33 | // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 34 | // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 35 | // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 36 | // THE CONTRIBUTORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 37 | // OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 38 | // ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 39 | // DEALINGS WITH THE SOFTWARE. 40 | // 41 | //////////////////////////////////////////////////////////////////////////////// 42 | 43 | #ifndef _ASSEMBLE_H_ 44 | #define _ASSEMBLE_H_ 45 | 46 | #include "OSWrapper.hpp" 47 | 48 | #define ASM_MCPU_LEN 16 49 | 50 | class Assembler { 51 | private: 52 | const char* ArchName = "amdgcn"; 53 | const char* VendorName = "amd"; 54 | const char* OSName = "amdhsa"; 55 | char MCPU[ASM_MCPU_LEN]; 56 | 57 | std::string TripleName; 58 | std::string Error; 59 | 60 | char* TextData; 61 | size_t TextSize; 62 | 63 | void SetTargetAsic(const uint32_t Gfxv); 64 | 65 | void LLVMInit(); 66 | void FlushText(); 67 | void PrintELFHex(const std::string Data); 68 | int ExtractELFText(const char* RawData); 69 | 70 | public: 71 | Assembler(const uint32_t Gfxv); 72 | ~Assembler(); 73 | 74 | void PrintTextHex(); 75 | const char* GetTargetAsic(); 76 | 77 | const char* GetInstrStream(); 78 | const size_t GetInstrStreamSize(); 79 | int CopyInstrStream(char* OutBuf, const size_t BufSize = PAGE_SIZE); 80 | 81 | int RunAssemble(const char* const AssemblySource); 82 | int RunAssembleBuf(const char* const AssemblySource, char* OutBuf, 83 | const size_t BufSize = PAGE_SIZE); 84 | int RunAssembleBuf(const char* const AssemblySource, char* OutBuf, 85 | const size_t BufSize, const uint32_t Gfxv); 86 | }; 87 | 88 | #endif // _ASSEMBLE_H_ 89 | -------------------------------------------------------------------------------- /tests/kfdtest/src/KFDPMTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2018 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #include "KFDPMTest.hpp" 25 | #include "KFDTestUtil.hpp" 26 | #include "PM4Packet.hpp" 27 | #include "PM4Queue.hpp" 28 | #include "hsakmt/hsakmt.h" 29 | 30 | void KFDPMTest::SetUp() { 31 | ROUTINE_START 32 | 33 | KFDBaseComponentTest::SetUp(); 34 | 35 | ROUTINE_END 36 | } 37 | 38 | void KFDPMTest::TearDown() { 39 | ROUTINE_START 40 | 41 | KFDBaseComponentTest::TearDown(); 42 | 43 | ROUTINE_END 44 | } 45 | 46 | TEST_F(KFDPMTest, SuspendWithActiveProcess) { 47 | TEST_START(TESTPROFILE_RUNALL) 48 | 49 | EXPECT_EQ(true, SuspendAndWakeUp()); 50 | 51 | TEST_END 52 | } 53 | 54 | TEST_F(KFDPMTest, SuspendWithIdleQueue) { 55 | TEST_START(TESTPROFILE_RUNALL) 56 | 57 | PM4Queue queue; 58 | int defaultGPUNode = m_NodeInfo.HsaDefaultGPUNode(); 59 | ASSERT_GE(defaultGPUNode, 0) << "failed to get default GPU Node"; 60 | 61 | ASSERT_SUCCESS(queue.Create(defaultGPUNode)); 62 | 63 | EXPECT_EQ(true, SuspendAndWakeUp()); 64 | 65 | EXPECT_SUCCESS(queue.Destroy()); 66 | 67 | TEST_END 68 | } 69 | 70 | TEST_F(KFDPMTest, SuspendWithIdleQueueAfterWork) { 71 | TEST_START(TESTPROFILE_RUNALL) 72 | 73 | PM4Queue queue; 74 | int defaultGPUNode = m_NodeInfo.HsaDefaultGPUNode(); 75 | ASSERT_GE(defaultGPUNode, 0) << "failed to get default GPU Node"; 76 | 77 | HsaMemoryBuffer destBuffer(PAGE_SIZE, defaultGPUNode); 78 | 79 | ASSERT_SUCCESS(queue.Create(defaultGPUNode)); 80 | 81 | HsaEvent *event; 82 | ASSERT_SUCCESS(CreateQueueTypeEvent(false, false, defaultGPUNode, &event)); 83 | 84 | queue.PlaceAndSubmitPacket(PM4WriteDataPacket(destBuffer.As(), 0x1, 0x2)); 85 | queue.Wait4PacketConsumption(event); 86 | WaitOnValue(&(destBuffer.As()[0]), 0x1); 87 | WaitOnValue(&(destBuffer.As()[1]), 0x2); 88 | 89 | destBuffer.Fill(0); 90 | 91 | EXPECT_EQ(true, SuspendAndWakeUp()); 92 | 93 | queue.PlaceAndSubmitPacket(PM4WriteDataPacket(&(destBuffer.As()[2]), 0x3, 0x4)); 94 | queue.Wait4PacketConsumption(event); 95 | 96 | EXPECT_EQ(destBuffer.As()[0], 0); 97 | EXPECT_EQ(destBuffer.As()[1], 0); 98 | 99 | WaitOnValue(&(destBuffer.As()[2]), 0x3); 100 | WaitOnValue(&(destBuffer.As()[3]), 0x4); 101 | 102 | hsaKmtDestroyEvent(event); 103 | EXPECT_SUCCESS(queue.Destroy()); 104 | 105 | TEST_END 106 | } 107 | 108 | // TODO: Suspend while workload is being executed by a queue 109 | -------------------------------------------------------------------------------- /tests/kfdtest/src/SDMAQueue.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2018 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #include "SDMAQueue.hpp" 25 | #include "SDMAPacket.hpp" 26 | 27 | SDMAQueue::SDMAQueue(void) { 28 | CMD_NOP = 0; 29 | } 30 | 31 | SDMAQueue::~SDMAQueue(void) { 32 | } 33 | 34 | unsigned int SDMAQueue::Wptr() { 35 | /* In SDMA queues write pointers are saved in bytes, convert the 36 | * wptr value to dword to fit the way BaseQueue works. On Vega10 37 | * the write ptr is 64-bit. We only read the low 32 bit (assuming 38 | * the queue buffer is smaller than 4GB) and modulo divide by the 39 | * queue size to simulate a 32-bit read pointer. 40 | */ 41 | return (*m_Resources.Queue_write_ptr % m_QueueBuf->Size()) / 42 | sizeof(unsigned int); 43 | } 44 | 45 | unsigned int SDMAQueue::Rptr() { 46 | /* In SDMA queues read pointers are saved in bytes, convert the 47 | * read value to dword to fit the way BaseQueue works. On Vega10 48 | * the read ptr is 64-bit. We only read the low 32 bit (assuming 49 | * the queue buffer is smaller than 4GB) and modulo divide by the 50 | * queue size to simulate a 32-bit read pointer. 51 | */ 52 | return (*m_Resources.Queue_read_ptr % m_QueueBuf->Size()) / 53 | sizeof(unsigned int); 54 | } 55 | 56 | unsigned int SDMAQueue::RptrWhenConsumed() { 57 | /* Rptr is same size and byte units as Wptr. Here we only care 58 | * about the low 32-bits. When all packets are consumed, read and 59 | * write pointers should have the same value. 60 | */ 61 | return *m_Resources.Queue_write_ptr; 62 | } 63 | 64 | void SDMAQueue::SubmitPacket() { 65 | // m_pending Wptr is in dwords 66 | if (m_FamilyId < FAMILY_AI) { 67 | // Pre-Vega10 uses 32-bit wptr and doorbell 68 | unsigned int wPtrInBytes = m_pendingWptr * sizeof(unsigned int); 69 | MemoryBarrier(); 70 | *m_Resources.Queue_write_ptr = wPtrInBytes; 71 | MemoryBarrier(); 72 | *(m_Resources.Queue_DoorBell) = wPtrInBytes; 73 | } else { 74 | // Vega10 and later uses 64-bit wptr and doorbell 75 | HSAuint64 wPtrInBytes = m_pendingWptr64 * sizeof(unsigned int); 76 | MemoryBarrier(); 77 | *m_Resources.Queue_write_ptr_aql = wPtrInBytes; 78 | MemoryBarrier(); 79 | *(m_Resources.Queue_DoorBell_aql) = wPtrInBytes; 80 | } 81 | } 82 | 83 | void SDMAQueue::Wait4PacketConsumption(HsaEvent *event, unsigned int timeOut) { 84 | if (event) { 85 | PlacePacket(SDMAFencePacket(m_FamilyId, (void*)event->EventData.HWData2, event->EventId)); 86 | 87 | PlaceAndSubmitPacket(SDMATrapPacket(event->EventId)); 88 | 89 | EXPECT_SUCCESS(hsaKmtWaitOnEvent(event, timeOut)); 90 | } else { 91 | BaseQueue::Wait4PacketConsumption(NULL, timeOut); 92 | } 93 | } 94 | -------------------------------------------------------------------------------- /tests/kfdtest/src/GoogleTestExtension.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2018 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #ifndef __GOOGLETEST_EXTENSION__H__ 25 | #define __GOOGLETEST_EXTENSION__H__ 26 | 27 | #include 28 | #include "hsakmt/hsakmt.h" 29 | #include "KFDTestFlags.hpp" 30 | 31 | enum LOGTYPE { 32 | LOGTYPE_INFO, // msg header in green 33 | LOGTYPE_WARNING // msg header in yellow 34 | }; 35 | 36 | class KFDLog{}; 37 | std::ostream& operator << (KFDLog log, LOGTYPE level); 38 | 39 | // @brief Log additional details, to be displayed in the same format as other google test outputs 40 | // Currently not supported by gtest 41 | // Should be used like cout: LOG() << "message" << value << std::endl; 42 | #define LOG() KFDLog() << LOGTYPE_INFO 43 | #define WARN() KFDLog() << LOGTYPE_WARNING 44 | 45 | class KFDRecord: public testing::Test { 46 | public: 47 | KFDRecord(const char *val): m_val(val) {} 48 | KFDRecord(std::string &val): m_val(val) {} 49 | KFDRecord(HSAint64 val): m_val(std::to_string(val)) {} 50 | KFDRecord(HSAuint64 val): m_val(std::to_string(val)) {} 51 | KFDRecord(double val): m_val(std::to_string(val)) {} 52 | ~KFDRecord() { 53 | RecordProperty(m_key.str().c_str(), m_val.c_str()); 54 | } 55 | std::stringstream &get_key_stream() { 56 | return m_key; 57 | } 58 | virtual void TestBody() {}; 59 | private: 60 | std::string m_val; 61 | std::stringstream m_key; 62 | }; 63 | 64 | #define RECORD(val) (KFDRecord(val).get_key_stream()) 65 | 66 | // All tests MUST be in a try catch since the gtest flag to throw an exception on any fatal failure is enabled 67 | #define TEST_START(testProfile) if (Ok2Run(testProfile)) try { 68 | #define TEST_END } catch (...) {} 69 | 70 | // Used to wrap setup and teardown functions, anything that is built-in gtest and is not a test 71 | #define ROUTINE_START try { 72 | #define ROUTINE_END }catch(...) {} 73 | 74 | #define TEST_REQUIRE_ENV_CAPABILITIES(envCaps) if (!TestReqEnvCaps(envCaps)) return; 75 | #define TEST_REQUIRE_NO_ENV_CAPABILITIES(envCaps) if (!TestReqNoEnvCaps(envCaps)) return; 76 | 77 | #define ASSERT_SUCCESS(_val) ASSERT_EQ(HSAKMT_STATUS_SUCCESS, (_val)) 78 | #define EXPECT_SUCCESS(_val) EXPECT_EQ(HSAKMT_STATUS_SUCCESS, (_val)) 79 | 80 | #define ASSERT_NOTNULL(_val) ASSERT_NE((void *)NULL, _val) 81 | #define EXPECT_NOTNULL(_val) EXPECT_NE((void *)NULL, _val) 82 | 83 | // @brief Determines if it is ok to run a test given input flags 84 | bool Ok2Run(unsigned int testProfile); 85 | 86 | // @brief Checks if all HW capabilities needed for a test to run exist 87 | bool TestReqEnvCaps(unsigned int hwCaps); 88 | 89 | // @brief Checks if all HW capabilities that prevents a test from running are absent 90 | bool TestReqNoEnvCaps(unsigned int hwCaps); 91 | 92 | #endif 93 | -------------------------------------------------------------------------------- /tests/kfdtest/src/KFDTestMain.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2018 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #include "gtest/gtest.h" 25 | #include "KFDTestFlags.hpp" 26 | #include "KFDTestUtil.hpp" 27 | #include "GoogleTestExtension.hpp" 28 | #include "OSWrapper.hpp" 29 | 30 | #define KFD_TEST_DEFAULT_TIMEOUT 10000 31 | 32 | std::ostream& operator << (std::ostream& out, TESTPROFILE profile) { 33 | switch (profile) { 34 | case TESTPROFILE_DEV: 35 | out << "Developer Test"; 36 | break; 37 | case TESTPROFILE_PROMO: 38 | out << "Promotion Test"; 39 | break; 40 | case TESTPROFILE_RUNALL: 41 | out << "Full Test"; 42 | break; 43 | default: 44 | out << "INVALID"; 45 | } 46 | 47 | return out; 48 | } 49 | 50 | unsigned int g_TestRunProfile; 51 | unsigned int g_TestENVCaps; 52 | unsigned int g_TestTimeOut; 53 | int g_TestNodeId; 54 | int g_TestDstNodeId; 55 | bool g_IsChildProcess; 56 | bool g_IsEmuMode; 57 | unsigned int g_SleepTime; 58 | unsigned int g_TestGPUFamilyId; 59 | class KFDBaseComponentTest *g_baseTest; 60 | 61 | GTEST_API_ int main(int argc, char **argv) { 62 | // Default values for run parameters 63 | g_TestRunProfile = TESTPROFILE_RUNALL; 64 | g_TestENVCaps = ENVCAPS_NOADDEDCAPS | ENVCAPS_64BITLINUX; 65 | g_TestTimeOut = KFD_TEST_DEFAULT_TIMEOUT; 66 | 67 | testing::InitGoogleTest(&argc, argv); 68 | 69 | CommandLineArguments args; 70 | memset(&args, 0, sizeof(args)); 71 | 72 | bool success = GetCommandLineArguments(argc, argv, args); 73 | 74 | if (success) { 75 | if ((GetHwCapabilityHWS() || args.HwsEnabled == HWCAP__FORCE_ENABLED) && 76 | (args.HwsEnabled != HWCAP__FORCE_DISABLED)) 77 | g_TestENVCaps |= ENVCAPS_HWSCHEDULING; 78 | 79 | g_TestRunProfile = args.TestProfile; 80 | g_IsChildProcess = args.ChildProcess; 81 | 82 | if ( args.TimeOut > 0 ) 83 | g_TestTimeOut = args.TimeOut; 84 | 85 | g_SleepTime = 0x00; 86 | if (args.SleepTime > 0) { 87 | g_SleepTime = args.SleepTime; 88 | } 89 | 90 | // If --node is not specified, then args.NodeId == -1 91 | g_TestNodeId = args.NodeId; 92 | g_TestDstNodeId = args.DstNodeId; 93 | 94 | g_IsEmuMode = CheckEmuModeEnabled(); 95 | 96 | LOG() << "Profile: " << (TESTPROFILE)g_TestRunProfile << std::endl; 97 | LOG() << "HW capabilities: 0x" << std::hex << g_TestENVCaps << std::endl; 98 | if (g_IsEmuMode) 99 | { 100 | LOG() << "Emulation Mode Enabled" << std::endl; 101 | } 102 | 103 | if (g_SleepTime > 0) { 104 | LOG() << "Sleep time in seconds as specified by user: " << std::dec << g_SleepTime << std::endl; 105 | } 106 | 107 | return RUN_ALL_TESTS(); 108 | } 109 | } 110 | -------------------------------------------------------------------------------- /tests/kfdtest/src/OSWrapper.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2018 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #include 25 | #include 26 | #include 27 | 28 | #include "KFDTestFlags.hpp" 29 | #include "hsakmt/hsakmt.h" 30 | 31 | #ifndef __OS__WRAPPER__H__ 32 | #define __OS__WRAPPER__H__ 33 | 34 | #ifndef PAGE_SIZE 35 | #define PAGE_SIZE (1<<12) 36 | #define PAGE_SHIFT (12) 37 | #endif 38 | 39 | enum TEXTCOLOR { 40 | TEXTCOLOR_WHITE, 41 | TEXTCOLOR_GREEN, 42 | TEXTCOLOR_YELLOW 43 | }; 44 | 45 | enum OS_PRIVILEGE { 46 | OS_DRIVER_OPERATIONS, 47 | OS_SUSPEND 48 | }; 49 | 50 | enum CONFIG_VALUE { 51 | CONFIG_HWS 52 | }; 53 | 54 | enum HwCapabilityStatus { 55 | HWCAP__FORCE_DISABLED, 56 | HWCAP__DEFAULT, 57 | HWCAP__FORCE_ENABLED 58 | }; 59 | 60 | struct CommandLineArguments { 61 | HwCapabilityStatus HwsEnabled; 62 | TESTPROFILE TestProfile; 63 | bool ChildProcess; 64 | unsigned int TimeOut; 65 | int NodeId; 66 | int DstNodeId; 67 | /* Time in units of seconds */ 68 | unsigned int SleepTime; 69 | }; 70 | 71 | // It is either MEM_NONE or the bitwise OR of one or more of the following flags 72 | #define MEM_NONE 0x00 73 | #define MEM_READ 0x01 74 | #define MEM_WRITE 0x02 75 | #define MEM_EXECUTE 0x4 76 | 77 | // @brief Change console text color 78 | void SetConsoleTextColor(TEXTCOLOR color); 79 | // @params delayCount : delay time in milliseconds 80 | void Delay(int delayCount); 81 | // @brief Replacement for windows VirtualAlloc func 82 | void *VirtualAllocMemory(void *address, unsigned int size, int memProtection = MEM_READ | MEM_WRITE); 83 | // @brief Replacement for windows FreeVirtual func 84 | bool VirtualFreeMemory(void *address, unsigned int size); 85 | // @brief Retrieve the last error number 86 | HSAuint64 GetLastErrorNo(); 87 | 88 | HSAint64 AtomicInc(volatile HSAint64* pValue); 89 | 90 | void MemoryBarrier(); 91 | 92 | /* @brief: Runs the selected test case number of times required, each in a separate process 93 | * @params testToRun : Can be a specific test testcase like TestCase.TestName or if you want 94 | * to run all tests in a test case: TestCase.* and so on 95 | * @params numOfProcesses : How many processes to run in parallel 96 | * @params runsPerProcess : How many iteration a test should do per process, must be a positive number 97 | */ 98 | bool MultiProcessTest(const char *testToRun, int numOfProcesses, int runsPerProcess = 1); 99 | 100 | /* Put the system to S3/S4 power state and bring it back to S0. 101 | * @return 'true' on success, 'false' on failure. 102 | */ 103 | bool SuspendAndWakeUp(); 104 | 105 | bool ReadDriverConfigValue(CONFIG_VALUE config, unsigned int& rValue); 106 | 107 | bool GetCommandLineArguments(int argc, char **argv, CommandLineArguments& rArgs); 108 | 109 | void HWMemoryBarrier(); 110 | bool StartThread(unsigned int (*)(void*), void* pParam, uint64_t& threadId); 111 | bool WaitForThread(uint64_t threadId); 112 | 113 | #endif // __OS__WRAPPER__H__ 114 | -------------------------------------------------------------------------------- /tests/kfdtest/src/KFDGWSTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2019 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #include "KFDGWSTest.hpp" 25 | #include "PM4Queue.hpp" 26 | #include "PM4Packet.hpp" 27 | #include "Dispatch.hpp" 28 | 29 | void KFDGWSTest::SetUp() { 30 | ROUTINE_START 31 | 32 | KFDBaseComponentTest::SetUp(); 33 | 34 | ROUTINE_END 35 | } 36 | 37 | void KFDGWSTest::TearDown() { 38 | ROUTINE_START 39 | 40 | KFDBaseComponentTest::TearDown(); 41 | 42 | ROUTINE_END 43 | } 44 | 45 | TEST_F(KFDGWSTest, Allocate) { 46 | TEST_START(TESTPROFILE_RUNALL); 47 | 48 | HSAuint32 firstGWS; 49 | PM4Queue queue; 50 | int defaultGPUNode = m_NodeInfo.HsaDefaultGPUNode(); 51 | ASSERT_GE(defaultGPUNode, 0) << "failed to get default GPU Node"; 52 | const HsaNodeProperties *pNodeProperties = m_NodeInfo.HsaDefaultGPUNodeProperties(); 53 | if (!pNodeProperties || !pNodeProperties->NumGws) { 54 | LOG() << "Skip test: GPU node doesn't support GWS" << std::endl; 55 | return; 56 | } 57 | 58 | ASSERT_SUCCESS(queue.Create(defaultGPUNode)); 59 | ASSERT_SUCCESS(hsaKmtAllocQueueGWS(queue.GetResource()->QueueId, 60 | pNodeProperties->NumGws,&firstGWS)); 61 | EXPECT_EQ(0, firstGWS); 62 | EXPECT_SUCCESS(queue.Destroy()); 63 | 64 | TEST_END 65 | } 66 | 67 | TEST_F(KFDGWSTest, Semaphore) { 68 | TEST_START(TESTPROFILE_RUNALL); 69 | 70 | int defaultGPUNode = m_NodeInfo.HsaDefaultGPUNode(); 71 | ASSERT_GE(defaultGPUNode, 0) << "failed to get default GPU Node"; 72 | const HsaNodeProperties *pNodeProperties = m_NodeInfo.HsaDefaultGPUNodeProperties(); 73 | HSAuint32 firstGWS; 74 | HSAuint32 numResources = 1; 75 | PM4Queue queue; 76 | 77 | if (!pNodeProperties || !pNodeProperties->NumGws) { 78 | LOG() << "Skip test: GPU node doesn't support GWS" << std::endl; 79 | return; 80 | } 81 | 82 | HsaMemoryBuffer isaBuffer(PAGE_SIZE, defaultGPUNode, true/*zero*/, false/*local*/, true/*exec*/); 83 | HsaMemoryBuffer buffer(PAGE_SIZE, defaultGPUNode, true, false, false); 84 | ASSERT_SUCCESS(queue.Create(defaultGPUNode)); 85 | ASSERT_SUCCESS(hsaKmtAllocQueueGWS(queue.GetResource()->QueueId, 86 | pNodeProperties->NumGws,&firstGWS)); 87 | EXPECT_EQ(0, firstGWS); 88 | 89 | ASSERT_SUCCESS(m_pAsm->RunAssembleBuf(GwsInitIsa, isaBuffer.As())); 90 | 91 | Dispatch dispatch0(isaBuffer); 92 | buffer.Fill(numResources, 0, 4); 93 | dispatch0.SetArgs(buffer.As(), NULL); 94 | dispatch0.Submit(queue); 95 | dispatch0.Sync(); 96 | 97 | ASSERT_SUCCESS(m_pAsm->RunAssembleBuf(GwsAtomicIncreaseIsa, isaBuffer.As())); 98 | 99 | Dispatch dispatch(isaBuffer); 100 | dispatch.SetArgs(buffer.As(), NULL); 101 | dispatch.SetDim(1024, 16, 16); 102 | 103 | dispatch.Submit(queue); 104 | dispatch.Sync(); 105 | 106 | EXPECT_EQ(1024*16*16+1, *buffer.As()); 107 | EXPECT_SUCCESS(queue.Destroy()); 108 | 109 | TEST_END 110 | } 111 | 112 | -------------------------------------------------------------------------------- /src/rbtree_amd.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2018 Advanced Micro Devices, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, copy, 8 | * modify, merge, publish, distribute, sublicense, and/or sell copies 9 | * of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice (including 13 | * the next paragraph) shall be included in all copies or substantial 14 | * portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef _RBTREE_AMD_H_ 27 | #define _RBTREE_AMD_H_ 28 | 29 | typedef struct rbtree_key_s rbtree_key_t; 30 | struct rbtree_key_s { 31 | #define ADDR_BIT 0 32 | #define SIZE_BIT 1 33 | unsigned long addr; 34 | unsigned long size; 35 | }; 36 | #define BIT(x) (1<<(x)) 37 | #define LKP_ALL (BIT(ADDR_BIT) | BIT(SIZE_BIT)) 38 | #define LKP_ADDR (BIT(ADDR_BIT)) 39 | #define LKP_ADDR_SIZE (BIT(ADDR_BIT) | BIT(SIZE_BIT)) 40 | 41 | static inline rbtree_key_t 42 | rbtree_key(unsigned long addr, unsigned long size) 43 | { 44 | return (rbtree_key_t){addr, size}; 45 | } 46 | 47 | /* 48 | * compare addr, size one by one 49 | */ 50 | static inline int 51 | rbtree_key_compare(unsigned int type, rbtree_key_t *key1, rbtree_key_t *key2) 52 | { 53 | if ((type & 1 << ADDR_BIT) && (key1->addr != key2->addr)) 54 | return key1->addr > key2->addr ? 1 : -1; 55 | 56 | if ((type & 1 << SIZE_BIT) && (key1->size != key2->size)) 57 | return key1->size > key2->size ? 1 : -1; 58 | 59 | return 0; 60 | } 61 | #endif /*_RBTREE_AMD_H_*/ 62 | 63 | /*inlcude this file again with RBTREE_HELPER defined*/ 64 | #ifndef RBTREE_HELPER 65 | #define RBTREE_HELPER 66 | #else 67 | #ifndef _RBTREE_AMD_H_HELPER_ 68 | #define _RBTREE_AMD_H_HELPER_ 69 | static inline rbtree_node_t * 70 | rbtree_max(rbtree_node_t *node, rbtree_node_t *sentinel) 71 | { 72 | while (node->right != sentinel) 73 | node = node->right; 74 | 75 | return node; 76 | } 77 | 78 | #define LEFT 0 79 | #define RIGHT 1 80 | #define MID 2 81 | static inline rbtree_node_t * 82 | rbtree_min_max(rbtree_t *tree, int lr) 83 | { 84 | rbtree_node_t *sentinel = &tree->sentinel; 85 | rbtree_node_t *node = tree->root; 86 | 87 | if (node == sentinel) 88 | return NULL; 89 | 90 | if (lr == LEFT) 91 | node = rbtree_min(node, sentinel); 92 | else if (lr == RIGHT) 93 | node = rbtree_max(node, sentinel); 94 | 95 | return node; 96 | } 97 | 98 | static inline rbtree_node_t * 99 | rbtree_node_any(rbtree_t *tree, int lmr) 100 | { 101 | rbtree_node_t *sentinel = &tree->sentinel; 102 | rbtree_node_t *node = tree->root; 103 | 104 | if (node == sentinel) 105 | return NULL; 106 | 107 | if (lmr == MID) 108 | return node; 109 | 110 | return rbtree_min_max(tree, lmr); 111 | } 112 | 113 | static inline rbtree_node_t * 114 | rbtree_lookup_nearest(rbtree_t *rbtree, rbtree_key_t *key, 115 | unsigned int type, int lr) 116 | { 117 | int rc; 118 | rbtree_node_t *node, *sentinel, *n = NULL; 119 | 120 | node = rbtree->root; 121 | sentinel = &rbtree->sentinel; 122 | 123 | while (node != sentinel) { 124 | rc = rbtree_key_compare(type, key, &node->key); 125 | 126 | if (rc < 0) { 127 | if (lr == RIGHT) 128 | n = node; 129 | node = node->left; 130 | continue; 131 | } 132 | 133 | if (rc > 0) { 134 | if (lr == LEFT) 135 | n = node; 136 | node = node->right; 137 | continue; 138 | } 139 | 140 | return node; 141 | } 142 | 143 | return n; 144 | } 145 | 146 | static inline rbtree_node_t * 147 | rbtree_lookup(rbtree_t *rbtree, rbtree_key_t *key, 148 | unsigned int type) 149 | { 150 | return rbtree_lookup_nearest(rbtree, key, type, -1); 151 | } 152 | #endif /*_RBTREE_AMD_H_HELPER_*/ 153 | 154 | #endif /*RBTREE_HELPER*/ 155 | 156 | -------------------------------------------------------------------------------- /tests/reopen/kmtreopen.c: -------------------------------------------------------------------------------- 1 | #include 2 | #include 3 | #include 4 | #include 5 | 6 | HSAKMT_STATUS HSAKMTAPI (*pfn_hsaKmtOpenKFD)(void); 7 | HSAKMT_STATUS HSAKMTAPI (*pfn_hsaKmtCloseKFD)(void); 8 | HSAKMT_STATUS HSAKMTAPI (*pfn_hsaKmtGetVersion)(HsaVersionInfo* VersionInfo); 9 | HSAKMT_STATUS HSAKMTAPI (*pfn_hsaKmtAcquireSystemProperties)(HsaSystemProperties* SystemProperties); 10 | HSAKMT_STATUS HSAKMTAPI (*pfn_hsaKmtReleaseSystemProperties)(void); 11 | 12 | HsaVersionInfo g_versionInfo; 13 | HsaSystemProperties g_systemProperties; 14 | 15 | static void hsa_perror(const char *s, HSAKMT_STATUS status) 16 | { 17 | static const char *errorStrings[] = { 18 | [HSAKMT_STATUS_SUCCESS] = "Success", 19 | [HSAKMT_STATUS_ERROR] = "General error", 20 | [HSAKMT_STATUS_DRIVER_MISMATCH] = "Driver mismatch", 21 | [HSAKMT_STATUS_INVALID_PARAMETER] = "Invalid parameter", 22 | [HSAKMT_STATUS_INVALID_HANDLE] = "Invalid handle", 23 | [HSAKMT_STATUS_INVALID_NODE_UNIT] = "Invalid node or unit", 24 | [HSAKMT_STATUS_NO_MEMORY] = "No memory", 25 | [HSAKMT_STATUS_BUFFER_TOO_SMALL] = "Buffer too small", 26 | [HSAKMT_STATUS_NOT_IMPLEMENTED] = "Not implemented", 27 | [HSAKMT_STATUS_NOT_SUPPORTED] = "Not supported", 28 | [HSAKMT_STATUS_UNAVAILABLE] = "Unavailable", 29 | [HSAKMT_STATUS_KERNEL_IO_CHANNEL_NOT_OPENED] = "Kernel IO channel not opened", 30 | [HSAKMT_STATUS_KERNEL_COMMUNICATION_ERROR] = "Kernel communication error", 31 | [HSAKMT_STATUS_KERNEL_ALREADY_OPENED] = "Kernel already opened", 32 | [HSAKMT_STATUS_HSAMMU_UNAVAILABLE] = "HSA MMU unavailable", 33 | [HSAKMT_STATUS_WAIT_FAILURE] = "Wait failure", 34 | [HSAKMT_STATUS_WAIT_TIMEOUT] = "Wait timeout", 35 | [HSAKMT_STATUS_MEMORY_ALREADY_REGISTERED] = "Memory already registered", 36 | [HSAKMT_STATUS_MEMORY_NOT_REGISTERED] = "Memory not registered", 37 | [HSAKMT_STATUS_MEMORY_ALIGNMENT] = "Memory alignment error" 38 | }; 39 | 40 | if (status >= 0 && status <= HSAKMT_STATUS_MEMORY_ALIGNMENT) 41 | fprintf(stderr, "%s: %s\n", s, errorStrings[status]); 42 | else 43 | fprintf(stderr, "%s: Unknown error %d\n", s, status); 44 | } 45 | 46 | #define HSA_CHECK_RETURN(call) do { \ 47 | HSAKMT_STATUS __ret; \ 48 | printf(" Calling %s\n", #call); \ 49 | __ret = pfn_##call; \ 50 | if (__ret != HSAKMT_STATUS_SUCCESS) { \ 51 | hsa_perror(#call, __ret); \ 52 | return __ret; \ 53 | } \ 54 | } while(0) 55 | 56 | #define HSA_DLSYM(handle, func) do { \ 57 | pfn_##func = dlsym(handle, #func); \ 58 | if (pfn_##func == NULL) { \ 59 | fprintf(stderr, "dlsym failed: %s\n", dlerror()); \ 60 | return HSAKMT_STATUS_ERROR; \ 61 | } \ 62 | } while(0) 63 | 64 | static int runTest(void *handle) 65 | { 66 | HSA_DLSYM(handle, hsaKmtOpenKFD); 67 | HSA_DLSYM(handle, hsaKmtCloseKFD); 68 | HSA_DLSYM(handle, hsaKmtGetVersion); 69 | HSA_DLSYM(handle, hsaKmtAcquireSystemProperties); 70 | HSA_DLSYM(handle, hsaKmtReleaseSystemProperties); 71 | 72 | HSA_CHECK_RETURN(hsaKmtOpenKFD()); 73 | HSA_CHECK_RETURN(hsaKmtGetVersion(&g_versionInfo)); 74 | HSA_CHECK_RETURN(hsaKmtAcquireSystemProperties(&g_systemProperties)); 75 | 76 | HSA_CHECK_RETURN(hsaKmtReleaseSystemProperties()); 77 | HSA_CHECK_RETURN(hsaKmtCloseKFD()); 78 | 79 | return HSAKMT_STATUS_SUCCESS; 80 | } 81 | 82 | int main(int argc, char *argv[]) 83 | { 84 | void *handle; 85 | int i; 86 | 87 | for (i = 0; i < 5; i++) { 88 | printf("Iteration %d:\n Loading libhsakmt.so\n", i+1); 89 | 90 | handle = dlopen("libhsakmt.so", RTLD_LAZY); 91 | if (handle == NULL) { 92 | fprintf(stderr, "dlopen failed: %s\n", dlerror()); 93 | exit(1); 94 | } 95 | 96 | if (runTest(handle) != HSAKMT_STATUS_SUCCESS) 97 | exit(1); 98 | 99 | printf(" Unloading libhsakmt.so\n"); 100 | if (dlclose(handle) != 0) { 101 | fprintf(stderr, "dlclose failed: %s\n", dlerror()); 102 | exit(1); 103 | } 104 | } 105 | } 106 | -------------------------------------------------------------------------------- /tests/kfdtest/LICENSE.kfdtest: -------------------------------------------------------------------------------- 1 | KFDTest - KFD unit tests LICENSE 2 | /* The following license applies to all parts of kfdtest except the 3 | * SP3 shader assembler. See separate license terms below. 4 | */ 5 | 6 | Copyright (C) 2018 Advanced Micro Devices, Inc. All Rights Reserved. 7 | 8 | MIT LICENSE: 9 | Permission is hereby granted, free of charge, to any person obtaining 10 | a copy of this software and associated documentation files (the 11 | "Software"), to deal in the Software without restriction, including 12 | without limitation the rights to use, copy, modify, merge, publish, 13 | distribute, sublicense, and/or sell copies of the Software, and to 14 | permit persons to whom the Software is furnished to do so, subject to 15 | the following conditions: 16 | 17 | The above copyright notice and this permission notice shall be 18 | included in all copies or substantial portions of the Software. 19 | 20 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 21 | EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 22 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 23 | IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY 24 | CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, 25 | TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE 26 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 27 | 28 | ----------------------------------------------- 29 | 30 | libamdsp3 - AMD SP3 shader assembler library LICENSE 31 | /* The following license applies to the SP3 shader assembler, which is 32 | * named as libamdsp3.a and will be built into the kfdtest binary. 33 | */ 34 | 35 | Copyright (C) 2018 Advanced Micro Devices, Inc. All rights reserved. 36 | 37 | REDISTRIBUTION: Permission is hereby granted, free of any license fees, 38 | to any person obtaining a copy of this program (the "Software"), to 39 | install, reproduce, copy and distribute copies, in binary form only, of 40 | the Software and to permit persons to whom the Software is provided to 41 | do the same, provided that the following conditions are met: 42 | 43 | No reverse engineering, decompilation, or disassembly of this Software 44 | is permitted. 45 | 46 | Redistributions must reproduce the above copyright notice, this 47 | permission notice, and the following disclaimers and notices in the 48 | Software documentation and/or other materials provided with the 49 | Software. 50 | 51 | DISCLAIMER: THE USE OF THE SOFTWARE IS AT YOUR SOLE RISK. THE SOFTWARE 52 | IS PROVIDED "AS IS" AND WITHOUT WARRANTY OF ANY KIND AND COPYRIGHT 53 | HOLDER AND ITS LICENSORS EXPRESSLY DISCLAIM ALL WARRANTIES, EXPRESS AND 54 | IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 55 | MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NON-INFRINGEMENT. 56 | COPYRIGHT HOLDER AND ITS LICENSORS DO NOT WARRANT THAT THE SOFTWARE WILL 57 | MEET YOUR REQUIREMENTS, OR THAT THE OPERATION OF THE SOFTWARE WILL BE 58 | UNINTERRUPTED OR ERROR-FREE. THE ENTIRE RISK ASSOCIATED WITH THE USE OF 59 | THE SOFTWARE IS ASSUMED BY YOU. FURTHERMORE, COPYRIGHT HOLDER AND ITS 60 | LICENSORS DO NOT WARRANT OR MAKE ANY REPRESENTATIONS REGARDING THE USE 61 | OR THE RESULTS OF THE USE OF THE SOFTWARE IN TERMS OF ITS CORRECTNESS, 62 | ACCURACY, RELIABILITY, CURRENTNESS, OR OTHERWISE. 63 | 64 | DISCLAIMER: UNDER NO CIRCUMSTANCES INCLUDING NEGLIGENCE, SHALL COPYRIGHT 65 | HOLDER AND ITS LICENSORS OR ITS DIRECTORS, OFFICERS, EMPLOYEES OR AGENTS 66 | ("AUTHORIZED REPRESENTATIVES") BE LIABLE FOR ANY INCIDENTAL, INDIRECT, 67 | SPECIAL OR CONSEQUENTIAL DAMAGES (INCLUDING DAMAGES FOR LOSS OF BUSINESS 68 | PROFITS, BUSINESS INTERRUPTION, LOSS OF BUSINESS INFORMATION, AND THE 69 | LIKE) ARISING OUT OF THE USE, MISUSE OR INABILITY TO USE THE SOFTWARE, 70 | BREACH OR DEFAULT, INCLUDING THOSE ARISING FROM INFRINGEMENT OR ALLEGED 71 | INFRINGEMENT OF ANY PATENT, TRADEMARK, COPYRIGHT OR OTHER INTELLECTUAL 72 | PROPERTY RIGHT EVEN IF COPYRIGHT HOLDER AND ITS AUTHORIZED 73 | REPRESENTATIVES HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. IN 74 | NO EVENT SHALL COPYRIGHT HOLDER OR ITS AUTHORIZED REPRESENTATIVES TOTAL 75 | LIABILITY FOR ALL DAMAGES, LOSSES, AND CAUSES OF ACTION (WHETHER IN 76 | CONTRACT, TORT (INCLUDING NEGLIGENCE) OR OTHERWISE) EXCEED THE AMOUNT OF 77 | US$10. 78 | 79 | Notice: The Software is subject to United States export laws and 80 | regulations. You agree to comply with all domestic and international 81 | export laws and regulations that apply to the Software, including but 82 | not limited to the Export Administration Regulations administered by the 83 | U.S. Department of Commerce and International Traffic in Arm Regulations 84 | administered by the U.S. Department of State. These laws include 85 | restrictions on destinations, end users and end use. 86 | -------------------------------------------------------------------------------- /src/fmm.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright © 2014 Advanced Micro Devices, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person 5 | * obtaining a copy of this software and associated documentation 6 | * files (the "Software"), to deal in the Software without 7 | * restriction, including without limitation the rights to use, copy, 8 | * modify, merge, publish, distribute, sublicense, and/or sell copies 9 | * of the Software, and to permit persons to whom the Software is 10 | * furnished to do so, subject to the following conditions: 11 | * 12 | * The above copyright notice and this permission notice (including 13 | * the next paragraph) shall be included in all copies or substantial 14 | * portions of the Software. 15 | * 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 17 | * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 18 | * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND 19 | * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT 20 | * HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, 21 | * WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 22 | * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 23 | * DEALINGS IN THE SOFTWARE. 24 | */ 25 | 26 | #ifndef FMM_H_ 27 | #define FMM_H_ 28 | 29 | #include "hsakmt/hsakmttypes.h" 30 | #include 31 | 32 | typedef enum { 33 | FMM_FIRST_APERTURE_TYPE = 0, 34 | FMM_GPUVM = FMM_FIRST_APERTURE_TYPE, 35 | FMM_LDS, 36 | FMM_SCRATCH, 37 | FMM_SVM, 38 | FMM_MMIO, 39 | FMM_LAST_APERTURE_TYPE 40 | } aperture_type_e; 41 | 42 | typedef struct { 43 | aperture_type_e app_type; 44 | uint64_t size; 45 | void *start_address; 46 | } aperture_properties_t; 47 | 48 | HSAKMT_STATUS fmm_get_amdgpu_device_handle(uint32_t node_id, HsaAMDGPUDeviceHandle *DeviceHandle); 49 | HSAKMT_STATUS fmm_init_process_apertures(unsigned int NumNodes); 50 | void fmm_destroy_process_apertures(void); 51 | 52 | /* Memory interface */ 53 | void *fmm_allocate_scratch(uint32_t gpu_id, void *address, uint64_t MemorySizeInBytes); 54 | void *fmm_allocate_device(uint32_t gpu_id, uint32_t node_id, void *address, 55 | uint64_t MemorySizeInBytes, uint64_t alignment, HsaMemFlags flags); 56 | void *fmm_allocate_doorbell(uint32_t gpu_id, uint64_t MemorySizeInBytes, uint64_t doorbell_offset); 57 | void *fmm_allocate_host(uint32_t gpu_id, uint32_t node_id, void *address, uint64_t MemorySizeInBytes, 58 | uint64_t alignment, HsaMemFlags flags); 59 | void fmm_print(uint32_t node); 60 | HSAKMT_STATUS fmm_release(void *address); 61 | HSAKMT_STATUS fmm_map_to_gpu(void *address, uint64_t size, uint64_t *gpuvm_address); 62 | int fmm_unmap_from_gpu(void *address); 63 | bool fmm_get_handle(void *address, uint64_t *handle); 64 | HSAKMT_STATUS fmm_get_mem_info(const void *address, HsaPointerInfo *info); 65 | HSAKMT_STATUS fmm_set_mem_user_data(const void *mem, void *usr_data); 66 | #ifdef SANITIZER_AMDGPU 67 | HSAKMT_STATUS fmm_replace_asan_header_page(void* address); 68 | HSAKMT_STATUS fmm_return_asan_header_page(void* address); 69 | #endif 70 | 71 | /* Topology interface*/ 72 | HSAKMT_STATUS fmm_node_added(HSAuint32 gpu_id); 73 | HSAKMT_STATUS fmm_node_removed(HSAuint32 gpu_id); 74 | HSAKMT_STATUS fmm_get_aperture_base_and_limit(aperture_type_e aperture_type, HSAuint32 gpu_id, 75 | HSAuint64 *aperture_base, HSAuint64 *aperture_limit); 76 | 77 | HSAKMT_STATUS fmm_register_memory(void *address, uint64_t size_in_bytes, 78 | uint32_t *gpu_id_array, 79 | uint32_t gpu_id_array_size, 80 | bool coarse_grain, 81 | bool ext_coherent); 82 | HSAKMT_STATUS fmm_register_graphics_handle(HSAuint64 GraphicsResourceHandle, 83 | HsaGraphicsResourceInfo *GraphicsResourceInfo, 84 | uint32_t *gpu_id_array, 85 | uint32_t gpu_id_array_size); 86 | HSAKMT_STATUS fmm_deregister_memory(void *address); 87 | HSAKMT_STATUS fmm_export_dma_buf_fd(void *MemoryAddress, 88 | HSAuint64 MemorySizeInBytes, 89 | int *DMABufFd, 90 | HSAuint64 *Offset); 91 | HSAKMT_STATUS fmm_share_memory(void *MemoryAddress, 92 | HSAuint64 SizeInBytes, 93 | HsaSharedMemoryHandle *SharedMemoryHandle); 94 | HSAKMT_STATUS fmm_register_shared_memory(const HsaSharedMemoryHandle *SharedMemoryHandle, 95 | HSAuint64 *SizeInBytes, 96 | void **MemoryAddress, 97 | uint32_t *gpu_id_array, 98 | uint32_t gpu_id_array_size); 99 | HSAKMT_STATUS fmm_map_to_gpu_nodes(void *address, uint64_t size, 100 | uint32_t *nodes_to_map, uint64_t num_of_nodes, uint64_t *gpuvm_address); 101 | 102 | int open_drm_render_device(int minor); 103 | void *mmap_allocate_aligned(int prot, int flags, uint64_t size, uint64_t align, 104 | uint64_t guard_size, void *aper_base, void *aper_limit); 105 | 106 | extern int (*fn_amdgpu_device_get_fd)(HsaAMDGPUDeviceHandle device_handle); 107 | #endif /* FMM_H_ */ 108 | -------------------------------------------------------------------------------- /tests/kfdtest/include/pm4_pkt_struct_ci.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2012-2018 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #ifndef __PM4_PKT_STRUCT_CI_H__ 25 | #define __PM4_PKT_STRUCT_CI_H__ 26 | 27 | 28 | enum WRITE_DATA_CI_atc_enum { atc_write_data_NOT_USE_ATC_0 = 0, atc_write_data_USE_ATC_1 = 1 }; 29 | enum WRITE_DATA_CI_engine_sel { engine_sel_write_data_ci_MICRO_ENGINE_0 = 0, engine_sel_write_data_ci_PREFETCH_PARSER_1 = 1, engine_sel_write_data_ci_CONST_ENG_2 = 2 }; 30 | 31 | typedef struct _PM4WRITE_DATA_CI { 32 | union { 33 | PM4_TYPE_3_HEADER header; 34 | unsigned int ordinal1; 35 | }; 36 | 37 | union { 38 | struct { 39 | unsigned int reserved1:8; 40 | MEC_WRITE_DATA_dst_sel_enum dst_sel:4; 41 | unsigned int reserved2:4; 42 | MEC_WRITE_DATA_addr_incr_enum addr_incr:1; 43 | unsigned int reserved3:3; 44 | MEC_WRITE_DATA_wr_confirm_enum wr_confirm:1; 45 | unsigned int reserved4:3; 46 | WRITE_DATA_CI_atc_enum atc:1; 47 | MEC_WRITE_DATA_cache_policy_enum cache_policy:2; 48 | unsigned int volatile_setting:1; 49 | unsigned int reserved5:2; 50 | WRITE_DATA_CI_engine_sel engine_sel:2; 51 | } bitfields2; 52 | unsigned int ordinal2; 53 | }; 54 | 55 | unsigned int dst_addr_lo; 56 | 57 | unsigned int dst_address_hi; 58 | 59 | unsigned int data[1]; // 1..N of these fields 60 | } PM4WRITE_DATA_CI, *PPM4WRITE_DATA_CI; 61 | 62 | 63 | enum MEC_RELEASE_MEM_CI_atc_enum { atc_mec_release_mem_ci_NOT_USE_ATC_0 = 0, atc_mec_release_mem_ci_USE_ATC_1 = 1 }; 64 | 65 | typedef struct _PM4_RELEASE_MEM_CI { 66 | union { 67 | PM4_TYPE_3_HEADER header; 68 | unsigned int ordinal1; 69 | }; 70 | 71 | union { 72 | struct { 73 | unsigned int event_type:6; 74 | unsigned int reserved1:2; 75 | MEC_RELEASE_MEM_event_index_enum event_index:4; 76 | unsigned int l1_vol:1; 77 | unsigned int l2_vol:1; 78 | unsigned int reserved:1; 79 | unsigned int l2_wb:1; 80 | unsigned int l1_inv:1; 81 | unsigned int l2_inv:1; 82 | unsigned int reserved2:6; 83 | MEC_RELEASE_MEM_CI_atc_enum atc:1; 84 | MEC_RELEASE_MEM_cache_policy_enum cache_policy:2; 85 | unsigned int volatile_setting:1; 86 | unsigned int reserved3:4; 87 | } bitfields2; 88 | unsigned int ordinal2; 89 | }; 90 | 91 | union { 92 | struct { 93 | unsigned int reserved4:16; 94 | MEC_RELEASE_MEM_dst_sel_enum dst_sel:2; 95 | unsigned int reserved5:6; 96 | MEC_RELEASE_MEM_int_sel_enum int_sel:3; 97 | unsigned int reserved6:2; 98 | MEC_RELEASE_MEM_data_sel_enum data_sel:3; 99 | } bitfields3; 100 | unsigned int ordinal3; 101 | }; 102 | 103 | union { 104 | struct { 105 | unsigned int reserved7:2; 106 | unsigned int address_lo_dword_aligned:30; 107 | } bitfields4a; 108 | struct { 109 | unsigned int reserved8:3; 110 | unsigned int address_lo_qword_aligned:29; 111 | } bitfields4b; 112 | unsigned int ordinal4; 113 | }; 114 | 115 | unsigned int addr_hi; 116 | 117 | union { 118 | unsigned int data_lo; 119 | struct { 120 | unsigned int offset:16; 121 | unsigned int num_dwords:16; 122 | } bitfields5b; 123 | unsigned int ordinal6; 124 | }; 125 | 126 | unsigned int data_hi; 127 | } PM4_RELEASE_MEM_CI, *PPM4_RELEASE_MEM_CI; 128 | 129 | #endif // __PM4_PKT_STRUCT_CI_H__ 130 | -------------------------------------------------------------------------------- /hsakmt-backward-compat.cmake: -------------------------------------------------------------------------------- 1 | # Copyright (c) 2022 Advanced Micro Devices, Inc. All Rights Reserved. 2 | # Permission is hereby granted, free of charge, to any person obtaining a copy 3 | # of this software and associated documentation files (the "Software"), to deal 4 | # in the Software without restriction, including without limitation the rights 5 | # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 6 | # copies of the Software, and to permit persons to whom the Software is 7 | # furnished to do so, subject to the following conditions: 8 | # 9 | # The above copyright notice and this permission notice shall be included in 10 | # all copies or substantial portions of the Software. 11 | # 12 | # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 13 | # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 14 | # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 15 | # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 16 | # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 17 | # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 18 | # THE SOFTWARE. 19 | 20 | set(HSAKMT_WRAPPER_DIR ${CMAKE_CURRENT_BINARY_DIR}/wrapper_dir) 21 | set(HSAKMT_WRAPPER_INC_DIR ${HSAKMT_WRAPPER_DIR}/include) 22 | #Function to generate header template file 23 | function(create_header_template) 24 | file(WRITE ${HSAKMT_WRAPPER_DIR}/header.hpp.in "/* 25 | Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved. 26 | 27 | Permission is hereby granted, free of charge, to any person obtaining a copy 28 | of this software and associated documentation files (the \"Software\"), to deal 29 | in the Software without restriction, including without limitation the rights 30 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 31 | copies of the Software, and to permit persons to whom the Software is 32 | furnished to do so, subject to the following conditions: 33 | 34 | The above copyright notice and this permission notice shall be included in 35 | all copies or substantial portions of the Software. 36 | 37 | THE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 38 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 39 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 40 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 41 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 42 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN 43 | THE SOFTWARE. 44 | */ 45 | 46 | #ifndef @include_guard@ 47 | #define @include_guard@ 48 | 49 | #ifndef ROCM_HEADER_WRAPPER_WERROR 50 | #define ROCM_HEADER_WRAPPER_WERROR @deprecated_error@ 51 | #endif 52 | #if ROCM_HEADER_WRAPPER_WERROR /* ROCM_HEADER_WRAPPER_WERROR 1 */ 53 | #error \"@file_name@ has moved to @CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_INCLUDEDIR@/hsakmt and package include paths have changed.\\nInclude as \\\"hsakmt/@file_name@\\\" when using cmake packages.\" 54 | #else /* ROCM_HEADER_WRAPPER_WERROR 0 */ 55 | #if defined(__GNUC__) 56 | #warning \"@file_name@ has moved to @CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_INCLUDEDIR@/hsakmt and package include paths have changed.\\nInclude as \\\"hsakmt/@file_name@\\\" when using cmake packages.\" 57 | #else 58 | #pragma message(\"@file_name@ has moved to @CMAKE_INSTALL_PREFIX@/@CMAKE_INSTALL_INCLUDEDIR@/hsakmt and package include paths have changed.\\nInclude as \\\"hsakmt/@file_name@\\\" when using cmake packages.\") 59 | #endif 60 | #endif /* ROCM_HEADER_WRAPPER_WERROR */ 61 | 62 | @include_statements@ 63 | 64 | #endif") 65 | endfunction() 66 | 67 | #use header template file and generate wrapper header files 68 | function(generate_wrapper_header) 69 | file(MAKE_DIRECTORY ${HSAKMT_WRAPPER_INC_DIR}) 70 | #find all header files from include folder 71 | file(GLOB include_files ${CMAKE_CURRENT_SOURCE_DIR}/include/*.h) 72 | #generate wrapper header files 73 | foreach(header_file ${include_files}) 74 | # set include guard 75 | get_filename_component(INC_GUARD_NAME ${header_file} NAME_WE) 76 | string(TOUPPER ${INC_GUARD_NAME} INC_GUARD_NAME) 77 | set(include_guard "${include_guard}HSAKMT_WRAPPER_INCLUDE_${INC_GUARD_NAME}_H") 78 | # set include statements 79 | get_filename_component(file_name ${header_file} NAME) 80 | set(include_statements "${include_statements}#include \"hsakmt/${file_name}\"\n") 81 | configure_file(${HSAKMT_WRAPPER_DIR}/header.hpp.in ${HSAKMT_WRAPPER_INC_DIR}/${file_name}) 82 | unset(include_guard) 83 | unset(include_statements) 84 | endforeach() 85 | endfunction() 86 | 87 | #Creater a template for header file 88 | create_header_template() 89 | #Use template header file and generater wrapper header files 90 | generate_wrapper_header() 91 | install(DIRECTORY ${HSAKMT_WRAPPER_INC_DIR} DESTINATION . COMPONENT devel PATTERN "linux" EXCLUDE) 92 | -------------------------------------------------------------------------------- /tests/kfdtest/src/KFDHWSTest.cpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2019 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #include "KFDHWSTest.hpp" 25 | 26 | void KFDHWSTest::SetUp() { 27 | ROUTINE_START 28 | 29 | KFDBaseComponentTest::SetUp(); 30 | 31 | ROUTINE_END 32 | } 33 | 34 | void KFDHWSTest::TearDown() { 35 | ROUTINE_START 36 | 37 | KFDBaseComponentTest::TearDown(); 38 | 39 | ROUTINE_END 40 | } 41 | 42 | void KFDHWSTest::RunTest(unsigned nProcesses, unsigned nQueues, unsigned nLoops) { 43 | int defaultGPUNode = m_NodeInfo.HsaDefaultGPUNode(); 44 | ASSERT_GE(defaultGPUNode, 0) << "failed to get default GPU Node"; 45 | 46 | unsigned q, l; 47 | bool timeout = false; 48 | 49 | /* Fork the child processes */ 50 | ForkChildProcesses(nProcesses); 51 | 52 | // Create queues 53 | PM4Queue *queues = new PM4Queue[nQueues]; 54 | for (q = 0; q < nQueues; q++) 55 | ASSERT_SUCCESS(queues[q].Create(defaultGPUNode)); 56 | 57 | // Create dispatch pointers. Each loop iteration creates fresh dispatches 58 | Dispatch **dispatch = new Dispatch*[nQueues]; 59 | for (q = 0; q < nQueues; q++) 60 | dispatch[q] = NULL; 61 | 62 | // Logging: Each process prints its index after each loop iteration, all in one line. 63 | std::ostream &log = LOG() << std::dec << "Process " << m_ProcessIndex << " starting." << std::endl; 64 | 65 | // Run work on all queues 66 | HsaMemoryBuffer isaBuffer(PAGE_SIZE, defaultGPUNode, true/*zero*/, false/*local*/, true/*exec*/); 67 | 68 | ASSERT_SUCCESS(m_pAsm->RunAssembleBuf(NoopIsa, isaBuffer.As())); 69 | 70 | for (l = 0; l < nLoops; l++) { 71 | for (q = 0; q < nQueues; q++) { 72 | if (dispatch[q]) 73 | delete dispatch[q]; 74 | dispatch[q] = new Dispatch(isaBuffer); 75 | dispatch[q]->SetArgs(NULL, NULL); 76 | dispatch[q]->SetDim(1, 1, 1); 77 | dispatch[q]->Submit(queues[q]); 78 | } 79 | for (q = 0; q < nQueues; q++) { 80 | timeout = dispatch[q]->SyncWithStatus(g_TestTimeOut); 81 | if (timeout) 82 | goto timeout; 83 | } 84 | log << m_ProcessIndex; 85 | } 86 | 87 | timeout: 88 | log << std::endl; 89 | if (timeout) { 90 | WARN() << "Process " << m_ProcessIndex << " timeout." << std::endl; 91 | } else { 92 | LOG() << "Process " << m_ProcessIndex << " done. Waiting ..." << std::endl; 93 | 94 | // Wait here before destroying queues. If another process' queues 95 | // are soft-hanging, destroying queues can resolve the soft-hang 96 | // by changing the run list. Make sure the other process's 97 | // dispatches have a chance to time out first. 98 | Delay(g_TestTimeOut+1000); 99 | } 100 | 101 | // Destroy queues and dispatches. Destroying the queues first 102 | // ensures that the memory allocated by the Dispatch is no longer 103 | // accessed by the GPU. 104 | LOG() << "Process " << m_ProcessIndex << " cleaning up." << std::endl; 105 | for (q = 0; q < nQueues; q++) { 106 | EXPECT_SUCCESS(queues[q].Destroy()); 107 | if (dispatch[q]) 108 | delete dispatch[q]; 109 | } 110 | delete[] queues; 111 | delete[] dispatch; 112 | 113 | // This is after all the cleanup to avoid leaving any garbage 114 | // behind, but before WaitChildProcesses to ensure a child process 115 | // with a timeout exits with an error that can be detected by the 116 | // parent. 117 | ASSERT_FALSE(timeout); 118 | 119 | WaitChildProcesses(); 120 | } 121 | 122 | TEST_F(KFDHWSTest, MultiProcessOversubscribed) { 123 | TEST_REQUIRE_ENV_CAPABILITIES(ENVCAPS_64BITLINUX); 124 | TEST_START(TESTPROFILE_RUNALL); 125 | 126 | RunTest(3, 13, 40); 127 | 128 | TEST_END 129 | } 130 | -------------------------------------------------------------------------------- /tests/kfdtest/include/kfd_pm4_opcodes.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2018 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | 25 | #ifndef KFD_PM4_OPCODES_H 26 | #define KFD_PM4_OPCODES_H 27 | 28 | enum it_opcode_type { 29 | IT_NOP = 0x10, 30 | IT_SET_BASE = 0x11, 31 | IT_CLEAR_STATE = 0x12, 32 | IT_INDEX_BUFFER_SIZE = 0x13, 33 | IT_DISPATCH_DIRECT = 0x15, 34 | IT_DISPATCH_INDIRECT = 0x16, 35 | IT_ATOMIC_GDS = 0x1D, 36 | IT_OCCLUSION_QUERY = 0x1F, 37 | IT_SET_PREDICATION = 0x20, 38 | IT_REG_RMW = 0x21, 39 | IT_COND_EXEC = 0x22, 40 | IT_PRED_EXEC = 0x23, 41 | IT_DRAW_INDIRECT = 0x24, 42 | IT_DRAW_INDEX_INDIRECT = 0x25, 43 | IT_INDEX_BASE = 0x26, 44 | IT_DRAW_INDEX_2 = 0x27, 45 | IT_CONTEXT_CONTROL = 0x28, 46 | IT_INDEX_TYPE = 0x2A, 47 | IT_DRAW_INDIRECT_MULTI = 0x2C, 48 | IT_DRAW_INDEX_AUTO = 0x2D, 49 | IT_NUM_INSTANCES = 0x2F, 50 | IT_DRAW_INDEX_MULTI_AUTO = 0x30, 51 | IT_INDIRECT_BUFFER_CNST = 0x33, 52 | IT_STRMOUT_BUFFER_UPDATE = 0x34, 53 | IT_DRAW_INDEX_OFFSET_2 = 0x35, 54 | IT_DRAW_PREAMBLE = 0x36, 55 | IT_WRITE_DATA = 0x37, 56 | IT_DRAW_INDEX_INDIRECT_MULTI = 0x38, 57 | IT_MEM_SEMAPHORE = 0x39, 58 | IT_COPY_DW = 0x3B, 59 | IT_WAIT_REG_MEM = 0x3C, 60 | IT_INDIRECT_BUFFER = 0x3F, 61 | IT_COPY_DATA = 0x40, 62 | IT_PFP_SYNC_ME = 0x42, 63 | IT_SURFACE_SYNC = 0x43, 64 | IT_COND_WRITE = 0x45, 65 | IT_EVENT_WRITE = 0x46, 66 | IT_EVENT_WRITE_EOP = 0x47, 67 | IT_EVENT_WRITE_EOS = 0x48, 68 | IT_RELEASE_MEM = 0x49, 69 | IT_PREAMBLE_CNTL = 0x4A, 70 | IT_DMA_DATA = 0x50, 71 | IT_ACQUIRE_MEM = 0x58, 72 | IT_REWIND = 0x59, 73 | IT_LOAD_UCONFIG_REG = 0x5E, 74 | IT_LOAD_SH_REG = 0x5F, 75 | IT_LOAD_CONFIG_REG = 0x60, 76 | IT_LOAD_CONTEXT_REG = 0x61, 77 | IT_SET_CONFIG_REG = 0x68, 78 | IT_SET_CONTEXT_REG = 0x69, 79 | IT_SET_CONTEXT_REG_INDIRECT = 0x73, 80 | IT_SET_SH_REG = 0x76, 81 | IT_SET_SH_REG_OFFSET = 0x77, 82 | IT_SET_QUEUE_REG = 0x78, 83 | IT_SET_UCONFIG_REG = 0x79, 84 | IT_SCRATCH_RAM_WRITE = 0x7D, 85 | IT_SCRATCH_RAM_READ = 0x7E, 86 | IT_LOAD_CONST_RAM = 0x80, 87 | IT_WRITE_CONST_RAM = 0x81, 88 | IT_DUMP_CONST_RAM = 0x83, 89 | IT_INCREMENT_CE_COUNTER = 0x84, 90 | IT_INCREMENT_DE_COUNTER = 0x85, 91 | IT_WAIT_ON_CE_COUNTER = 0x86, 92 | IT_WAIT_ON_DE_COUNTER_DIFF = 0x88, 93 | IT_SWITCH_BUFFER = 0x8B, 94 | IT_SET_RESOURCES = 0xA0, 95 | IT_MAP_PROCESS = 0xA1, 96 | IT_MAP_QUEUES = 0xA2, 97 | IT_UNMAP_QUEUES = 0xA3, 98 | IT_QUERY_STATUS = 0xA4, 99 | IT_RUN_LIST = 0xA5, 100 | }; 101 | 102 | #define PM4_TYPE_0 0 103 | #define PM4_TYPE_2 2 104 | #define PM4_TYPE_3 3 105 | 106 | #endif /* KFD_PM4_OPCODES_H */ 107 | 108 | -------------------------------------------------------------------------------- /tests/kfdtest/include/pm4_pkt_struct_nv.h: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright 2018 Advanced Micro Devices, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #ifndef __PM4__PKT__STRUCT__NV__HPP__ 25 | #define __PM4__PKT__STRUCT__NV__HPP__ 26 | 27 | #include "pm4_pkt_struct_ai.h" 28 | 29 | typedef struct _PM4_ACQUIRE_MEM_NV 30 | { 31 | union 32 | { 33 | PM4_TYPE_3_HEADER header; ///header 34 | unsigned int ordinal1; 35 | }; 36 | 37 | unsigned int reserved; 38 | 39 | unsigned int coher_size; 40 | 41 | 42 | union 43 | { 44 | struct 45 | { 46 | unsigned int coher_size_hi:8; 47 | unsigned int reserved1:24; 48 | } bitfields3; 49 | unsigned int ordinal4; 50 | }; 51 | 52 | unsigned int coher_base_lo; 53 | 54 | 55 | union 56 | { 57 | struct 58 | { 59 | unsigned int coher_base_hi:24; 60 | unsigned int reserved2:8; 61 | } bitfields4; 62 | unsigned int ordinal6; 63 | }; 64 | 65 | union 66 | { 67 | struct 68 | { 69 | unsigned int poll_interval:16; 70 | unsigned int reserved3:16; 71 | } bitfields5; 72 | unsigned int ordinal7; 73 | }; 74 | 75 | union 76 | { 77 | struct 78 | { 79 | unsigned int gcr_cntl:18; 80 | unsigned int reserved4:14; 81 | } bitfields6; 82 | unsigned int ordinal8; 83 | }; 84 | 85 | 86 | } PM4ACQUIRE_MEM_NV, *PPM4ACQUIRE_MEM_NV; 87 | 88 | typedef struct PM4_MEC_RELEASE_MEM_NV { 89 | union { 90 | PM4_TYPE_3_HEADER header; 91 | unsigned int ordinal1; 92 | }; 93 | 94 | union { 95 | struct { 96 | unsigned int event_type:6; 97 | unsigned int reserved1:2; 98 | AI_MEC_RELEASE_MEM_event_index_enum event_index:4; 99 | unsigned int gcr_cntl:12; 100 | unsigned int reserved4:1; 101 | AI_MEC_RELEASE_MEM_cache_policy_enum cache_policy:2; 102 | unsigned int reserved5:1; 103 | AI_MEC_RELEASE_MEM_pq_exe_status_enum pq_exe_status:1; 104 | unsigned int reserved6:3; 105 | } bitfields2; 106 | unsigned int ordinal2; 107 | }; 108 | 109 | union { 110 | struct { 111 | unsigned int reserved7:16; 112 | AI_MEC_RELEASE_MEM_dst_sel_enum dst_sel:2; 113 | unsigned int reserved8:6; 114 | AI_MEC_RELEASE_MEM_int_sel_enum int_sel:3; 115 | unsigned int reserved9:2; 116 | AI_MEC_RELEASE_MEM_data_sel_enum data_sel:3; 117 | } bitfields3; 118 | unsigned int ordinal3; 119 | }; 120 | 121 | union { 122 | struct { 123 | unsigned int reserved10:2; 124 | unsigned int address_lo_32b:30; 125 | } bitfields4a; 126 | struct { 127 | unsigned int reserved11:3; 128 | unsigned int address_lo_64b:29; 129 | } bitfields4b; 130 | unsigned int reserved12; 131 | 132 | unsigned int ordinal4; 133 | }; 134 | 135 | union { 136 | unsigned int address_hi; 137 | 138 | unsigned int reserved13; 139 | 140 | unsigned int ordinal5; 141 | }; 142 | 143 | union { 144 | unsigned int data_lo; 145 | 146 | unsigned int cmp_data_lo; 147 | 148 | struct { 149 | unsigned int dw_offset:16; 150 | unsigned int num_dwords:16; 151 | } bitfields6c; 152 | unsigned int reserved14; 153 | 154 | unsigned int ordinal6; 155 | }; 156 | 157 | union { 158 | unsigned int data_hi; 159 | 160 | unsigned int cmp_data_hi; 161 | 162 | unsigned int reserved15; 163 | 164 | unsigned int reserved16; 165 | 166 | unsigned int ordinal7; 167 | }; 168 | 169 | unsigned int int_ctxid; 170 | } PM4MEC_RELEASE_MEM_NV, *PPM4MEC_RELEASE_MEM_NV; 171 | 172 | 173 | #endif // __PM4__PKT__STRUCT__NV__HPP__ 174 | -------------------------------------------------------------------------------- /tests/kfdtest/src/KFDIPCTest.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2017-2018 Advanced Micro Devices, Inc. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | 24 | #include "KFDBaseComponentTest.hpp" 25 | #include "BaseQueue.hpp" 26 | 27 | #ifndef __KFD_MEMORY_TEST__H__ 28 | #define __KFD_MEMORY_TEST__H__ 29 | 30 | #define CMA_MEMORY_TEST_ARRAY_SIZE 4 31 | #define CMA_TEST_COUNT 3 32 | 33 | enum CMA_MEM_TYPE { 34 | CMA_MEM_TYPE_SYSTEM = 0, 35 | CMA_MEM_TYPE_USERPTR, 36 | CMA_MEM_TYPE_LOCAL_MEM, 37 | }; 38 | 39 | enum CMA_TEST_TYPE { 40 | CMA_READ_TEST = 0, 41 | CMA_WRITE_TEST 42 | }; 43 | 44 | enum CMA_TEST_STATUS { 45 | CMA_TEST_SUCCESS = 0, 46 | CMA_IPC_PIPE_ERROR = 1, 47 | CMA_CHECK_PATTERN_ERROR, 48 | CMA_TEST_ABORT, 49 | CMA_TEST_NOMEM, 50 | CMA_PARENT_FAIL, 51 | CMA_TEST_HSA_READ_FAIL, 52 | CMA_TEST_HSA_WRITE_FAIL 53 | }; 54 | 55 | /* @struct testMemoryDescriptor 56 | * @brief Describes test buffers for Cross Memory Attach Test. 57 | */ 58 | struct testMemoryDescriptor { 59 | CMA_MEM_TYPE m_MemType; 60 | HSAuint64 m_MemSize; 61 | /* The buffer will be initialized with this pattern */ 62 | HSAuint32 m_FillPattern; 63 | /* After CMA test, this pattern is expected in the first word */ 64 | HSAuint32 m_CheckFirstWordPattern; 65 | /* After CMA test, this pattern is expected in the last word */ 66 | HSAuint32 m_CheckLastWordPattern; 67 | 68 | testMemoryDescriptor(CMA_MEM_TYPE memType, HSAuint64 memSize, 69 | HSAuint32 fillPattern, HSAuint32 firstCheckPattern, 70 | HSAuint32 lastCheckPattern) : 71 | m_MemType(memType), 72 | m_MemSize(memSize), 73 | m_FillPattern(fillPattern), 74 | m_CheckFirstWordPattern(firstCheckPattern), 75 | m_CheckLastWordPattern(lastCheckPattern) {} 76 | ~testMemoryDescriptor(){} 77 | }; 78 | 79 | /* @class KFDCMAArray 80 | * @brief Array of buffers that will be passed between the parent and child 81 | * process for Cross memory read and write tests 82 | */ 83 | class KFDCMAArray { 84 | /* Used to store the actual buffer array */ 85 | HsaMemoryBuffer* m_MemArray[CMA_MEMORY_TEST_ARRAY_SIZE]; 86 | /* Used for passing to thunk CMA functions */ 87 | HsaMemoryRange m_HsaMemoryRange[CMA_MEMORY_TEST_ARRAY_SIZE]; 88 | /* Though previous arrays are fixed sizes only m_ValidCount 89 | * ones are valid 90 | */ 91 | HSAuint64 m_ValidCount; 92 | QueueArray m_QueueArray; 93 | 94 | public: 95 | KFDCMAArray(); 96 | ~KFDCMAArray() { 97 | Destroy(); 98 | } 99 | 100 | CMA_TEST_STATUS Init(testMemoryDescriptor(*memDescriptor)[CMA_MEMORY_TEST_ARRAY_SIZE], int node); 101 | CMA_TEST_STATUS Destroy(); 102 | 103 | HsaMemoryRange* getMemoryRange() { return m_HsaMemoryRange; } 104 | HSAuint64 getValidRangeCount() { return m_ValidCount; } 105 | void FillPattern(testMemoryDescriptor(*memDescriptor)[CMA_MEMORY_TEST_ARRAY_SIZE]); 106 | CMA_TEST_STATUS checkPattern(testMemoryDescriptor(*memDescriptor)[CMA_MEMORY_TEST_ARRAY_SIZE]); 107 | CMA_TEST_STATUS sendCMAArray(int writePipe); 108 | CMA_TEST_STATUS recvCMAArray(int readPipe); 109 | }; 110 | 111 | 112 | // @class KFDIPCTest 113 | class KFDIPCTest : public KFDBaseComponentTest { 114 | public: 115 | KFDIPCTest(void) : m_ChildPid(-1) {} 116 | ~KFDIPCTest(void); 117 | protected: 118 | virtual void SetUp(); 119 | virtual void TearDown(); 120 | 121 | /* For IPC testing */ 122 | void BasicTestChildProcess(int defaultGPUNode, int *pipefd, HsaMemFlags mflags); 123 | void BasicTestParentProcess(int defaultGPUNode, pid_t childPid, int *pipefd, HsaMemFlags mflags); 124 | 125 | /* For CMA testing */ 126 | CMA_TEST_STATUS CrossMemoryAttachChildProcess(int defaultGPUNode, int writePipe, 127 | int readPipe, CMA_TEST_TYPE testType); 128 | CMA_TEST_STATUS CrossMemoryAttachParentProcess(int defaultGPUNode, pid_t cid, 129 | int writePipe, int readPipe, CMA_TEST_TYPE testType); 130 | protected: 131 | pid_t m_ChildPid; 132 | }; 133 | 134 | #endif // __KFD_MEMORY_TEST__H__ 135 | -------------------------------------------------------------------------------- /tests/kfdtest/src/KFDBaseComponentTest.hpp: -------------------------------------------------------------------------------- 1 | /* 2 | * Copyright (C) 2014-2018 Advanced Micro Devices, Inc. All Rights Reserved. 3 | * 4 | * Permission is hereby granted, free of charge, to any person obtaining a 5 | * copy of this software and associated documentation files (the "Software"), 6 | * to deal in the Software without restriction, including without limitation 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8 | * and/or sell copies of the Software, and to permit persons to whom the 9 | * Software is furnished to do so, subject to the following conditions: 10 | * 11 | * The above copyright notice and this permission notice shall be included in 12 | * all copies or substantial portions of the Software. 13 | * 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17 | * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20 | * OTHER DEALINGS IN THE SOFTWARE. 21 | * 22 | */ 23 | #ifndef __KFD_BASE_COMPONENT_TEST__H__ 24 | #define __KFD_BASE_COMPONENT_TEST__H__ 25 | 26 | #include 27 | #include 28 | #include 29 | #include 30 | #include 31 | #include 32 | #include 33 | #include 34 | #include "hsakmt/hsakmt.h" 35 | #include "OSWrapper.hpp" 36 | #include "KFDTestUtil.hpp" 37 | #include "Assemble.hpp" 38 | #include "ShaderStore.hpp" 39 | 40 | // @class KFDBaseComponentTest 41 | class KFDBaseComponentTest : public testing::Test { 42 | public: 43 | KFDBaseComponentTest(void) { m_MemoryFlags.Value = 0; } 44 | ~KFDBaseComponentTest(void) {} 45 | 46 | HSAuint64 GetSysMemSize(); 47 | HSAuint64 GetVramSize(int defaultGPUNode); 48 | #define MAX_RENDER_NODES 64 49 | struct { 50 | int fd; 51 | uint32_t major_version; 52 | uint32_t minor_version; 53 | amdgpu_device_handle device_handle; 54 | uint32_t bdf; 55 | } m_RenderNodes[MAX_RENDER_NODES]; 56 | 57 | // @brief Finds DRM Render node corresponding to gpuNode 58 | // @return DRM Render Node if successful or -1 on failure 59 | int FindDRMRenderNode(int gpuNode); 60 | unsigned int GetFamilyIdFromNodeId(unsigned int nodeId); 61 | bool NeedCwsrWA(unsigned int nodeId); 62 | bool NeedNonPagedWptr(unsigned int nodeId); 63 | unsigned int GetFamilyIdFromDefaultNode(){ return m_FamilyId; } 64 | 65 | // @brief Executed before the first test that uses KFDBaseComponentTest. 66 | static void SetUpTestCase(); 67 | // @brief Executed after the last test from KFDBaseComponentTest. 68 | static void TearDownTestCase(); 69 | 70 | protected: 71 | HsaVersionInfo m_VersionInfo; 72 | HsaSystemProperties m_SystemProperties; 73 | unsigned int m_FamilyId; 74 | unsigned int m_numCpQueues; 75 | unsigned int m_numSdmaEngines; 76 | unsigned int m_numSdmaXgmiEngines; 77 | unsigned int m_numSdmaQueuesPerEngine; 78 | HsaMemFlags m_MemoryFlags; 79 | HsaNodeInfo m_NodeInfo; 80 | HSAint32 m_xnack; 81 | Assembler* m_pAsm; 82 | 83 | // @brief Executed before every test that uses KFDBaseComponentTest class and sets all common settings for the tests. 84 | virtual void SetUp(); 85 | // @brief Executed after every test that uses KFDBaseComponentTest class. 86 | virtual void TearDown(); 87 | 88 | bool SVMAPISupported() { 89 | bool supported = m_NodeInfo.HsaDefaultGPUNodeProperties() 90 | ->Capability.ui32.SVMAPISupported; 91 | if (!supported) 92 | LOG() << "SVM API not supported" << std::endl; 93 | return supported; 94 | } 95 | 96 | // Set xnack_override to -1 if parameter is not passed in, to avoid unnecessary code churn 97 | void SVMSetXNACKMode(int xnack_override = -1) { 98 | if (!SVMAPISupported()) 99 | return; 100 | 101 | m_xnack = -1; 102 | HSAKMT_STATUS ret = hsaKmtGetXNACKMode(&m_xnack); 103 | if (ret != HSAKMT_STATUS_SUCCESS) { 104 | LOG() << "Failed " << ret << " to get XNACK mode" << std::endl; 105 | return; 106 | } 107 | 108 | HSAint32 xnack_on = -1; 109 | char *hsa_xnack = getenv("HSA_XNACK"); 110 | 111 | // HSA_XNACK takes priority over kfdtest parameters 112 | if (hsa_xnack) 113 | xnack_on = strncmp(hsa_xnack, "0", 1); 114 | else if (xnack_override > -1) 115 | xnack_on = xnack_override; 116 | else 117 | return; 118 | 119 | // No need to set XNACK if it's already the current value 120 | if (xnack_on == m_xnack) 121 | return; 122 | 123 | ret = hsaKmtSetXNACKMode(xnack_on); 124 | if (ret != HSAKMT_STATUS_SUCCESS) 125 | LOG() << "Failed " << ret << " to set XNACK mode " << xnack_on << std::endl; 126 | else 127 | LOG() << "Setting XNACK mode to " << xnack_on << std::endl; 128 | } 129 | 130 | void SVMRestoreXNACKMode() { 131 | if (!SVMAPISupported()) 132 | return; 133 | 134 | if (m_xnack == -1) 135 | return; 136 | 137 | hsaKmtSetXNACKMode(m_xnack); 138 | } 139 | }; 140 | 141 | extern KFDBaseComponentTest* g_baseTest; 142 | #endif // __KFD_BASE_COMPONENT_TEST__H__ 143 | --------------------------------------------------------------------------------