Merge 'develop' into 'amd-staging'

Change-Id: Ic8ed238745f7565efabd4bb38d791de9bebabe71
Этот коммит содержится в:
Maneesh Gupta
2023-09-14 09:01:06 +00:00
родитель 0acd91db44 8a8b157ca7
Коммит b6b43db172
202 изменённых файлов: 19721 добавлений и 2633 удалений
+1 -1
Просмотреть файл
@@ -97,7 +97,7 @@ timestamps {
skipDefaultCheckout()
// labels belonging to each backend - AMD, NVIDIA
String[] labels = ['hip-amd-vg20-ubu1804', 'hip-nvidia-rtx5000-ubu1804']
String[] labels = ['hip-amd-mi100-ubu2004', 'hip-nvidia-rtx5000-ubu2004']
buildMap = [:]
labels.each { backendLabel ->
+88 -54
Просмотреть файл
@@ -9,52 +9,52 @@ project(hiptests)
# flag to generate standalone exe per src file.
message(STATUS "STANDALONE_TESTS : ${STANDALONE_TESTS}")
# Check if platform and compiler are set
if(HIP_PLATFORM STREQUAL "amd")
if(HIP_COMPILER STREQUAL "nvcc")
message(FATAL_ERROR "Unexpected HIP_COMPILER:${HIP_COMPILER} is set for HIP_PLATFOR:amd")
endif()
elseif(HIP_PLATFORM STREQUAL "nvidia")
if(DEFINED HIP_COMPILER AND NOT HIP_COMPILER STREQUAL "nvcc")
message(FATAL_ERROR "Unexpected HIP_COMPILER: ${HIP_COMPILER} is set for HIP_PLATFORM:nvidia")
endif()
else()
# Check if platform is set
if(NOT HIP_PLATFORM STREQUAL "amd" AND NOT HIP_PLATFORM STREQUAL "nvidia")
message(FATAL_ERROR "Unexpected HIP_PLATFORM: " ${HIP_PLATFORM})
endif()
if (WIN32)
if(WIN32)
set(EXT ".bat")
endif()
# Read -DROCM_Path and env{ROCM_PATH}
if(NOT DEFINED ROCM_PATH)
if(DEFINED ENV{ROCM_PATH})
set(ROCM_PATH $ENV{ROCM_PATH} CACHE STRING "ROCM Path")
if(HIP_PLATFORM STREQUAL "amd")
if(UNIX AND DEFINED ROCM_PATH)
# Read -DROCM_PATH and set CXX_FLAGS for amd platform only
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --rocm-path=${ROCM_PATH}")
endif()
if(DEFINED HIP_PATH)
# Read -DHIP_PATH and set CXX_FLAGS for amd platform only
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --hip-path=${HIP_PATH}")
endif()
endif()
# Read -DHIP_PATH
# If not set read env{HIP_PATH} only on Windows
if(WIN32)
if(NOT DEFINED HIP_PATH)
if(DEFINED ENV{HIP_PATH})
set(HIP_PATH $ENV{HIP_PATH} CACHE STRING "HIP Path")
endif()
endif()
endif()
# Read -DHIP_Path and env{HIP_PATH}
if(NOT DEFINED HIP_PATH)
if(DEFINED ENV{HIP_PATH})
set(HIP_PATH $ENV{HIP_PATH} CACHE STRING "HIP Path")
if(DEFINED ROCM_PATH)
set(HIP_PATH ${ROCM_PATH})
else()
set(HIP_PATH "/opt/rocm")
endif()
endif()
# both are not set
if(NOT DEFINED HIP_PATH AND NOT DEFINED ROCM_PATH)
set(HIP_PATH "/opt/rocm")
if(NOT DEFINED ROCM_PATH)
set(ROCM_PATH "/opt/rocm")
elseif(DEFINED HIP_PATH AND NOT DEFINED ROCM_PATH)
execute_process(COMMAND ${HIP_PATH}/bin/hipconfig${EXT} --rocmpath
OUTPUT_VARIABLE ROCM_PATH
OUTPUT_STRIP_TRAILING_WHITESPACE)
elseif(DEFINED ROCM_PATH AND NOT DEFINED HIP_PATH)
set(HIP_PATH ${ROCM_PATH})
endif()
message(STATUS "HIP_PATH: ${HIP_PATH}")
message(STATUS "ROCM_PATH: ${ROCM_PATH}")
set(CMAKE_CXX_COMPILER "${HIP_PATH}/bin/hipcc${EXT}")
set(CMAKE_C_COMPILER "${HIP_PATH}/bin/hipcc${EXT}")
set(HIPCONFIG_EXECUTABLE "${HIP_PATH}/bin/hipconfig${EXT}")
@@ -62,10 +62,6 @@ execute_process(COMMAND ${HIPCONFIG_EXECUTABLE} --version
OUTPUT_VARIABLE HIP_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE)
if(HIP_PLATFORM STREQUAL "amd")
# prioritize -DROCM_PATH over env{ROCM_PATH} for amd platform only
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --rocm-path=${ROCM_PATH}")
endif()
# enforce c++17
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --std=c++17")
@@ -75,6 +71,7 @@ list(GET VERSION_LIST 1 HIP_VERSION_MINOR)
list(GET VERSION_LIST 2 HIP_VERSION_PATCH_GITHASH)
string(REPLACE "-" ";" VERSION_LIST ${HIP_VERSION_PATCH_GITHASH})
list(GET VERSION_LIST 0 HIP_VERSION_PATCH)
list(GET VERSION_LIST 1 HIP_VERSION_GITHASH)
if(DEFINED ENV{ROCM_LIBPATCH_VERSION})
set(HIP_PACKAGING_VERSION_PATCH ${HIP_VERSION_PATCH}.$ENV{ROCM_LIBPATCH_VERSION})
@@ -128,7 +125,13 @@ endif()
add_definitions(-DKERNELS_PATH="${CMAKE_CURRENT_SOURCE_DIR}/kernels/")
set(CATCH_BUILD_DIR catch_tests)
file(COPY ./hipTestMain/config DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${CATCH_BUILD_DIR}/hipTestMain)
execute_process(COMMAND ${CMAKE_COMMAND} -E
make_directory ${CMAKE_CURRENT_BINARY_DIR}/${CATCH_BUILD_DIR}/hipTestMain/config)
file(GLOB JSON_FILES "./hipTestMain/config/*.json")
foreach(json IN LISTS JSON_FILES)
file(COPY ${json}
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${CATCH_BUILD_DIR}/hipTestMain/config/)
endforeach()
file(COPY ./external/Catch2/cmake/Catch2/CatchAddTests.cmake
DESTINATION ${CMAKE_CURRENT_BINARY_DIR}/${CATCH_BUILD_DIR}/script)
file(COPY ./external/Catch2/cmake/Catch2/catch_include.cmake
@@ -155,8 +158,8 @@ if (WIN32)
SET(CMAKE_CXX_RESPONSE_FILE_LINK_FLAG "")
endif()
if(HIP_PLATFORM MATCHES "amd" AND HIP_COMPILER MATCHES "clang")
add_compile_options(-Wall -Wextra -pedantic -Werror -Wno-deprecated)
if(HIP_PLATFORM STREQUAL "amd")
add_compile_options(-Wall -Wextra -Werror -Wno-deprecated)
endif()
cmake_policy(PUSH)
@@ -178,29 +181,26 @@ message(STATUS "CMAKE HIP ARCHITECTURES: ${CMAKE_HIP_ARCHITECTURES}")
# That results in hipcc building the test for gfx803 (the default target)
# preference to pass arch -
# OFFLOAD_ARCH_STR
# ENV{HCC_AMDGPU_TARGET}
# rocm_agent_enumerator
if(NOT DEFINED OFFLOAD_ARCH_STR
AND NOT DEFINED ENV{HCC_AMDGPU_TARGET}
AND EXISTS "${ROCM_PATH}/bin/rocm_agent_enumerator"
AND HIP_PLATFORM STREQUAL "amd" AND UNIX)
execute_process(COMMAND ${ROCM_PATH}/bin/rocm_agent_enumerator
execute_process(COMMAND "${ROCM_PATH}/bin/rocm_agent_enumerator"
OUTPUT_VARIABLE HIP_GPU_ARCH
RESULT_VARIABLE ROCM_AGENT_ENUM_RESULT)
RESULT_VARIABLE ROCM_AGENT_ENUM_RESULT
OUTPUT_STRIP_TRAILING_WHITESPACE)
# Trim out gfx000
string(REPLACE "gfx000\n" "" HIP_GPU_ARCH ${HIP_GPU_ARCH})
if (NOT HIP_GPU_ARCH STREQUAL "")
string(LENGTH ${HIP_GPU_ARCH} HIP_GPU_ARCH_LEN)
# If string has more gfx target except gfx000
if(${HIP_GPU_ARCH_LEN} GREATER_EQUAL 1)
string(REGEX REPLACE "\n" ";" HIP_GPU_ARCH_LIST "${HIP_GPU_ARCH}")
set(OFFLOAD_ARCH_STR "")
foreach(_hip_gpu_arch ${HIP_GPU_ARCH_LIST})
set(OFFLOAD_ARCH_STR "--offload-arch=${_hip_gpu_arch} ${OFFLOAD_ARCH_STR}")
endforeach()
endif()
string(REGEX REPLACE "\n" ";" HIP_GPU_ARCH_LIST "${HIP_GPU_ARCH}")
list(REMOVE_DUPLICATES HIP_GPU_ARCH_LIST)
list(LENGTH HIP_GPU_ARCH_LIST HIP_GPU_ARCH_LEN)
set(OFFLOAD_ARCH_STR "")
foreach(_hip_gpu_arch ${HIP_GPU_ARCH_LIST})
set(OFFLOAD_ARCH_STR "--offload-arch=${_hip_gpu_arch} ${OFFLOAD_ARCH_STR}")
endforeach()
else()
message(STATUS "ROCm Agent Enumurator found no valid architectures")
message(STATUS "ROCm Agent Enumerator found no valid architectures")
endif()
elseif(DEFINED OFFLOAD_ARCH_STR)
string(REPLACE "--offload-arch=" "" HIP_GPU_ARCH_LIST ${OFFLOAD_ARCH_STR})
@@ -208,10 +208,6 @@ endif()
if(DEFINED OFFLOAD_ARCH_STR)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} ${OFFLOAD_ARCH_STR} ")
elseif(DEFINED ENV{HCC_AMDGPU_TARGET})
# hipcc pl script appends it to the options
set(OFFLOAD_ARCH_STR "--offload-arch=$ENV{HCC_AMDGPU_TARGET}")
set(HIP_GPU_ARCH_LIST $ENV{HCC_AMDGPU_TARGET})
endif()
message(STATUS "Using offload arch string: ${OFFLOAD_ARCH_STR}")
@@ -226,7 +222,44 @@ if(git_result EQUAL 0)
set(HIP_TESTS_GITHASH ${git_output})
endif()
set(OFFLOAD_ARCH_LIST ${OFFLOAD_ARCH_STR})
separate_arguments(OFFLOAD_ARCH_LIST)
list(REMOVE_DUPLICATES OFFLOAD_ARCH_LIST)
set(hip_gpu_arch_list "")
foreach(__offload_arch ${OFFLOAD_ARCH_LIST})
string(REPLACE "--offload-arch=" "" targetid ${__offload_arch})
string(REPLACE ":" ";" target_id_list ${targetid})
list(GET target_id_list 0 arch)
string(APPEND hip_gpu_arch_list "${arch};")
list(REMOVE_DUPLICATES hip_gpu_arch_list)
endforeach()
file(MAKE_DIRECTORY ${CMAKE_CURRENT_BINARY_DIR}/${CATCH_BUILD_DIR}/hipTestMain/config)
set(config_gen_path ${CMAKE_CURRENT_BINARY_DIR}/${CATCH_BUILD_DIR}/hipTestMain/config)
if(WIN32)
set(configToUse "config_amd_windows")
set(config_file ${CMAKE_SOURCE_DIR}/hipTestMain/config/${configToUse})
set(json_file ${config_gen_path}/${configToUse}.json)
set(CLANG_CPP "${HIP_PATH}/../lc/bin/clang-cpp.exe")
set(cmd "${CLANG_CPP} -P -DGITHASH=\"${HIP_VERSION_GITHASH}\" ${config_file}>${json_file}")
message(${cmd})
execute_process(COMMAND cmd.exe /C ${cmd}
RESULT_VARIABLE json_result)
message(STATUS "${configToUse}.json file generation result: ${json_result}")
else()
set(configToUse "config_amd_linux")
foreach(arch ${hip_gpu_arch_list})
set(config_file ${CMAKE_SOURCE_DIR}/hipTestMain/config/${configToUse})
set(config_gen_path ${CMAKE_CURRENT_BINARY_DIR}/${CATCH_BUILD_DIR}/hipTestMain/config)
set(json_file ${config_gen_path}/${configToUse}_${arch}.json)
set(cmd "${ROCM_PATH}/llvm/bin/clang-cpp -P -D${arch} -DGITHASH=\\\"${HIP_VERSION_GITHASH}\\\" ${config_file}>${json_file}")
message(${cmd})
execute_process(COMMAND bash -c ${cmd}
RESULT_VARIABLE json_result)
message(STATUS "${configToUse}_${arch}.json file generation result: ${json_result}")
endforeach()
endif()
# prints the catch info to a file
string(TIMESTAMP _timestamp UTC)
set(_autogen "# Auto-generated by cmake on ${_timestamp} UTC\n")
@@ -240,7 +273,7 @@ set(_subdirs ${_autogen} "subdirs(..)\n")
file(WRITE ${CMAKE_CURRENT_BINARY_DIR}/${CATCH_BUILD_DIR}/CTestTestfile.cmake ${_subdirs})
# Enable device lambda on nvidia platforms
if(HIP_COMPILER MATCHES "nvcc")
if(HIP_PLATFORM STREQUAL "nvidia")
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} --extended-lambda")
endif()
@@ -257,6 +290,7 @@ add_subdirectory(kernels ${CATCH_BUILD_DIR}/kernels)
add_subdirectory(hipTestMain ${CATCH_BUILD_DIR}/hipTestMain)
add_subdirectory(stress ${CATCH_BUILD_DIR}/stress)
add_subdirectory(TypeQualifiers ${CATCH_BUILD_DIR}/TypeQualifiers)
add_subdirectory(perftests ${CATCH_BUILD_DIR}/perftests)
if(UNIX)
add_subdirectory(multiproc ${CATCH_BUILD_DIR}/multiproc)
endif()
+1 -1
Просмотреть файл
@@ -11,7 +11,7 @@ Tests in Catch2 are declared via ```TEST_CASE```.
[Catch2 Detailed Reference](https://github.com/catchorg/Catch2/blob/v2.13.6/docs/Readme.md#top)
## Taking care of existing features
- Dont build on platform: EXCLUDE_(HIP_PLATFORM/HIP_RUNTIME), can be done via CMAKE. Adding source in if(HIP_PLATFORM == amd/nvidia).
- Dont build on platform: EXCLUDE_HIP_PLATFORM, can be done via CMAKE. Adding source in if(HIP_PLATFORM == amd/nvidia).
- HIPCC_OPTIONS/CLANG Options: Can be done via: set_source_files_properties(src.cc PROPERTIES COMPILE_FLAGS “…”).
- Additional libraries: Can be done via target_link_libraries()
- Multiple runs with different args: This can be done by Catchs Feature: GENERATE(…)
+245
Просмотреть файл
@@ -0,0 +1,245 @@
#define COMMON
#if defined gfx906
#define VEGA20
#endif
#if defined gfx908
#define MI100
#endif
#if defined gfx90a || defined gfx940
#define MI2XX
#endif
#if defined gfx1100 || defined gfx1102
#define NAVI3X
#endif
{
"Info": [
"File generated for commit on below mentioned date and time",
__DATE__,
__TIME__,
GITHASH
],
"DisabledTests": [
#if defined COMMON
"Unit_hipStreamPerThread_DeviceReset_1",
"Unit_hipMallocManaged_OverSubscription",
"Unit_hipDeviceGetSharedMemConfig_Positive_Basic",
"Unit_hipDeviceGetSharedMemConfig_Positive_Threaded",
"Unit_hipDeviceGetCacheConfig_Positive_Basic",
"Unit_hipDeviceGetCacheConfig_Positive_Threaded",
"Unit_hipGetDeviceFlags_Positive_Context",
"Unit_hipIpcCloseMemHandle_Negative_Close_In_Originating_Process",
"Unit_hipIpcOpenMemHandle_Negative_Open_In_Creating_Process",
"Unit_hipInit_Negative",
"Unit_hipDeviceReset_Positive_Basic",
"Unit_hipDeviceReset_Positive_Threaded",
"Unit_hipFuncSetCacheConfig_Positive_Basic",
"Unit_hipFuncSetCacheConfig_Negative_Parameters",
"Unit_hipFuncSetSharedMemConfig_Positive_Basic",
"Unit_hipFuncSetSharedMemConfig_Negative_Parameters",
"Unit_hipFuncSetAttribute_Positive_MaxDynamicSharedMemorySize",
"Unit_hipFuncSetAttribute_Positive_PreferredSharedMemoryCarveout",
"Unit_hipFuncSetAttribute_Positive_Parameters",
"Unit_hipFuncSetAttribute_Negative_Parameters",
"NOTE: The following 4 tests are disabled due to defect - EXSWHTEC-240",
"Unit_hipFuncSetCacheConfig_Negative_Not_Supported",
"Unit_hipFuncSetSharedMemConfig_Negative_Not_Supported",
"Unit_hipFuncSetAttribute_Positive_MaxDynamicSharedMemorySize_Not_Supported",
"Unit_hipFuncSetAttribute_Positive_PreferredSharedMemoryCarveout_Not_Supported",
"Unit_hipOccupancyMaxActiveBlocksPerMultiprocessor_Negative_Parameters",
"Unit_hipGraphMemcpyNodeSetParamsToSymbol_Positive_Basic",
"Unit_hipGraphExecMemcpyNodeSetParamsToSymbol_Positive_Basic",
"Unit_hipGraphExecMemcpyNodeSetParamsFromSymbol_Positive_Basic",
"Unit_hipKernelNameRef_Negative_Parameters",
"Unit_hipMemAdvise_AccessedBy_All_Devices",
"Unit_hipMemAdvise_No_Flag_Interference",
"Unit_hipMemGetAddressRange_Negative",
"NOTE: The following 2 tests are disabled due to defect - EXSWHTEC-238",
"Unit_hipDrvMemcpy3D_Positive_Array",
"Unit_hipDrvMemcpy3DAsync_Positive_Array",
"Unit_hipMemRangeGetAttribute_Positive_AccessedBy_Basic",
"Unit_hipMemRangeGetAttribute_Positive_AccessedBy_Partial_Range",
"Unit_hipMemGetAddressRange_Positive",
"Unit_hipGraphAddMemcpyNode1D_Negative_Basic",
"intermittent issue: corrupted double-linked list",
"Unit_hipGraphRetainUserObject_Functional_2",
"Unit_ChannelDescriptor_Positive_16BitFloatingPoint",
"intermittent issue: failure expected but sucess returned",
"Unit_hipMemAdvise_NegtveTsts",
"Note: Following four tests disabled due to defect - EXSWHTEC-203",
"Unit_hipGraphAddMemsetNode_Positive_Basic - uint16_t",
"Unit_hipGraphAddMemsetNode_Positive_Basic - uint32_t",
"Unit_hipStreamSetCaptureDependencies_Positive_Functional",
"Note: Test disabled due to defect - EXSWHTEC-207",
"Unit_hipIpcGetMemHandle_Positive_Unique_Handles_Separate_Allocations",
"Unit_hipStreamCreateWithFlags_DefaultStreamInteraction",
"Unit_hipStreamWaitEvent_UninitializedStream_Negative",
"Unit_hipMemset3DSync",
"Unit_hipStreamAddCallback_StrmSyncTiming",
"Disabling test tracked SWDEV-394199",
"Unit_hipStreamCreateWithPriority_MulthreadNonblockingflag",
"Disabling test tracked SWDEV-395683",
"Unit_hipStreamPerThread_MultiThread",
"SWDEV-396963",
"Unit_hipMemcpy2DFromArrayAsync_Positive_Synchronization_Behavior",
"Disabling tests tracked with SWDEV-389647..",
"Unit_hipMemcpy2DToArrayAsync_Positive_Synchronization_Behavior",
"Disabling test tracked SWDEV-391555",
"Unit_hipMemcpyPeer_Positive_ZeroSize",
"Unit_hipMemcpyPeerAsync_Positive_ZeroSize",
"Disabling test tracked SWDEV-391718",
"Unit_hipMemRangeGetAttribute_TstCountParam",
"Fails in Stress test SWDEV-398971",
"SWDEV-398975 Seg faults in stress test",
"Unit_hipMemcpyWithStream_MultiThread",
"SWDEV-398977 fails in stress tests",
"Unit_hipMemset2DSync",
"SWDEV-398981 fails in stress test",
"Unit_hipStreamCreateWithPriority_MulthreadDefaultflag",
"SWDEV-402054 fails in external github build",
"Unit_hipEventDestroy_WithWaitingStream",
"=== Below tests fail in stress test on 23/06/23 ===",
"Unit_hipIpcMemAccess_ParameterValidation",
"Unit_hipMemcpy2DFromArrayAsync_Positive_Synchronization_Behavior",
"Unit_hipGraphClone_Test_hipGraphExecMemcpyNodeSetParams",
"Unit_hipGraphClone_Test_hipGraphMemcpyNodeSetParams1D_and_exec",
"Unit_hipStreamValue_Wait64_Blocking_NoMask_And",
"Unit_hipStreamValue_Wait64_Blocking_NoMask_Nor",
"=== Below tests fail in stress test on 30/06/23 ===",
"Unit_hipStreamValue_Wait32_Blocking_NoMask_Nor",
"Unit_hipStreamValue_Write - TestParams<uint32_t, PtrType::HostPtr>",
"Unit_hipMemcpyParam2DAsync_multiDevice-StreamOnDiffDevice",
"=== Below tests fail in external CI for PR https://github.com/ROCm-Developer-Tools/hip-tests/pull/96 ===",
"Unit_hipHostGetDevicePointer_Negative",
"=== Below tests fail in external CI for PR https://github.com/ROCm-Developer-Tools/hip-tests/pull/215 ===",
"Unit_ChannelDescriptor_Positive_Basic_1D - long",
"Unit_ChannelDescriptor_Positive_Basic_1D - unsigned long",
"Unit_ChannelDescriptor_Positive_Basic_1D - ulong1",
"Unit_ChannelDescriptor_Positive_Basic_1D - signed long",
"Unit_ChannelDescriptor_Positive_Basic_1D - long1",
"Unit_ChannelDescriptor_Positive_Basic_2D - ulong2",
"Unit_ChannelDescriptor_Positive_Basic_2D - long2",
"Unit_ChannelDescriptor_Positive_Basic_4D - ulong4",
"Unit_ChannelDescriptor_Positive_Basic_4D - long4",
"Unit_hipExtModuleLaunchKernel_NonUniformWorkGroup",
"=== Below tests fail in external CI for PR https://github.com/ROCm-Developer-Tools/hip-tests/pull/18 ===",
"Unit_hipMemcpyAsync_Negative_Parameters",
"Unit_hipMemcpyDtoHAsync_Negative_Parameters",
"Unit_hipMemcpyHtoDAsync_Negative_Parameters",
"Unit_hipMemcpyDtoDAsync_Negative_Parameters",
"Unit_hipStreamValue_Wait32_Blocking_Mask_Eq_1",
"=== Below tests fail in external CI for PR https://github.com/ROCm-Developer-Tools/hip-tests/pull/327 ===",
"Unit_hiprtcGpuRdcComplrOptnTst",
"Unit_hiprtcDisabledSlpVectorizeComplrOptnTst",
"Unit_hiprtcRpassInlineComplrOptnTst",
"Unit_hiprtcCombiComplrOptnTst",
"=== Below tests fail in external CI for PR https://github.com/ROCm-Developer-Tools/hip-tests/pull/92 ===",
"Unit_hipGetChannelDesc_Negative_Parameters",
"Unit_hipGraphAddChildGraphNode_CmplxNstGrph_UpdKerFun_Clone",
"=== Below tests fail in stress test on 24/07/23 ===",
"Unit_hipStreamCreateWithPriority_ValidateWithEvents",
"Unit_hipEventIpc",
"=== Below hiprtc tests are disabled temporarily, will be renabled once patches for SWDEV-395996 are merged ===",
"Unit_hiprtc_saxpy",
"Unit_hiprtc_warpsize",
"Unit_hiprtc_functional",
"Unit_hipStreamCaptureRtc",
"Unit_hiprtc_cpp17",
"Unit_hiprtc_namehandling",
"Unit_hiprtc_getloweredname",
"Unit_hiprtc_test_hip_bfloat16",
"Unit_RTC_LinkerAPI",
"Unit_hiprtc_half_shuffle",
"Unit_hiprtc_includepath",
#endif
#if defined VEGA20
"=== SWDEV-419112 Below tests fail in stress test on 29/08/23 ===",
"Unit_deviceAllocation_Malloc_ComplexDataType",
"Unit_hipStreamCreate_WithPriorityPerformance_Default_low",
"=== Below tests tests fail in stress test on 13/09/23 ===",
"Unit_hipStreamCreate_Performance",
"Unit_hipStreamCreate_WithPriorityPerformance_Default_high",
#endif
#if defined MI100
"=== Below test soft hang in stress test on 29/08/23 ===",
"Unit_hipMultiThreadStreams2",
#endif
#if defined MI2XX
"Unit_hipStreamPerThread_DeviceReset_1",
"Unit_hipMallocManaged_OverSubscription",
"Unit_hipDeviceGetPCIBusId_Negative_PartialFill",
"Unit_hipInit_Negative",
"Unit_hipMemGetAddressRange_Negative",
"Unit_hipExternalMemoryGetMappedBuffer_Vulkan_Positive_Read_Write",
"Unit_hipExternalMemoryGetMappedBuffer_Vulkan_Negative_Parameters",
"Unit_hipImportExternalMemory_Vulkan_Negative_Parameters",
"Unit_hipWaitExternalSemaphoresAsync_Vulkan_Positive_Binary_Semaphore",
"Unit_hipWaitExternalSemaphoresAsync_Vulkan_Positive_Multiple_Semaphores",
"Unit_hipWaitExternalSemaphoresAsync_Vulkan_Negative_Parameters",
"Unit_hipSignalExternalSemaphoresAsync_Vulkan_Positive_Binary_Semaphore",
"Unit_hipSignalExternalSemaphoresAsync_Vulkan_Positive_Multiple_Semaphores",
"Unit_hipSignalExternalSemaphoresAsync_Vulkan_Negative_Parameters",
"Unit_hipImportExternalSemaphore_Vulkan_Negative_Parameters",
"Unit_hipDestroyExternalSemaphore_Vulkan_Negative_Parameters",
"SWDEV-415692 Soft hang in stress test on 29/08/23",
"Unit_Grid_Group_Sync_Positive_Basic",
"=== Below hiprtc tests are disabled temporarily, will be renabled once patches for SWDEV-395996 are merged ===",
"Unit_hiprtc_saxpy",
"Unit_hiprtc_warpsize",
"Unit_hiprtc_functional",
"Unit_hipStreamCaptureRtc",
"Unit_hiprtc_cpp17",
"Unit_hiprtc_namehandling",
"Unit_hiprtc_getloweredname",
"Unit_hiprtc_test_hip_bfloat16",
"Unit_RTC_LinkerAPI",
"Unit_hiprtc_half_shuffle",
"Unit_hiprtc_includepath",
"=== Below tests fail in stress test on 29/08/23 ===",
"Unit_hipMemcpy2DToArray_multiDevicePinnedMemPeerGpu",
"Unit_hipMemcpy2DToArray_multiDeviceDeviceContextChange",
"Unit_hipMemcpy2DToArrayAsync_multiDeviceDeviceContextChange",
"Unit_hipMemcpy3D_multiDevice-OnPeerDevice",
"Unit_hipMemcpy3DAsync_multiDevice-D2D",
"Unit_hipMemcpy3DAsync_multiDevice-DiffStream",
"Unit_hipMemcpy2DFromArray_multiDevicePinnedMemPeerGpu",
"Unit_hipMemcpy2DFromArray_multiDeviceContextChange",
"Unit_hipMemcpy2DFromArrayAsync_multiDeviceContextChange",
"Unit_hipMemcpyAtoH_multiDevice-PeerDeviceContext - char",
"Unit_hipMemcpyAtoH_multiDevice-PeerDeviceContext - int",
"Unit_hipMemcpyAtoH_multiDevice-PeerDeviceContext - float",
"Unit_hipMemcpyHtoA_multiDevice-PeerDeviceContext - char",
"Unit_hipMemcpyHtoA_multiDevice-PeerDeviceContext - int",
"Unit_hipMemcpyHtoA_multiDevice-PeerDeviceContext - float",
"Unit_hipDrvMemcpy3D_Host2ArrayDeviceContextChange",
"=== Below tests tests fail in stress test on 13/09/23 ===",
"Unit_hipGraphInstantiateWithFlags_DependencyGraphDeviceCtxtChg",
"Unit_hipGraphUpload_Functional_multidevice_test",
"Unit_hipMemcpyParam2D_multiDevice-D2D - char",
"Unit_hipMemcpyParam2D_multiDevice-D2D - float",
"Unit_hipMemcpyParam2D_multiDevice-D2D - int",
"Unit_hipMemcpyParam2D_multiDevice-D2D - double",
"Unit_hipMemcpyParam2D_multiDevice-D2D - long double",
"Unit_hipMemcpyParam2DAsync_multiDevice-StreamOnDiffDevice - char",
#endif
#if defined NAVI3X
"=== Below tests soft hang in stress test on 13/09/23 ===",
"Unit_hipMemsetFunctional_ZeroValue_hipMemsetD16",
"Unit_hipIpcMemAccess_Semaphores",
"Unit_hipStreamCreate_WithFlagsPerformance_Nonblocking",
"Unit_hipStreamCreate_WithFlagsPerformance_Default",
"Unit_hipStreamAttachMemAsync_Negative_Parameters",
"hipStreamPerThread_CoopLaunch",
"hipCGMultiGridGroupType",
"Grid_Group_Getters_Positive_Basic",
"Grid_Group_Getters_Via_Non_Member_Functions_Positive_Basic",
"Grid_Group_Sync_Positive_Basic",
"dynamic_loading_device_kernels_from_library",
#endif
"End of json"
]
}
-23
Просмотреть файл
@@ -1,23 +0,0 @@
{
"DisabledTests":
[
"Unit_hipStreamPerThread_DeviceReset_1",
"Unit_hipMallocManaged_OverSubscription",
"Unit_hipDeviceGetPCIBusId_Negative_PartialFill",
"Unit_hipInit_Negative",
"Unit_hipMemGetAddressRange_Negative",
"Unit_hipExternalMemoryGetMappedBuffer_Vulkan_Positive_Read_Write",
"Unit_hipExternalMemoryGetMappedBuffer_Vulkan_Negative_Parameters",
"Unit_hipImportExternalMemory_Vulkan_Negative_Parameters",
"Unit_hipWaitExternalSemaphoresAsync_Vulkan_Positive_Binary_Semaphore",
"Unit_hipWaitExternalSemaphoresAsync_Vulkan_Positive_Multiple_Semaphores",
"Unit_hipWaitExternalSemaphoresAsync_Vulkan_Negative_Parameters",
"Unit_hipSignalExternalSemaphoresAsync_Vulkan_Positive_Binary_Semaphore",
"Unit_hipSignalExternalSemaphoresAsync_Vulkan_Positive_Multiple_Semaphores",
"Unit_hipSignalExternalSemaphoresAsync_Vulkan_Negative_Parameters",
"Unit_hipImportExternalSemaphore_Vulkan_Negative_Parameters",
"Unit_hipDestroyExternalSemaphore_Vulkan_Negative_Parameters",
"Unit_Grid_Group_Sync_Positive_Basic"
]
}
-118
Просмотреть файл
@@ -1,118 +0,0 @@
{
"DisabledTests":
[
"Unit_hipStreamPerThread_DeviceReset_1",
"Unit_hipMallocManaged_OverSubscription",
"Unit_hipDeviceGetSharedMemConfig_Positive_Basic",
"Unit_hipDeviceGetSharedMemConfig_Positive_Threaded",
"Unit_hipDeviceGetCacheConfig_Positive_Basic",
"Unit_hipDeviceGetCacheConfig_Positive_Threaded",
"Unit_hipGetDeviceFlags_Positive_Context",
"Unit_hipIpcCloseMemHandle_Negative_Close_In_Originating_Process",
"Unit_hipIpcOpenMemHandle_Negative_Open_In_Creating_Process",
"Unit_hipInit_Negative",
"Unit_hipDeviceReset_Positive_Basic",
"Unit_hipDeviceReset_Positive_Threaded",
"Unit_hipFuncSetCacheConfig_Positive_Basic",
"Unit_hipFuncSetCacheConfig_Negative_Parameters",
"Unit_hipFuncSetSharedMemConfig_Positive_Basic",
"Unit_hipFuncSetSharedMemConfig_Negative_Parameters",
"Unit_hipFuncSetAttribute_Positive_MaxDynamicSharedMemorySize",
"Unit_hipFuncSetAttribute_Positive_PreferredSharedMemoryCarveout",
"Unit_hipFuncSetAttribute_Positive_Parameters",
"Unit_hipFuncSetAttribute_Negative_Parameters",
"NOTE: The following 4 tests are disabled due to defect - EXSWHTEC-240",
"Unit_hipFuncSetCacheConfig_Negative_Not_Supported",
"Unit_hipFuncSetSharedMemConfig_Negative_Not_Supported",
"Unit_hipFuncSetAttribute_Positive_MaxDynamicSharedMemorySize_Not_Supported",
"Unit_hipFuncSetAttribute_Positive_PreferredSharedMemoryCarveout_Not_Supported",
"Unit_hipOccupancyMaxActiveBlocksPerMultiprocessor_Negative_Parameters",
"Unit_hipGraphMemcpyNodeSetParamsToSymbol_Positive_Basic",
"Unit_hipGraphExecMemcpyNodeSetParamsToSymbol_Positive_Basic",
"Unit_hipGraphExecMemcpyNodeSetParamsFromSymbol_Positive_Basic",
"Unit_hipKernelNameRef_Negative_Parameters",
"Unit_hipMemAdvise_AccessedBy_All_Devices",
"Unit_hipMemAdvise_No_Flag_Interference",
"Unit_hipMemGetAddressRange_Negative",
"NOTE: The following 2 tests are disabled due to defect - EXSWHTEC-238",
"Unit_hipDrvMemcpy3D_Positive_Array",
"Unit_hipDrvMemcpy3DAsync_Positive_Array",
"Unit_hipMemRangeGetAttribute_Positive_AccessedBy_Basic",
"Unit_hipMemRangeGetAttribute_Positive_AccessedBy_Partial_Range",
"Unit_hipMemGetAddressRange_Positive",
"Unit_hipGraphAddMemcpyNode1D_Negative_Basic",
"intermittent issue: corrupted double-linked list",
"Unit_hipGraphRetainUserObject_Functional_2",
"Unit_ChannelDescriptor_Positive_16BitFloatingPoint",
"intermittent issue: failure expected but sucess returned",
"Unit_hipMemAdvise_NegtveTsts",
"Note: Following four tests disabled due to defect - EXSWHTEC-203",
"Unit_hipGraphAddMemsetNode_Positive_Basic - uint16_t",
"Unit_hipGraphAddMemsetNode_Positive_Basic - uint32_t",
"Unit_hipStreamSetCaptureDependencies_Positive_Functional",
"Note: Test disabled due to defect - EXSWHTEC-207",
"Unit_hipIpcGetMemHandle_Positive_Unique_Handles_Separate_Allocations",
"Unit_hipStreamCreateWithFlags_DefaultStreamInteraction",
"Unit_hipStreamWaitEvent_UninitializedStream_Negative",
"Unit_hipMemset3DSync",
"Unit_hipStreamAddCallback_StrmSyncTiming",
"Disabling test tracked SWDEV-394199",
"Unit_hipStreamCreateWithPriority_MulthreadNonblockingflag",
"Disabling test tracked SWDEV-395683",
"Unit_hipStreamPerThread_MultiThread",
"SWDEV-396963",
"Unit_hipMemcpy2DFromArrayAsync_Positive_Synchronization_Behavior",
"Disabling tests tracked with SWDEV-389647..",
"Unit_hipMemcpy2DToArrayAsync_Positive_Synchronization_Behavior",
"Disabling test tracked SWDEV-391555",
"Unit_hipMemcpyPeer_Positive_ZeroSize",
"Unit_hipMemcpyPeerAsync_Positive_ZeroSize",
"Disabling test tracked SWDEV-391718",
"Unit_hipMemRangeGetAttribute_TstCountParam",
"Fails in Stress test SWDEV-398971",
"SWDEV-398975 Seg faults in stress test",
"Unit_hipMemcpyWithStream_MultiThread",
"SWDEV-398977 fails in stress tests",
"Unit_hipMemset2DSync",
"SWDEV-398981 fails in stress test",
"Unit_hipStreamCreateWithPriority_MulthreadDefaultflag",
"SWDEV-402054 fails in external github build",
"Unit_hipEventDestroy_WithWaitingStream",
"=== Below tests fail in stress test on 23/06/23 ===",
"Unit_hipIpcMemAccess_ParameterValidation",
"Unit_hipMemcpy2DFromArrayAsync_Positive_Synchronization_Behavior",
"Unit_hipGraphClone_Test_hipGraphExecMemcpyNodeSetParams",
"Unit_hipGraphClone_Test_hipGraphMemcpyNodeSetParams1D_and_exec",
"Unit_hipStreamValue_Wait64_Blocking_NoMask_And",
"Unit_hipStreamValue_Wait64_Blocking_NoMask_Nor",
"=== Below tests fail in stress test on 30/06/23 ===",
"Unit_hipStreamValue_Wait32_Blocking_NoMask_Nor",
"Unit_hipStreamValue_Write - TestParams<uint32_t, PtrType::HostPtr>",
"Unit_hipMemcpyParam2DAsync_multiDevice-StreamOnDiffDevice",
"=== Below tests fail in external CI for PR https://github.com/ROCm-Developer-Tools/hip-tests/pull/96 ===",
"Unit_hipHostGetDevicePointer_Negative",
"=== Below tests fail in external CI for PR https://github.com/ROCm-Developer-Tools/hip-tests/pull/215 ===",
"Unit_ChannelDescriptor_Positive_Basic_1D - long",
"Unit_ChannelDescriptor_Positive_Basic_1D - unsigned long",
"Unit_ChannelDescriptor_Positive_Basic_1D - ulong1",
"Unit_ChannelDescriptor_Positive_Basic_1D - signed long",
"Unit_ChannelDescriptor_Positive_Basic_1D - long1",
"Unit_ChannelDescriptor_Positive_Basic_2D - ulong2",
"Unit_ChannelDescriptor_Positive_Basic_2D - long2",
"Unit_ChannelDescriptor_Positive_Basic_4D - ulong4",
"Unit_ChannelDescriptor_Positive_Basic_4D - long4",
"Unit_hipExtModuleLaunchKernel_NonUniformWorkGroup",
"=== Below tests fail in external CI for PR https://github.com/ROCm-Developer-Tools/hip-tests/pull/18 ===",
"Unit_hipMemcpyAsync_Negative_Parameters",
"Unit_hipMemcpyDtoHAsync_Negative_Parameters",
"Unit_hipMemcpyHtoDAsync_Negative_Parameters",
"Unit_hipMemcpyDtoDAsync_Negative_Parameters",
"=== Below tests fail in stress test on 13/07/23 ===",
"Unit_deviceAllocation_Malloc_ComplexDataType",
"Unit_deviceAllocation_New_ComplexDataType",
"Unit_hipStreamValue_Wait32_Blocking_Mask_Eq_1",
"=== Below tests fail in stress test on 24/07/23 ===",
"Unit_hipStreamCreateWithPriority_ValidateWithEvents",
"Unit_hipEventIpc"
]
}
+255
Просмотреть файл
@@ -0,0 +1,255 @@
#define COMMON
{
"Info": [
"File generated for commit on below mentioned date and time",
__DATE__,
__TIME__,
GITHASH
],
"DisabledTests": [
#if defined COMMON
"Unit_hipMalloc_CoherentTst",
"Unit_hipTextureMipmapObj2D_Check",
"Unit_hipGraphAddHostNode_ClonedGraphwithHostNode",
"Unit_hipEventIpc",
"Unit_hipMalloc3D_Negative",
"Unit_hipMemPoolApi_BasicAlloc",
"Unit_hipMemPoolApi_BasicTrim",
"Unit_hipMemPoolApi_BasicReuse",
"Unit_hipMemPoolApi_Opportunistic",
"Unit_hipMalloc3D_ValidatePitch",
"Unit_hipMemAllocPitch_ValidatePitch",
"Unit_hipGraphExecMemcpyNodeSetParamsToSymbol_Functional",
"Unit_hipMallocManaged_OverSubscription",
"Unit_hipMallocManaged_CoherentTstWthAdvise",
"Unit_hipMallocManaged_Advanced",
"Unit_hipMemRangeGetAttribute_TstCountParam",
"Unit_hipMemRangeGetAttribute_NegativeTests",
"Unit_hipMemRangeGetAttribute_AccessedBy1",
"Unit_hipMemRangeGetAttribte_3",
"Unit_hipMemRangeGetAttribute_4",
"Unit_hipMemRangeGetAttribute_PrefetchAndGtAttr",
"Unit_hipMemAdvise_TstFlags",
"Unit_hipMemAdvise_PrefrdLoc",
"Unit_hipMemAdvise_ReadMostly",
"Unit_hipMemAdvise_TstFlgOverrideEffect",
"Unit_hipMemAdvise_TstAccessedByFlg",
"Unit_hipMemAdvise_TstAccessedByFlg4",
"Unit_hipMemAdvise_TstMemAdvisePrefrdLoc",
"Unit_hipMemAdvise_TstMemAdviseMultiFlag",
"Unit_hipMemAdvise_ReadMosltyMgpuTst",
"Unit_hipMemAdvise_TstSetUnsetPrfrdLoc",
"Unit_hipMallocManaged_DeviceContextChange - unsigned char",
"Unit_hipMallocManaged_DeviceContextChange - int",
"Unit_hipMallocManaged_DeviceContextChange - float",
"Unit_hipMallocManaged_DeviceContextChange - double",
"Unit_hipStreamCreateWithPriority_ValidateWithEvents",
"Unit_hipStreamPerThread_StrmWaitEvt",
"Unit_hipMemGetInfo_DifferentMallocSmall",
"Unit_hipMemGetInfo_MallocArray - int",
"Unit_hipMemGetInfo_MallocArray - int4",
"Unit_hipMemGetInfo_MallocArray - char",
"Unit_hipMemGetInfo_Malloc3D",
"Unit_hipMemGetInfo_Malloc3DArray - char",
"Unit_hipMemGetInfo_Malloc3DArray - int",
"Unit_hipMemGetInfo_Malloc3DArray - int4",
"Unit_hipMemGetInfo_ParaSmall",
"Unit_hipMemGetInfo_ParaMultiSmall",
"Unit_hipMultiThreadDevice_NearZero",
"Unit_hipStreamPerThread_DeviceReset_1",
"Unit_hipStreamCreateWithPriority_ValidateWithEvents",
"Unit_hipStreamPerThread_StrmWaitEvt",
"Unit_hipGraphMemcpyNodeSetParamsToSymbol_Functional",
"Unit_hipStreamWaitEvent_DifferentStreams",
"Unit_hipStreamQuery_WithFinishedWork",
"Unit_hipDeviceGetCacheConfig_Positive_Basic",
"Unit_hipDeviceGetCacheConfig_Positive_Basic",
"Unit_hipDeviceGetCacheConfig_Positive_Threaded",
"Unit_hipStreamValue_Wait32_Blocking_Mask_Gte",
"Unit_hipStreamValue_Wait32_Blocking_Mask_Eq_1",
"Unit_hipStreamValue_Wait32_Blocking_Mask_Eq_2",
"Unit_hipStreamValue_Wait32_Blocking_Mask_And",
"Unit_hipStreamValue_Wait32_Blocking_NoMask_Eq",
"Unit_hipStreamValue_Wait32_Blocking_NoMask_Gte",
"Unit_hipStreamValue_Wait32_Blocking_NoMask_And",
"Unit_hipStreamValue_Wait32_Blocking_NoMask_Nor",
"Unit_hipStreamValue_Wait64_Blocking_Mask_Gte_1",
"Unit_hipStreamValue_Wait64_Blocking_Mask_Gte_2",
"Unit_hipStreamValue_Wait64_Blocking_Mask_Eq_1",
"Unit_hipStreamValue_Wait64_Blocking_Mask_Eq_2",
"Unit_hipStreamValue_Wait64_Blocking_Mask_And",
"Unit_hipStreamValue_Wait64_Blocking_NoMask_Gte",
"Unit_hipStreamValue_Wait64_Blocking_NoMask_Eq",
"Unit_hipStreamValue_Wait64_Blocking_NoMask_And",
"Unit_hipStreamValue_Wait64_Blocking_NoMask_Nor",
"Unit_hipGetDeviceFlags_Positive_Context",
"Unit_hipIpcCloseMemHandle_Negative_Close_In_Originating_Process",
"Unit_hipIpcOpenMemHandle_Negative_Open_In_Creating_Process",
"Unit_hipDeviceGetPCIBusId_Negative_PartialFill",
"Unit_hipDeviceGetSharedMemConfig_Positive_Basic",
"Unit_hipDeviceGetSharedMemConfig_Positive_Threaded",
"Unit_hipDeviceReset_Positive_Basic",
"Unit_hipDeviceReset_Positive_Threaded",
"Unit_hipInit_Negative",
"Unit_hipGraphMemcpyNodeSetParams_Functional",
"Unit_hipGraphNodeGetDependentNodes_Functional",
"Unit_hipGraphNodeGetDependencies_Functional",
"Unit_hipGraphExecChildGraphNodeSetParams_ChildTopology",
"Unit_hipGraphAddEventRecordNode_MultipleRun",
"Unit_hipGraphAddEventRecordNode_Functional_ElapsedTime",
"Unit_hipStreamBeginCapture_captureComplexGraph",
"Note: needs to be enabled when streamPerThread issues are fixed",
"Unit_hipStreamSynchronize_NullStreamAndStreamPerThread",
"Note: intermittent Seg fault failure ",
"Unit_hipGraphAddEventRecordNode_Functional_WithoutFlags",
"Unit_hipGraphAddChildGraphNode_MultGraphsAsSingleGraph",
"Unit_hipFuncSetCacheConfig_Positive_Basic",
"Unit_hipFuncSetCacheConfig_Negative_Parameters",
"Unit_hipFuncSetSharedMemConfig_Positive_Basic",
"Unit_hipFuncSetSharedMemConfig_Negative_Parameters",
"Unit_hipFuncSetAttribute_Positive_MaxDynamicSharedMemorySize",
"Unit_hipFuncSetAttribute_Positive_PreferredSharedMemoryCarveout",
"Unit_hipFuncSetAttribute_Positive_Parameters",
"Unit_hipFuncSetAttribute_Negative_Parameters",
"Unit_hipEventCreateWithFlags_DisableSystemFence_HstVisMem",
"Unit_hipEventCreateWithFlags_DefaultFlg_HstVisMem",
"Unit_hipEventCreateWithFlags_DisableSystemFence_NonCohHstMem",
"Unit_hipEventCreateWithFlags_DefaultFlg_NonCohHstMem",
"Unit_hipEventCreateWithFlags_DisableSystemFence_CohHstMem",
"Unit_hipEventCreateWithFlags_DefaultFlg_CohHstMem",
"NOTE: The following 4 tests are disabled due to defect - EXSWHTEC-240",
"Unit_hipFuncSetCacheConfig_Negative_Not_Supported",
"Unit_hipFuncSetSharedMemConfig_Negative_Not_Supported",
"Unit_hipFuncSetAttribute_Positive_MaxDynamicSharedMemorySize_Not_Supported",
"Unit_hipFuncSetAttribute_Positive_PreferredSharedMemoryCarveout_Not_Supported",
"Unit_hipOccupancyMaxActiveBlocksPerMultiprocessor_Negative_Parameters",
"Unit_hipGraphMemcpyNodeSetParamsToSymbol_Positive_Basic",
"Unit_hipGraphExecMemcpyNodeSetParamsToSymbol_Positive_Basic",
"Unit_hipGraphMemcpyNodeSetParamsFromSymbol_Positive_Basic",
"Unit_hipGraphExecMemcpyNodeSetParamsFromSymbol_Positive_Basic",
"Unit_hipKernelNameRef_Negative_Parameters",
"Unit_hipKernelNameRef_Positive_Basic",
"Unit_hipMemAdvise_AccessedBy_All_Devices",
"Unit_hipMemAdvise_No_Flag_Interference",
"Unit_hipGraphAddEventRecordNode_Functional_WithoutFlags",
"Unit_hipGraphDestroyNode_Complx_ChkNumOfNodesNDep",
"Unit_hipGraphDestroyNode_Complx_ChkNumOfNodesNDep_ClonedGrph",
"Unit_hipGraphDestroyNode_Complx_ChkNumOfNodesNDep_ChldNode",
"Unit_hipMemGetAddressRange_Negative",
"NOTE: The following 2 tests are disabled due to defect - EXSWHTEC-238",
"Unit_hipDrvMemcpy3D_Positive_Array",
"Unit_hipDrvMemcpy3DAsync_Positive_Array",
"Unit_hipMemGetAddressRange_Positive",
"Note: devicelib hangs and failures",
"Unit_deviceAllocation_Malloc_PerThread_PrimitiveDataType",
"Unit_deviceAllocation_New_PerThread_PrimitiveDataType",
"Unit_deviceAllocation_Malloc_PerThread_StructDataType",
"Unit_deviceAllocation_New_PerThread_StructDataType",
"Unit_deviceAllocation_Malloc_AcrossKernels",
"Unit_deviceAllocation_New_AcrossKernels",
"Unit_deviceAllocation_Malloc_SingleCodeObj",
"Unit_deviceAllocation_New_SingleCodeObj",
"Unit_deviceAllocation_Malloc_PerThread_Graph",
"Unit_deviceAllocation_New_PerThread_Graph",
"Unit_deviceAllocation_Malloc_DeviceFunc",
"Unit_deviceAllocation_VirtualFunction",
"Unit_deviceAllocation_Malloc_MulKernels_MulThreads",
"Unit_deviceAllocation_New_MulKernels_MulThreads",
"Unit_deviceAllocation_Malloc_MulCodeObj",
"Unit_deviceAllocation_New_MulCodeObj",
"Unit_deviceAllocation_New_DeviceFunc",
"Unit_hipGraphAddEventRecordNode_MultipleRun",
"Unit_hipDeviceGetPCIBusId_Negative_PartialFill",
"Unit_hipStreamValue_Wait64_Blocking_NoMask_Nor",
"Unit_hipStreamQuery_WithFinishedWork",
"Unit_hipLaunchHostFunc_Graph",
"Unit_hipLaunchHostFunc_KernelHost",
"Unit_ChannelDescriptor_Positive_16BitFloatingPoint",
"Unit_hipStreamSetCaptureDependencies_Positive_Functional",
"Note: Following four tests disabled due to defect - EXSWHTEC-203",
"Unit_hipGraphAddMemsetNode_Positive_Basic - uint16_t",
"Unit_hipGraphAddMemsetNode_Positive_Basic - uint32_t",
"Unit_hipGraphMemsetNodeSetParams_Positive_Basic - uint16_t",
"Unit_hipGraphMemsetNodeSetParams_Positive_Basic - uint32_t",
"Note: Test disabled due to defect - EXSWHTEC-207",
"Unit_hipGraphExecMemsetNodeSetParams_Negative_Updating_Non1D_Node",
"Unit_hipGraphExecMemsetNodeSetParams_Positive_Basic - uint8_t",
"Unit_hipGraphExecMemsetNodeSetParams_Positive_Basic - uint16_t",
"Unit_hipGraphExecMemsetNodeSetParams_Positive_Basic - uint32_t",
"Unit_hipGraphMemsetNodeSetParams_Positive_Basic - uint8_t",
"Unit_hipStreamWaitEvent_UninitializedStream_Negative",
"Unit_hipDeviceGetUuid_Positive",
"Disabling test tracked SWDEV-394199",
"Unit_hipStreamCreateWithPriority_MulthreadNonblockingflag",
"SWDEV-396618 hipEventElapsedTime returns sucess",
"Unit_hipEventElapsedTime_NotReady_Negative",
"SWDEV-396617 ExecMemcpyNodeSetParamsFromSymbol fails in direction",
"Unit_hipGraphExecMemcpyNodeSetParamsFromSymbol_Negative_Parameters",
"SWDEV-396616 hipMemMap returns invalid error",
"Unit_hipMemVmm_Basic",
"SWDEV-396615 mGPUs not considered correctly",
"Unit_hipManagedKeyword_MultiGpu",
"Disabling test tracked SWDEV-391555",
"Unit_hipMemcpyPeer_Positive_ZeroSize",
"Unit_hipMemcpyPeerAsync_Positive_ZeroSize",
"Disabling test tracked SWDEV-391718",
"Unit_hipMemRangeGetAttribute_TstCountParam",
"SWDEV-400049 tdr intermittently",
"Unit_hipMemsetDSync – init16_t",
"Unit_hipStreamAddCallback_StrmSyncTiming",
"SWDEV-402082 - PAL Backend fails to reserve address on GPU except first one",
"Unit_hipGraphInstantiateWithFlags_FlagAutoFreeOnLaunch_check",
"SWDEV-398981 fails in stress test",
"Unit_hipStreamCreateWithPriority_MulthreadDefaultflag",
"Disabling below tests temporarily due to change in API behavior",
"Unit_hipMemPrefetchAsync_NonPageSz",
"Unit_hipStreamCreateWithFlags_DefaultStreamInteraction",
"SWDEV-402054 fails in external github build",
"Unit_hipEventDestroy_WithWaitingStream",
"Note: UUID returned empty on some windows nodes",
"Unit_hipDeviceGetUuid_Positive",
"=== Below tests fail in external CI for PR https://github.com/ROCm-Developer-Tools/hip-tests/pull/96 ===",
"Unit_hipHostGetDevicePointer_Negative",
"=== Below tests fail in external CI for PR https://github.com/ROCm-Developer-Tools/hip-tests/pull/215 ===",
"Unit_ChannelDescriptor_Positive_Basic_1D - long",
"Unit_ChannelDescriptor_Positive_Basic_1D - unsigned long",
"Unit_ChannelDescriptor_Positive_Basic_1D - ulong1",
"Unit_ChannelDescriptor_Positive_Basic_1D - signed long",
"Unit_ChannelDescriptor_Positive_Basic_1D - long1",
"Unit_ChannelDescriptor_Positive_Basic_2D - ulong2",
"Unit_ChannelDescriptor_Positive_Basic_2D - long2",
"Unit_ChannelDescriptor_Positive_Basic_3D - ulong3",
"Unit_ChannelDescriptor_Positive_Basic_3D - long3",
"Unit_ChannelDescriptor_Positive_Basic_4D - ulong4",
"Unit_ChannelDescriptor_Positive_Basic_4D - long4",
"Unit_hipExtModuleLaunchKernel_NonUniformWorkGroup",
"=== Below tests fail in external CI for PR https://github.com/ROCm-Developer-Tools/hip-tests/pull/18 ===",
"Unit_hipMemcpyAsync_Negative_Parameters",
"Unit_hipMemcpyDtoHAsync_Negative_Parameters",
"Unit_hipMemcpyHtoDAsync_Negative_Parameters",
"Unit_hipMemcpyDtoDAsync_Negative_Parameters",
"=== Below tests fail in external CI for PR https://github.com/ROCm-Developer-Tools/hip-tests/pull/92 ===",
"Unit_hipGetChannelDesc_Negative_Parameters",
"Unit_hipTextureMipmapRef2D_Positive_Check",
"Unit_hipTextureMipmapRef2D_Negative_Parameters",
"=== Below hiprtc tests are disabled temporarily, will be renabled once patches for SWDEV-395996 are merged ===",
"Unit_hiprtc_saxpy",
"Unit_hiprtc_warpsize",
"Unit_hiprtc_functional",
"Unit_hipStreamCaptureRtc",
"Unit_hiprtc_cpp17",
"Unit_hiprtc_namehandling",
"Unit_hiprtc_getloweredname",
"Unit_hiprtc_test_hip_bfloat16",
"Unit_RTC_LinkerAPI",
"Unit_hiprtc_half_shuffle",
"Unit_hiprtc_includepath",
"=== Below tests fail in external CI for PR https://github.com/ROCm-Developer-Tools/hip-tests/pull/416 ===",
"Unit_hipStreamCreate_Performance",
"Unit_hipStreamCreate_WithFlagsPerformance_Nonblocking",
"Unit_hipStreamCreate_WithFlagsPerformance_Default",
"Unit_hipStreamCreate_WithPriorityPerformance_Nonblocking_low",
#endif
"End of json"
]
}
-102
Просмотреть файл
@@ -1,102 +0,0 @@
{
"DisabledTests":
[
"Unit_hipMalloc_CoherentTst",
"Unit_printf_flags",
"Unit_printf_specifier",
"Unit_hipTextureMipmapObj2D_Check",
"Unit_hipGraphAddHostNode_ClonedGraphwithHostNode",
"Unit_hipEventIpc",
"Unit_hipMalloc3D_Negative",
"Unit_hipPointerGetAttribute_MappedMem",
"Unit_hipStreamValue_Write",
"Unit_hipMemPoolApi_Basic",
"Unit_hipMemPoolApi_BasicAlloc",
"Unit_hipMemPoolApi_BasicTrim",
"Unit_hipMemPoolApi_BasicReuse",
"Unit_hipMemPoolApi_Opportunistic",
"Unit_hipMemPoolApi_Default",
"Unit_hipDeviceGetUuid",
"Unit_hipGraphMemcpyNodeSetParams_Functional",
"Unit_hipMalloc3D_ValidatePitch",
"Unit_hipArrayCreate_happy",
"Unit_hipHostRegister_Negative - int",
"Unit_hipHostRegister_Negative - float",
"Unit_hipHostRegister_Negative - double",
"Unit_hipMemAllocPitch_ValidatePitch",
"Unit_hipArrayCreate_happy - int",
"Unit_hipArrayCreate_happy - int4",
"Unit_hipArrayCreate_happy - short2",
"Unit_hipArrayCreate_happy - char",
"Unit_hipArrayCreate_happy - char4",
"Unit_hipArrayCreate_happy - float",
"Unit_hipArrayCreate_happy - float2",
"Unit_hipArrayCreate_happy - float4",
"Unit_hipMemVmm_Basic",
"Unit_hipGraphExecMemcpyNodeSetParamsToSymbol_Functional",
"Unit_hipMallocManaged_MultiChunkMultiDevice",
"Unit_hipMallocManaged_TwoPointers - int",
"Unit_hipMallocManaged_TwoPointers - float",
"Unit_hipMallocManaged_TwoPointers - double",
"Unit_hipMallocManaged_DeviceContextChange - unsigned char",
"Unit_hipMallocManaged_DeviceContextChange - int",
"Unit_hipMallocManaged_DeviceContextChange - float",
"Unit_hipMallocManaged_DeviceContextChange - double",
"Unit_hipGraphNodeGetDependentNodes_Functional",
"Unit_hipGraphNodeGetDependentNodes_ParamValidation",
"Unit_hipGraphNodeGetDependencies_Functional",
"Unit_hipGraphNodeGetDependencies_ParamValidation",
"Unit_hipMemGetInfo_DifferentMallocSmall",
"Unit_hipMemGetInfo_MallocArray - int",
"Unit_hipMemGetInfo_MallocArray - int4",
"Unit_hipMemGetInfo_MallocArray - char",
"Unit_hipMemGetInfo_Malloc3D",
"Unit_hipMemGetInfo_Malloc3DArray - char",
"Unit_hipMemGetInfo_Malloc3DArray - int",
"Unit_hipMemGetInfo_Malloc3DArray - int4",
"Unit_hipMemGetInfo_ParaSmall",
"Unit_hipMemGetInfo_ParaMultiSmall",
"Unit_hipFreeMultiTDev - char",
"Unit_hipFreeMultiTDev - int",
"Unit_hipFreeMultiTDev - float2",
"Unit_hipFreeMultiTDev - float4",
"Unit_hipFreeMultiTHost - char",
"Unit_hipFreeMultiTHost - int",
"Unit_hipFreeMultiTHost - float2",
"Unit_hipFreeMultiTHost - float4",
"Unit_hipFreeMultiTArray - char",
"Unit_hipFreeMultiTArray - int",
"Unit_hipFreeMultiTArray - float2",
"Unit_hipFreeMultiTArray - float4",
"Unit_hipStreamSynchronize_FinishWork",
"Unit_hipStreamSynchronize_NullStreamAndStreamPerThread",
"Unit_hipMultiThreadDevice_NearZero",
"Unit_hipStreamPerThread_DeviceReset_1",
"Unit_hipStreamValue_Wait32_Blocking_Mask_Gte",
"Unit_hipStreamValue_Wait32_Blocking_Mask_Eq_1",
"Unit_hipStreamValue_Wait32_Blocking_Mask_Eq_2",
"Unit_hipStreamValue_Wait32_Blocking_Mask_And",
"Unit_hipStreamValue_Wait32_Blocking_NoMask_Eq",
"Unit_hipStreamValue_Wait32_Blocking_NoMask_Gte",
"Unit_hipStreamValue_Wait32_Blocking_NoMask_And",
"Unit_hipStreamValue_Wait32_Blocking_NoMask_Nor",
"Unit_hipStreamValue_Wait64_Blocking_Mask_Gte_1",
"Unit_hipStreamValue_Wait64_Blocking_Mask_Gte_2",
"Unit_hipStreamValue_Wait64_Blocking_Mask_Eq_1",
"Unit_hipStreamValue_Wait64_Blocking_Mask_Eq_2",
"Unit_hipStreamValue_Wait64_Blocking_Mask_And",
"Unit_hipStreamValue_Wait64_Blocking_NoMask_Gte",
"Unit_hipStreamValue_Wait64_Blocking_NoMask_Eq",
"Unit_hipStreamValue_Wait64_Blocking_NoMask_And",
"Unit_hipStreamValue_Wait64_Blocking_NoMask_Nor",
"Unit_hipDeviceGetPCIBusId_Negative_PartialFill",
"Unit_hipInit_Negative",
"Unit_hipGraphAddEventRecordNode_Functional_ElapsedTime",
"Unit_hipStreamBeginCapture_captureComplexGraph",
"Unit_hipGraphAddChildGraphNode_MultGraphsAsSingleGraph"
"Unit_hipMemGetAddressRange_Negative",
"Unit_hipStreamValue_Wait64_Blocking_NoMask_Nor",
"Unit_hipLaunchHostFunc_Graph",
"Unit_hipLaunchHostFunc_KernelHost"
]
}
-216
Просмотреть файл
@@ -1,216 +0,0 @@
{
"DisabledTests":
[
"Unit_hipMalloc_CoherentTst",
"Unit_hipTextureMipmapObj2D_Check",
"Unit_hipGraphAddHostNode_ClonedGraphwithHostNode",
"Unit_hipEventIpc",
"Unit_hipMalloc3D_Negative",
"Unit_hipMemPoolApi_BasicAlloc",
"Unit_hipMemPoolApi_BasicTrim",
"Unit_hipMemPoolApi_BasicReuse",
"Unit_hipMemPoolApi_Opportunistic",
"Unit_hipMalloc3D_ValidatePitch",
"Unit_hipMemAllocPitch_ValidatePitch",
"Unit_hipGraphExecMemcpyNodeSetParamsToSymbol_Functional",
"Unit_hipMallocManaged_OverSubscription",
"Unit_hipMallocManaged_CoherentTstWthAdvise",
"Unit_hipMallocManaged_Advanced",
"Unit_hipMemRangeGetAttribute_TstCountParam",
"Unit_hipMemRangeGetAttribute_NegativeTests",
"Unit_hipMemRangeGetAttribute_AccessedBy1",
"Unit_hipMemRangeGetAttribte_3",
"Unit_hipMemRangeGetAttribute_4",
"Unit_hipMemRangeGetAttribute_PrefetchAndGtAttr",
"Unit_hipMemAdvise_TstFlags",
"Unit_hipMemAdvise_PrefrdLoc",
"Unit_hipMemAdvise_ReadMostly",
"Unit_hipMemAdvise_TstFlgOverrideEffect",
"Unit_hipMemAdvise_TstAccessedByFlg",
"Unit_hipMemAdvise_TstAccessedByFlg4",
"Unit_hipMemAdvise_TstMemAdvisePrefrdLoc",
"Unit_hipMemAdvise_TstMemAdviseMultiFlag",
"Unit_hipMemAdvise_ReadMosltyMgpuTst",
"Unit_hipMemAdvise_TstSetUnsetPrfrdLoc",
"Unit_hipMallocManaged_DeviceContextChange - unsigned char",
"Unit_hipMallocManaged_DeviceContextChange - int",
"Unit_hipMallocManaged_DeviceContextChange - float",
"Unit_hipMallocManaged_DeviceContextChange - double",
"Unit_hipStreamCreateWithPriority_ValidateWithEvents",
"Unit_hipStreamPerThread_StrmWaitEvt",
"Unit_hipMemGetInfo_DifferentMallocSmall",
"Unit_hipMemGetInfo_MallocArray - int",
"Unit_hipMemGetInfo_MallocArray - int4",
"Unit_hipMemGetInfo_MallocArray - char",
"Unit_hipMemGetInfo_Malloc3D",
"Unit_hipMemGetInfo_Malloc3DArray - char",
"Unit_hipMemGetInfo_Malloc3DArray - int",
"Unit_hipMemGetInfo_Malloc3DArray - int4",
"Unit_hipMemGetInfo_ParaSmall",
"Unit_hipMemGetInfo_ParaMultiSmall",
"Unit_hipMultiThreadDevice_NearZero",
"Unit_hipStreamPerThread_DeviceReset_1",
"Unit_hipStreamCreateWithPriority_ValidateWithEvents",
"Unit_hipStreamPerThread_StrmWaitEvt",
"Unit_hipGraphMemcpyNodeSetParamsToSymbol_Functional",
"Unit_hipStreamWaitEvent_DifferentStreams",
"Unit_hipStreamQuery_WithFinishedWork",
"Unit_hipDeviceGetCacheConfig_Positive_Basic",
"Unit_hipDeviceGetCacheConfig_Positive_Basic",
"Unit_hipDeviceGetCacheConfig_Positive_Threaded",
"Unit_hipStreamValue_Wait32_Blocking_Mask_Gte",
"Unit_hipStreamValue_Wait32_Blocking_Mask_Eq_1",
"Unit_hipStreamValue_Wait32_Blocking_Mask_Eq_2",
"Unit_hipStreamValue_Wait32_Blocking_Mask_And",
"Unit_hipStreamValue_Wait32_Blocking_NoMask_Eq",
"Unit_hipStreamValue_Wait32_Blocking_NoMask_Gte",
"Unit_hipStreamValue_Wait32_Blocking_NoMask_And",
"Unit_hipStreamValue_Wait32_Blocking_NoMask_Nor",
"Unit_hipStreamValue_Wait64_Blocking_Mask_Gte_1",
"Unit_hipStreamValue_Wait64_Blocking_Mask_Gte_2",
"Unit_hipStreamValue_Wait64_Blocking_Mask_Eq_1",
"Unit_hipStreamValue_Wait64_Blocking_Mask_Eq_2",
"Unit_hipStreamValue_Wait64_Blocking_Mask_And",
"Unit_hipStreamValue_Wait64_Blocking_NoMask_Gte",
"Unit_hipStreamValue_Wait64_Blocking_NoMask_Eq",
"Unit_hipStreamValue_Wait64_Blocking_NoMask_And",
"Unit_hipStreamValue_Wait64_Blocking_NoMask_Nor",
"Unit_hipGetDeviceFlags_Positive_Context",
"Unit_hipIpcCloseMemHandle_Negative_Close_In_Originating_Process",
"Unit_hipIpcOpenMemHandle_Negative_Open_In_Creating_Process",
"Unit_hipDeviceGetPCIBusId_Negative_PartialFill",
"Unit_hipDeviceGetSharedMemConfig_Positive_Basic",
"Unit_hipDeviceGetSharedMemConfig_Positive_Threaded",
"Unit_hipDeviceReset_Positive_Basic",
"Unit_hipDeviceReset_Positive_Threaded",
"Unit_hipInit_Negative",
"Unit_hipGraphMemcpyNodeSetParams_Functional",
"Unit_hipGraphNodeGetDependentNodes_Functional",
"Unit_hipGraphNodeGetDependencies_Functional",
"Unit_hipGraphExecChildGraphNodeSetParams_ChildTopology",
"Unit_hipGraphAddEventRecordNode_MultipleRun",
"Unit_hipGraphAddEventRecordNode_Functional_ElapsedTime",
"Unit_hipStreamBeginCapture_captureComplexGraph",
"Note: needs to be enabled when streamPerThread issues are fixed",
"Unit_hipStreamSynchronize_NullStreamAndStreamPerThread",
"Note: intermittent Seg fault failure ",
"Unit_hipGraphAddEventRecordNode_Functional_WithoutFlags",
"Unit_hipGraphAddChildGraphNode_MultGraphsAsSingleGraph",
"Unit_hipFuncSetCacheConfig_Positive_Basic",
"Unit_hipFuncSetCacheConfig_Negative_Parameters",
"Unit_hipFuncSetSharedMemConfig_Positive_Basic",
"Unit_hipFuncSetSharedMemConfig_Negative_Parameters",
"Unit_hipFuncSetAttribute_Positive_MaxDynamicSharedMemorySize",
"Unit_hipFuncSetAttribute_Positive_PreferredSharedMemoryCarveout",
"Unit_hipFuncSetAttribute_Positive_Parameters",
"Unit_hipFuncSetAttribute_Negative_Parameters",
"NOTE: The following 4 tests are disabled due to defect - EXSWHTEC-240",
"Unit_hipFuncSetCacheConfig_Negative_Not_Supported",
"Unit_hipFuncSetSharedMemConfig_Negative_Not_Supported",
"Unit_hipFuncSetAttribute_Positive_MaxDynamicSharedMemorySize_Not_Supported",
"Unit_hipFuncSetAttribute_Positive_PreferredSharedMemoryCarveout_Not_Supported",
"Unit_hipOccupancyMaxActiveBlocksPerMultiprocessor_Negative_Parameters",
"Unit_hipGraphMemcpyNodeSetParamsToSymbol_Positive_Basic",
"Unit_hipGraphExecMemcpyNodeSetParamsToSymbol_Positive_Basic",
"Unit_hipGraphMemcpyNodeSetParamsFromSymbol_Positive_Basic",
"Unit_hipGraphExecMemcpyNodeSetParamsFromSymbol_Positive_Basic",
"Unit_hipKernelNameRef_Negative_Parameters",
"Unit_hipKernelNameRef_Positive_Basic",
"Unit_hipMemAdvise_AccessedBy_All_Devices",
"Unit_hipMemAdvise_No_Flag_Interference",
"Unit_hipGraphAddEventRecordNode_Functional_WithoutFlags",
"Unit_hipGraphDestroyNode_Complx_ChkNumOfNodesNDep",
"Unit_hipGraphDestroyNode_Complx_ChkNumOfNodesNDep_ClonedGrph",
"Unit_hipGraphDestroyNode_Complx_ChkNumOfNodesNDep_ChldNode",
"Unit_hipMemGetAddressRange_Negative",
"NOTE: The following 2 tests are disabled due to defect - EXSWHTEC-238",
"Unit_hipDrvMemcpy3D_Positive_Array",
"Unit_hipDrvMemcpy3DAsync_Positive_Array",
"Unit_hipMemGetAddressRange_Positive",
"Note: devicelib hangs and failures",
"Unit_deviceAllocation_Malloc_PerThread_PrimitiveDataType",
"Unit_deviceAllocation_New_PerThread_PrimitiveDataType",
"Unit_deviceAllocation_Malloc_PerThread_StructDataType",
"Unit_deviceAllocation_New_PerThread_StructDataType",
"Unit_deviceAllocation_Malloc_AcrossKernels",
"Unit_deviceAllocation_New_AcrossKernels",
"Unit_deviceAllocation_Malloc_SingleCodeObj",
"Unit_deviceAllocation_New_SingleCodeObj",
"Unit_deviceAllocation_Malloc_PerThread_Graph",
"Unit_deviceAllocation_New_PerThread_Graph",
"Unit_deviceAllocation_Malloc_DeviceFunc",
"Unit_deviceAllocation_VirtualFunction",
"Unit_deviceAllocation_Malloc_MulKernels_MulThreads",
"Unit_deviceAllocation_New_MulKernels_MulThreads",
"Unit_deviceAllocation_Malloc_MulCodeObj",
"Unit_deviceAllocation_New_MulCodeObj",
"Unit_deviceAllocation_New_DeviceFunc",
"Unit_hipGraphAddEventRecordNode_MultipleRun",
"Unit_hipDeviceGetPCIBusId_Negative_PartialFill",
"Unit_hipStreamValue_Wait64_Blocking_NoMask_Nor",
"Unit_hipStreamQuery_WithFinishedWork",
"Unit_hipLaunchHostFunc_Graph",
"Unit_hipLaunchHostFunc_KernelHost",
"Unit_ChannelDescriptor_Positive_16BitFloatingPoint",
"Unit_hipStreamSetCaptureDependencies_Positive_Functional",
"Note: Following four tests disabled due to defect - EXSWHTEC-203",
"Unit_hipGraphAddMemsetNode_Positive_Basic - uint16_t",
"Unit_hipGraphAddMemsetNode_Positive_Basic - uint32_t",
"Unit_hipGraphMemsetNodeSetParams_Positive_Basic - uint16_t",
"Unit_hipGraphMemsetNodeSetParams_Positive_Basic - uint32_t",
"Note: Test disabled due to defect - EXSWHTEC-207",
"Unit_hipGraphExecMemsetNodeSetParams_Negative_Updating_Non1D_Node",
"Unit_hipGraphExecMemsetNodeSetParams_Positive_Basic - uint8_t",
"Unit_hipGraphExecMemsetNodeSetParams_Positive_Basic - uint16_t",
"Unit_hipGraphExecMemsetNodeSetParams_Positive_Basic - uint32_t",
"Unit_hipGraphMemsetNodeSetParams_Positive_Basic - uint8_t",
"Unit_hipStreamWaitEvent_UninitializedStream_Negative",
"Unit_hipDeviceGetUuid_Positive",
"Disabling test tracked SWDEV-394199",
"Unit_hipStreamCreateWithPriority_MulthreadNonblockingflag",
"SWDEV-396618 hipEventElapsedTime returns sucess",
"Unit_hipEventElapsedTime_NotReady_Negative",
"SWDEV-396617 ExecMemcpyNodeSetParamsFromSymbol fails in direction",
"Unit_hipGraphExecMemcpyNodeSetParamsFromSymbol_Negative_Parameters",
"SWDEV-396616 hipMemMap returns invalid error",
"Unit_hipMemVmm_Basic",
"SWDEV-396615 mGPUs not considered correctly",
"Unit_hipManagedKeyword_MultiGpu",
"Disabling test tracked SWDEV-391555",
"Unit_hipMemcpyPeer_Positive_ZeroSize",
"Unit_hipMemcpyPeerAsync_Positive_ZeroSize",
"Disabling test tracked SWDEV-391718",
"Unit_hipMemRangeGetAttribute_TstCountParam",
"SWDEV-400049 tdr intermittently",
"Unit_hipMemsetDSync – init16_t",
"Unit_hipStreamAddCallback_StrmSyncTiming",
"SWDEV-402082 - PAL Backend fails to reserve address on GPU except first one",
"Unit_hipGraphInstantiateWithFlags_FlagAutoFreeOnLaunch_check",
"SWDEV-398981 fails in stress test",
"Unit_hipStreamCreateWithPriority_MulthreadDefaultflag",
"SWDEV-402054 fails in external github build",
"Unit_hipEventDestroy_WithWaitingStream",
"Note: UUID returned empty on some windows nodes",
"Unit_hipDeviceGetUuid_Positive",
"=== Below tests fail in external CI for PR https://github.com/ROCm-Developer-Tools/hip-tests/pull/96 ===",
"Unit_hipHostGetDevicePointer_Negative",
"=== Below tests fail in external CI for PR https://github.com/ROCm-Developer-Tools/hip-tests/pull/215 ===",
"Unit_ChannelDescriptor_Positive_Basic_1D - long",
"Unit_ChannelDescriptor_Positive_Basic_1D - unsigned long",
"Unit_ChannelDescriptor_Positive_Basic_1D - ulong1",
"Unit_ChannelDescriptor_Positive_Basic_1D - signed long",
"Unit_ChannelDescriptor_Positive_Basic_1D - long1",
"Unit_ChannelDescriptor_Positive_Basic_2D - ulong2",
"Unit_ChannelDescriptor_Positive_Basic_2D - long2",
"Unit_ChannelDescriptor_Positive_Basic_3D - ulong3",
"Unit_ChannelDescriptor_Positive_Basic_3D - long3",
"Unit_ChannelDescriptor_Positive_Basic_4D - ulong4",
"Unit_ChannelDescriptor_Positive_Basic_4D - long4",
"Unit_hipExtModuleLaunchKernel_NonUniformWorkGroup",
"=== Below tests fail in external CI for PR https://github.com/ROCm-Developer-Tools/hip-tests/pull/18 ===",
"Unit_hipMemcpyAsync_Negative_Parameters",
"Unit_hipMemcpyDtoHAsync_Negative_Parameters",
"Unit_hipMemcpyHtoDAsync_Negative_Parameters",
"Unit_hipMemcpyDtoDAsync_Negative_Parameters"
]
}
+35
Просмотреть файл
@@ -0,0 +1,35 @@
{
"DisabledTests": [
"Unit_hipFuncSetCacheConfig_Negative_Not_Supported",
"Unit_hipFuncSetSharedMemConfig_Negative_Not_Supported",
"Unit_hipFuncSetAttribute_Positive_MaxDynamicSharedMemorySize_Not_Supported",
"Unit_hipFuncSetAttribute_Positive_PreferredSharedMemoryCarveout_Not_Supported",
"=== Below test fails in external CI for PR https://github.com/ROCm-Developer-Tools/hip-tests/pull/85 ===",
"Unit_hipFuncSetAttribute_Negative_Parameters",
"=== Below test fails in external CI for PR https://github.com/ROCm-Developer-Tools/hip-tests/pull/215 ===",
"Unit_ChannelDescriptor_Positive_Basic_1D - long",
"Unit_ChannelDescriptor_Positive_Basic_1D - unsigned long",
"Unit_ChannelDescriptor_Positive_Basic_1D - ulong1",
"Unit_ChannelDescriptor_Positive_Basic_1D - signed long",
"Unit_ChannelDescriptor_Positive_Basic_1D - long1",
"Unit_ChannelDescriptor_Positive_Basic_2D - ulong2",
"Unit_ChannelDescriptor_Positive_Basic_2D - long2",
"Unit_ChannelDescriptor_Positive_Basic_3D - ulong3",
"Unit_ChannelDescriptor_Positive_Basic_3D - long3",
"Unit_ChannelDescriptor_Positive_Basic_4D - ulong4",
"Unit_ChannelDescriptor_Positive_Basic_4D - long4",
"=== Below test fails in external CI for PR https://github.com/ROCm-Developer-Tools/hip-tests/pull/38 ===",
"Unit_hipFreeAsync_negative",
"=== Below test fails in external CI for PR https://github.com/ROCm-Developer-Tools/hip-tests/pull/222 ===",
"Unit_hipStreamCreate_Performance",
"Unit_hipStreamCreate_WithPriorityPerformance_Nonblocking_high",
"Unit_hipStreamCreate_WithPriorityPerformance_Default_low",
"Unit_hipStreamCreate_WithPriorityPerformance_Nonblocking_low",
"=== Below test fails in external CI for PR https://github.com/ROCm-Developer-Tools/hip-tests/pull/92 ===",
"Unit_hipGetTexObjectResourceDesc_positive",
"Unit_hipGetTexObjectResourceDesc_Negative_Parameters",
"Unit_hipGetTexObjectTextureDesc_positive",
"Unit_hipGetTexObjectTextureDesc_Negative_Parameters",
"Unit_hipTexObjectDestroy_positive"
]
}
-25
Просмотреть файл
@@ -1,25 +0,0 @@
{
"DisabledTests":
[
"Unit_hipFuncSetCacheConfig_Negative_Not_Supported",
"Unit_hipFuncSetSharedMemConfig_Negative_Not_Supported",
"Unit_hipFuncSetAttribute_Positive_MaxDynamicSharedMemorySize_Not_Supported",
"Unit_hipFuncSetAttribute_Positive_PreferredSharedMemoryCarveout_Not_Supported",
"=== Below test fails in external CI for PR https://github.com/ROCm-Developer-Tools/hip-tests/pull/85 ===",
"Unit_hipFuncSetAttribute_Negative_Parameters",
"=== Below test fails in external CI for PR https://github.com/ROCm-Developer-Tools/hip-tests/pull/215 ===",
"Unit_ChannelDescriptor_Positive_Basic_1D - long",
"Unit_ChannelDescriptor_Positive_Basic_1D - unsigned long",
"Unit_ChannelDescriptor_Positive_Basic_1D - ulong1",
"Unit_ChannelDescriptor_Positive_Basic_1D - signed long",
"Unit_ChannelDescriptor_Positive_Basic_1D - long1",
"Unit_ChannelDescriptor_Positive_Basic_2D - ulong2",
"Unit_ChannelDescriptor_Positive_Basic_2D - long2",
"Unit_ChannelDescriptor_Positive_Basic_3D - ulong3",
"Unit_ChannelDescriptor_Positive_Basic_3D - long3",
"Unit_ChannelDescriptor_Positive_Basic_4D - ulong4",
"Unit_ChannelDescriptor_Positive_Basic_4D - long4",
"=== Below test fails in external CI for PR https://github.com/ROCm-Developer-Tools/hip-tests/pull/38 ===",
"Unit_hipFreeAsync_negative"
]
}
+20
Просмотреть файл
@@ -0,0 +1,20 @@
{
"DisabledTests": [
"Unit_hipFuncSetCacheConfig_Negative_Not_Supported",
"Unit_hipFuncSetSharedMemConfig_Negative_Not_Supported",
"Unit_hipFuncSetAttribute_Positive_MaxDynamicSharedMemorySize_Not_Supported",
"Unit_hipFuncSetAttribute_Positive_PreferredSharedMemoryCarveout_Not_Supported",
"=== Below test fails in external CI for PR https://github.com/ROCm-Developer-Tools/hip-tests/pull/215 ===",
"Unit_ChannelDescriptor_Positive_Basic_1D - long",
"Unit_ChannelDescriptor_Positive_Basic_1D - unsigned long",
"Unit_ChannelDescriptor_Positive_Basic_1D - ulong1",
"Unit_ChannelDescriptor_Positive_Basic_1D - signed long",
"Unit_ChannelDescriptor_Positive_Basic_1D - long1",
"Unit_ChannelDescriptor_Positive_Basic_2D - ulong2",
"Unit_ChannelDescriptor_Positive_Basic_2D - long2",
"Unit_ChannelDescriptor_Positive_Basic_3D - ulong3",
"Unit_ChannelDescriptor_Positive_Basic_3D - long3",
"Unit_ChannelDescriptor_Positive_Basic_4D - ulong4",
"Unit_ChannelDescriptor_Positive_Basic_4D - long4"
]
}
-21
Просмотреть файл
@@ -1,21 +0,0 @@
{
"DisabledTests":
[
"Unit_hipFuncSetCacheConfig_Negative_Not_Supported",
"Unit_hipFuncSetSharedMemConfig_Negative_Not_Supported",
"Unit_hipFuncSetAttribute_Positive_MaxDynamicSharedMemorySize_Not_Supported",
"Unit_hipFuncSetAttribute_Positive_PreferredSharedMemoryCarveout_Not_Supported",
"=== Below test fails in external CI for PR https://github.com/ROCm-Developer-Tools/hip-tests/pull/215 ===",
"Unit_ChannelDescriptor_Positive_Basic_1D - long",
"Unit_ChannelDescriptor_Positive_Basic_1D - unsigned long",
"Unit_ChannelDescriptor_Positive_Basic_1D - ulong1",
"Unit_ChannelDescriptor_Positive_Basic_1D - signed long",
"Unit_ChannelDescriptor_Positive_Basic_1D - long1",
"Unit_ChannelDescriptor_Positive_Basic_2D - ulong2",
"Unit_ChannelDescriptor_Positive_Basic_2D - long2",
"Unit_ChannelDescriptor_Positive_Basic_3D - ulong3",
"Unit_ChannelDescriptor_Positive_Basic_3D - long3",
"Unit_ChannelDescriptor_Positive_Basic_4D - ulong4",
"Unit_ChannelDescriptor_Positive_Basic_4D - long4"
]
}
+56 -23
Просмотреть файл
@@ -35,31 +35,61 @@ std::string TestContext::substringFound(std::vector<std::string> list, std::stri
return match;
}
std::string TestContext::getMatchingConfigFile(std::string config_dir) {
std::string configFileToUse;
for (auto& p : fs::recursive_directory_iterator(config_dir)) {
fs::path filename = p.path();
std::string cur_arch = "TODO";
std::string arch = substringFound(amd_arch_list_, filename.filename().string());
std::string platform = substringFound(platform_list_, filename.filename().string());
std::string os = substringFound(os_list_, filename.filename().string());
std::string common_arch = "common";
std::vector<std::string> default_arch_vec {common_arch};
std::string common = substringFound(default_arch_vec, filename.filename().string());
// if arch found then use that exit from loop
if (arch == cur_arch) {
configFileToUse = filename.string();
break;
// match the platform/os and continue to look
} else if ((platform == config_.platform) && (os == config_.os || os == "all") &&
common == common_arch) { // ensures only common file is returned
configFileToUse = filename.string();
std::string TestContext::getCurrentArch() {
#if HT_LINUX
const char* cmd = "/opt/rocm/bin/rocm_agent_enumerator | sort -u | xargs | sed -e 's/ /;/g'";
std::array<char, 1024> buffer;
std::string result;
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose);
if (!pipe) {
printf("popen() failed!");
return "";
}
while (fgets(buffer.data(), buffer.size(), pipe.get()) != nullptr) {
std::string res = buffer.data();
result = res;
}
result.erase(std::remove(result.begin(), result.end(), '\n'), result.end());
size_t pos = result.find("gfx000");
if (pos != std::string::npos) {
result.erase(pos, 7);
}
std::stringstream arch_list(result);
std::string arch1 = "", arch2 = "";
if (!arch_list.eof()) {
getline(arch_list, arch1, ';');
}
while (!arch_list.eof()) {
getline(arch_list, arch2, ';');
int result = strcmp(arch1.c_str(), arch2.c_str());
if (result != 0) {
LogPrintf("%s",
"[ERROR] Cannot run tests on Hetrogenous Architecture. Please set "
"HIP_VISIBLE_DEVICES with devices of same arch");
abort();
}
}
return configFileToUse;
return arch1;
#else
return "";
#endif
}
std::string TestContext::getMatchingConfigFile(std::string config_dir) {
std::string configFileToUse = "";
if (isLinux() && isAmd()) {
std::string cur_arch = getCurrentArch();
configFileToUse = config_dir + "/config_" + getConfig().platform + "_" + getConfig().os + "_" +
cur_arch + ".json";
} else {
configFileToUse =
config_dir + "/config_" + getConfig().platform + "_" + getConfig().os + ".json";
}
if (fs::exists(configFileToUse)) {
return configFileToUse;
}
return "";
}
std::string& TestContext::getCommonJsonFile() {
fs::path config_dir = exe_path;
@@ -102,15 +132,18 @@ void TestContext::getConfigFiles() {
std::string env_config = TestContext::getEnvVar("HIP_CATCH_EXCLUDE_FILE");
LogPrintf("Env Config file: %s",
(!env_config.empty()) ? env_config.c_str() : "Not found, using common config");
(!env_config.empty()) ? env_config.c_str() : "Not found");
// HIP_CATCH_EXCLUDE_FILE is set for custom file path
if (!env_config.empty()) {
if(fs::exists(env_config)) {
config_.json_files.push_back(env_config);
}
} else {
std::string jsonFile = getCommonJsonFile();
// get common json file
config_.json_files.push_back(getCommonJsonFile());
if (jsonFile != "") {
config_.json_files.push_back(getCommonJsonFile());
}
}
for (const auto& fl : config_.json_files) {
+2 -1
Просмотреть файл
@@ -21,6 +21,7 @@ THE SOFTWARE.
*/
#pragma once
#pragma clang diagnostic ignored "-Wsign-compare"
#include "hip_test_context.hh"
#include <catch.hpp>
@@ -355,7 +356,7 @@ class BlockingContext {
hipStream_t stream;
public:
BlockingContext(hipStream_t s) : stream(s), blocked(true) {}
BlockingContext(hipStream_t s) : blocked(true), stream(s) {}
BlockingContext(const BlockingContext& in) {
blocked = in.blocked_val();
+1
Просмотреть файл
@@ -100,6 +100,7 @@ class TestContext {
void parseOptions(int, char**);
bool parseJsonFiles();
std::string getMatchingConfigFile(std::string config_dir);
std::string getCurrentArch();
const Config& getConfig() const { return config_; }
+62 -68
Просмотреть файл
@@ -30,16 +30,17 @@ THE SOFTWARE.
*/
/**
* @defgroup GraphTest Graph Management
* @defgroup ContextTest Context Management
* @{
* This section describes tests for the graph management types & functions of HIP runtime API.
* This section describes tests for the context management functions of HIP runtime API.
* @warning All Context Management APIs are **deprecated** and shall not be implemented.
* @}
*/
/**
* @defgroup VectorTypeTest Vector types
* @defgroup DeviceLanguageTest Device Language
* @{
* This section describes tests for the Vector type functions and operators.
* This section describes tests for the Device Language API.
* @}
*/
@@ -50,28 +51,6 @@ THE SOFTWARE.
* @}
*/
/**
* @defgroup EventTest Event Management
* @{
* This section describes tests for the event management functions of HIP runtime API.
* @}
*/
/**
* @defgroup ErrorTest Error Handling
* @{
* This section describes tests for the error handling functions of HIP runtime API.
* @}
*/
/**
* @defgroup PeerToPeerTest PeerToPeer Device Memory Access
* @{
* This section describes tests for the PeerToPeer device memory access functions of HIP runtime API.
* @warning PeerToPeer support is experimental.
* @}
*/
/**
* @defgroup DriverTest Initialization and Version
* @{
@@ -79,42 +58,6 @@ THE SOFTWARE.
* @}
*/
/**
* @defgroup DeviceLanguageTest Device Language
* @{
* This section describes tests for the Device Language API.
* @}
*/
/**
* @defgroup ExecutionTest Execution Control
* @{
* This section describes tests for the execution control functions of HIP runtime API.
* @}
*/
/**
* @defgroup ShflTest warp shuffle function Management
* @{
* This section describes the warp shuffle types & functions of HIP runtime API.
* @}
*/
/**
* @defgroup ContextTest Context Management
* @{
* This section describes tests for the context management functions of HIP runtime API.
* @warning All Context Management APIs are **deprecated** and shall not be implemented.
* @}
*/
/**
* @defgroup StreamTest Stream Management
* @{
* This section describes the stream management types & functions of HIP runtime API.
* @}
*/
/**
* @defgroup DynamicLoadingTest Kernel Loading Management
* @{
@@ -123,9 +66,30 @@ THE SOFTWARE.
*/
/**
* @defgroup MemoryTest memory Management APIs
* @defgroup ErrorTest Error Handling
* @{
* This section describes the memory management types & functions of HIP runtime API.
* This section describes tests for the error handling functions of HIP runtime API.
* @}
*/
/**
* @defgroup EventTest Event Management
* @{
* This section describes tests for the event management functions of HIP runtime API.
* @}
*/
/**
* @defgroup ExecutionTest Execution Control
* @{
* This section describes tests for the execution control functions of HIP runtime API.
* @}
*/
/**
* @defgroup GraphTest Graph Management
* @{
* This section describes tests for the graph management types & functions of HIP runtime API.
* @}
*/
@@ -137,14 +101,44 @@ THE SOFTWARE.
*/
/**
* @defgroup DeviceLanguageTest Device Language
* @defgroup MemoryTest memory Management APIs
* @{
* This section describes tests for the Device Language API.
* This section describes the memory management types & functions of HIP runtime API.
* @}
*/
/**
* @defgroup DeviceLanguageTest Device Language
* @defgroup PeerToPeerTest PeerToPeer Device Memory Access
* @{
* This section describes tests for the Device Language API.
* This section describes tests for the PeerToPeer device memory access functions of HIP runtime API.
* @warning PeerToPeer support is experimental.
* @}
*/
/**
* @defgroup ShflTest warp shuffle function Management
* @{
* This section describes the warp shuffle types & functions of HIP runtime API.
* @}
*/
/**
* @defgroup StreamTest Stream Management
* @{
* This section describes the stream management types & functions of HIP runtime API.
* @}
*/
/**
* @defgroup TextureTest Texture Management
* @{
* This section describes tests for the texture management functions of HIP runtime API.
* @}
*/
/**
* @defgroup VectorTypeTest Vector types
* @{
* This section describes tests for the Vector type functions and operators.
* @}
*/
+9 -7
Просмотреть файл
@@ -21,7 +21,8 @@ THE SOFTWARE.
*/
#pragma once
#pragma clang diagnostic ignored "-Wmissing-field-initializers"
#pragma clang diagnostic ignored "-Wunused-lambda-capture"
#include <variant>
#include <hip_test_common.hh>
@@ -31,7 +32,7 @@ THE SOFTWARE.
using PtrVariant = std::variant<hipPitchedPtr, hipArray_t>;
static hipMemcpyKind ReverseMemcpyDirection(const hipMemcpyKind direction) {
static inline hipMemcpyKind ReverseMemcpyDirection(const hipMemcpyKind direction) {
switch (direction) {
case hipMemcpyHostToDevice:
return hipMemcpyDeviceToHost;
@@ -76,7 +77,7 @@ static bool operator==(const hipExtent& lhs, const hipExtent& rhs) {
return lhs.width == rhs.width && lhs.height == rhs.height && lhs.depth == rhs.depth;
}
static bool operator==(const hipMemcpy3DParms& lhs, const hipMemcpy3DParms& rhs) {
static inline bool operator==(const hipMemcpy3DParms& lhs, const hipMemcpy3DParms& rhs) {
return lhs.dstArray == rhs.dstArray && lhs.dstPtr == rhs.dstPtr && lhs.dstPos == rhs.dstPos &&
lhs.srcArray == rhs.srcArray && lhs.srcPtr == rhs.srcPtr && lhs.srcPos == rhs.srcPos &&
lhs.extent == rhs.extent && lhs.kind == rhs.kind;
@@ -168,7 +169,6 @@ void Memcpy3DDeviceToDeviceShell(F memcpy_func, const hipStream_t kernel_stream
const auto device_count = HipTest::getDeviceCount();
const auto src_device = GENERATE_COPY(range(0, device_count));
const auto dst_device = GENERATE_COPY(range(0, device_count));
const size_t src_cols_mult = GENERATE(1, 2);
INFO("Src device: " << src_device << ", Dst device: " << dst_device);
@@ -180,8 +180,10 @@ void Memcpy3DDeviceToDeviceShell(F memcpy_func, const hipStream_t kernel_stream
int can_access_peer = 0;
HIP_CHECK(hipDeviceCanAccessPeer(&can_access_peer, src_device, dst_device));
if (!can_access_peer) {
INFO("Peer access cannot be enabled between devices " << src_device << " " << dst_device);
REQUIRE(can_access_peer);
std::string msg = "Skipped as peer access cannot be enabled between devices " +
std::to_string(src_device) + " " + std::to_string(dst_device);
HipTest::HIP_SKIP_TEST(msg.c_str());
return;
}
HIP_CHECK(hipDeviceEnablePeerAccess(dst_device, 0));
}
@@ -797,4 +799,4 @@ void DrvMemcpy3DArrayDeviceShell(F memcpy_func, const hipStream_t kernel_stream
};
PitchedMemoryVerify(host_alloc.ptr(), extent.width, extent.width / sizeof(int), extent.height,
extent.depth, f);
}
}
+3
Просмотреть файл
@@ -33,6 +33,9 @@ THE SOFTWARE.
#include <hip_test_common.hh>
#include <resource_guards.hh>
#pragma clang diagnostic ignored "-Wunused-but-set-variable"
#pragma clang diagnostic ignored "-Wunused-function"
#if defined(_WIN32)
#if defined(_WIN64)
typedef __int64 ssize_t;
-4
Просмотреть файл
@@ -131,7 +131,6 @@ TEST_CASE("Unit_malloc_CoherentTst") {
p = strstr(prop.gcnArchName, "xnack+");
if (p) {
// Test Case execution begins from here
int stat = 0;
int managed = 0;
HIPCHECK(hipDeviceGetAttribute(&managed, hipDeviceAttributeManagedMemory,
0));
@@ -162,7 +161,6 @@ TEST_CASE("Unit_malloc_CoherentTstWthAdvise") {
char *p = NULL;
p = strstr(prop.gcnArchName, "xnack+");
if (p) {
int stat = 0;
int managed = 0;
HIP_CHECK(hipDeviceGetAttribute(&managed, hipDeviceAttributeManagedMemory,
0));
@@ -195,7 +193,6 @@ TEST_CASE("Unit_mmap_CoherentTst") {
char *p = NULL;
p = strstr(prop.gcnArchName, "xnack+");
if (p) {
int stat = 0;
int managed = 0;
HIP_CHECK(hipDeviceGetAttribute(&managed, hipDeviceAttributeManagedMemory,
0));
@@ -233,7 +230,6 @@ TEST_CASE("Unit_mmap_CoherentTstWthAdvise") {
char *p = NULL;
p = strstr(prop.gcnArchName, "xnack+");
if (p) {
int stat = 0;
int managed = 0;
HIP_CHECK(hipDeviceGetAttribute(&managed, hipDeviceAttributeManagedMemory,
0));
+1
Просмотреть файл
@@ -18,4 +18,5 @@
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
add_subdirectory(event)
add_subdirectory(example)
+14 -23
Просмотреть файл
@@ -1,4 +1,4 @@
# Copyright (c) 2020 - 2021 Advanced Micro Devices, Inc. All Rights Reserved.
# Copyright (c) 2022 Advanced Micro Devices, Inc. All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@@ -17,27 +17,18 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
ifeq ($(OS),Windows_NT)
$(error Makefile is not supported on windows platform. Please use cmake instead to build sample.)
endif
ROCM_PATH?= $(wildcard /opt/rocm/)
HIP_PATH?= $(wildcard $(ROCM_PATH)/hip)
ifeq (,$(HIP_PATH))
HIP_PATH=../../..
endif
HIPCC=$(HIP_PATH)/bin/hipcc
INCLUDES := -I../../common
EXE=./gpuarch
.PHONY: test
set(TEST_SRC
hipEventCreate.cc
hipEventCreateWithFlags.cc
hipEventRecord.cc
hipEventDestroy.cc
hipEventSynchronize.cc
hipEventElapsedTime.cc
hipEventQuery.cc
)
all: test
$(EXE): gpuarch.cpp
$(HIPCC) $(INCLUDES) $^ -o $@
test: $(EXE)
$(EXE)
clean:
rm -f *.o $(EXE)
hip_add_exe_to_target(NAME EventPerformance
TEST_SRC ${TEST_SRC}
TEST_TARGET_NAME build_tests
COMPILE_OPTIONS -std=c++17)
+56
Просмотреть файл
@@ -0,0 +1,56 @@
/*
Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip_test_common.hh>
#include <performance_common.hh>
#include <resource_guards.hh>
/**
* @addtogroup event event
* @{
* @ingroup PerformanceTest
* Contains performance tests for all hipEvent related HIP APIs.
*/
class HipEventCreateBenchmark : public Benchmark<HipEventCreateBenchmark> {
public:
void operator()() {
hipEvent_t event;
TIMED_SECTION(kTimerTypeCpu) { HIP_CHECK(hipEventCreate(&event)); }
HIP_CHECK(hipEventDestroy(event));
}
};
/**
* Test Description
* ------------------------
* - Executes `hipEventCreate`
* Test source
* ------------------------
* - performance/event/hipEventCreate.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
TEST_CASE("Performance_hipEventCreate") {
HipEventCreateBenchmark benchmark;
benchmark.Run();
}
+83
Просмотреть файл
@@ -0,0 +1,83 @@
/*
Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip_test_common.hh>
#include <performance_common.hh>
#include <resource_guards.hh>
/**
* @addtogroup event event
* @{
* @ingroup PerformanceTest
*/
class HipEventCreateWithFlagsBenchmark : public Benchmark<HipEventCreateWithFlagsBenchmark> {
public:
void operator()(unsigned flag) {
hipEvent_t event;
TIMED_SECTION(kTimerTypeCpu) { HIP_CHECK(hipEventCreateWithFlags(&event, flag)); }
HIP_CHECK(hipEventDestroy(event));
}
};
static std::string GetEventCreateFlagName(unsigned flag) {
switch (flag) {
case hipEventDefault:
return "hipEventDefault";
case hipEventBlockingSync:
return "hipEventBlockingSync";
case hipEventDisableTiming:
return "hipEventDisableTiming";
case hipEventInterprocess:
return "hipEventInterprocess";
default:
return "flag combination";
}
}
static void RunBenchmark(unsigned flag) {
HipEventCreateWithFlagsBenchmark benchmark;
benchmark.AddSectionName(GetEventCreateFlagName(flag));
benchmark.Run(flag);
}
/**
* Test Description
* ------------------------
* - Executes `hipEventCreateWithFlags` with all flags:
* -# Flags
* - hipEventDefault
* - hipEventBlockingSync
* - hipEventDisableTiming
* - hipEventInterprocess (currently disabled)
* Test source
* ------------------------
* - performance/event/hipEventCreate.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
TEST_CASE("Performance_hipEventCreateWithFlags") {
const auto flag = GENERATE(
hipEventDefault, hipEventBlockingSync,
hipEventDisableTiming /*, hipEventInterprocess disabled until fixed (EXSWHTEC-25) */);
RunBenchmark(flag);
}
+54
Просмотреть файл
@@ -0,0 +1,54 @@
/*
Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip_test_common.hh>
#include <performance_common.hh>
#include <resource_guards.hh>
/**
* @addtogroup event event
* @{
* @ingroup PerformanceTest
*/
class HipEventDestroyBenchmark : public Benchmark<HipEventDestroyBenchmark> {
public:
void operator()() {
hipEvent_t event;
HIP_CHECK(hipEventCreate(&event));
TIMED_SECTION(kTimerTypeCpu) { HIP_CHECK(hipEventDestroy(event)); }
}
};
/**
* Test Description
* ------------------------
* - Executes `hipEventDestroy`
* Test source
* ------------------------
* - performance/event/hipEventCreate.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
TEST_CASE("Performance_hipEventDestroy") {
HipEventDestroyBenchmark benchmark;
benchmark.Run();
}
+68
Просмотреть файл
@@ -0,0 +1,68 @@
/*
Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <chrono>
#include <thread>
#include <hip_test_common.hh>
#include <performance_common.hh>
#include <resource_guards.hh>
/**
* @addtogroup event event
* @{
* @ingroup PerformanceTest
*/
class HipEventElapsedTimeBenchmark : public Benchmark<HipEventElapsedTimeBenchmark> {
public:
void operator()() {
hipEvent_t start, end;
float time;
HIP_CHECK(hipEventCreate(&start));
HIP_CHECK(hipEventCreate(&end));
HIP_CHECK(hipEventRecord(start));
std::this_thread::sleep_for(std::chrono::milliseconds(5)); /* idle for 5 ms */
HIP_CHECK(hipEventRecord(end));
HIP_CHECK(hipEventSynchronize(end));
TIMED_SECTION(kTimerTypeCpu) { HIP_CHECK(hipEventElapsedTime(&time, start, end)); }
HIP_CHECK(hipEventDestroy(start));
HIP_CHECK(hipEventDestroy(end));
}
};
/**
* Test Description
* ------------------------
* - Executes `hipEventElapsedTime`
* Test source
* ------------------------
* - performance/event/hipEventElapsedTime.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
TEST_CASE("Performance_hipEventElapsedTime") {
HipEventElapsedTimeBenchmark benchmark;
benchmark.Run();
}
+58
Просмотреть файл
@@ -0,0 +1,58 @@
/*
Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip_test_common.hh>
#include <performance_common.hh>
#include <resource_guards.hh>
/**
* @addtogroup event event
* @{
* @ingroup PerformanceTest
*/
class HipEventQueryBenchmark : public Benchmark<HipEventQueryBenchmark> {
public:
void operator()() {
hipEvent_t event;
HIP_CHECK(hipEventCreate(&event));
HIP_CHECK(hipEventRecord(event));
HIP_CHECK(hipEventSynchronize(event));
TIMED_SECTION(kTimerTypeCpu) { HIP_CHECK(hipEventQuery(event)); }
HIP_CHECK(hipEventDestroy(event));
}
};
/**
* Test Description
* ------------------------
* - Executes `hipEventQuery`
* Test source
* ------------------------
* - performance/event/hipEventQuery.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
TEST_CASE("Performance_hipEventQuery") {
HipEventQueryBenchmark benchmark;
benchmark.Run();
}
+73
Просмотреть файл
@@ -0,0 +1,73 @@
/*
Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip_test_common.hh>
#include <performance_common.hh>
#include <resource_guards.hh>
/**
* @addtogroup event event
* @{
* @ingroup PerformanceTest
*/
class HipEventRecordBenchmark : public Benchmark<HipEventRecordBenchmark> {
public:
void operator()(hipStream_t stream) {
hipEvent_t event;
HIP_CHECK(hipEventCreate(&event));
TIMED_SECTION(kTimerTypeCpu) { HIP_CHECK(hipEventRecord(event, stream)); }
HIP_CHECK(hipEventDestroy(event));
}
};
static void RunBenchmark(hipStream_t stream) {
HipEventRecordBenchmark benchmark;
if (stream == NULL) {
benchmark.AddSectionName("Default stream");
} else {
benchmark.AddSectionName("Created stream");
}
benchmark.Run(stream);
}
/**
* Test Description
* ------------------------
* - Executes `hipEventRecord`
* -# Executed both on
* - default stream
* - created stream
* Test source
* ------------------------
* - performance/event/hipEventRecord.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
TEST_CASE("Performance_hipEventRecord") {
SECTION("default stream") { RunBenchmark(nullptr); }
SECTION("created stream") {
StreamGuard stream(Streams::created);
RunBenchmark(stream.stream());
}
}
+70
Просмотреть файл
@@ -0,0 +1,70 @@
/*
Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip_test_common.hh>
#include <performance_common.hh>
#include <resource_guards.hh>
/**
* @addtogroup event event
* @{
* @ingroup PerformanceTest
*/
class HipEventSynchronizeBenchmark : public Benchmark<HipEventSynchronizeBenchmark> {
public:
void operator()(unsigned flag) {
hipEvent_t event;
HIP_CHECK(hipEventCreateWithFlags(&event, flag));
HIP_CHECK(hipEventRecord(event));
TIMED_SECTION(kTimerTypeCpu) { HIP_CHECK(hipEventSynchronize(event)); }
HIP_CHECK(hipEventDestroy(event));
}
};
static void RunBenchmark(unsigned flag) {
HipEventSynchronizeBenchmark benchmark;
if (flag == hipEventDefault) {
benchmark.AddSectionName("Default event");
} else {
benchmark.AddSectionName("Blocking sync event");
}
benchmark.Run(flag);
}
/**
* Test Description
* ------------------------
* - Executes `hipEventSynchronize`
* -# Checked on events created with flags:
* - hipEventDefault
* - hipEventBlockingSync
* Test source
* ------------------------
* - performance/event/hipEventSynchronize.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
TEST_CASE("Performance_hipEventSynchronize") {
const auto flag = GENERATE(hipEventDefault, hipEventBlockingSync);
RunBenchmark(flag);
}
+4 -23
Просмотреть файл
@@ -1,4 +1,4 @@
# Copyright (c) 2019 - 2021 Advanced Micro Devices, Inc. All Rights Reserved.
# Copyright (c) 2023 Advanced Micro Devices, Inc. All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@@ -17,27 +17,8 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
ifeq ($(OS),Windows_NT)
$(error Makefile is not supported on windows platform. Please use cmake instead to build sample.)
endif
ROCM_PATH?= $(wildcard /opt/rocm/)
HIP_PATH?= $(wildcard $(ROCM_PATH)/hip)
ifeq (,$(HIP_PATH))
HIP_PATH=../../..
endif
HIPCC=$(HIP_PATH)/bin/hipcc
INCLUDES := -I../../common
EXE=./occupancy
.PHONY: test
add_custom_target(perf_test COMMAND "${CMAKE_CTEST_COMMAND}" -R "Perf_"
COMMENT "Build complete, now executing the performnce test ...")
all: test
$(EXE): occupancy.cpp
$(HIPCC) $(INCLUDES) $^ -o $@
test: $(EXE)
$(EXE)
clean:
rm -f *.o $(EXE)
add_subdirectory(memory)
+26 -26
Просмотреть файл
@@ -1,4 +1,4 @@
# Copyright (c) 2016 - 2021 Advanced Micro Devices, Inc. All Rights Reserved.
# Copyright (c) 2023 Advanced Micro Devices, Inc. All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@@ -17,31 +17,31 @@
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
ifeq ($(OS),Windows_NT)
$(error Makefile is not supported on windows platform. Please use cmake instead to build sample.)
endif
ROCM_PATH?= $(wildcard /opt/rocm/)
HIP_PATH?= $(wildcard $(ROCM_PATH)/hip)
ifeq (,$(HIP_PATH))
HIP_PATH=../../..
endif
HIP_PLATFORM=$(shell $(HIP_PATH)/bin/hipconfig --platform)
HIPCC=$(HIP_PATH)/bin/hipcc
ifeq (${HIP_PLATFORM}, nvidia)
SOURCES=square.cu
else
SOURCES=square.cpp
endif
set(TEST_SRC
hipPerfMemcpy.cc
hipPerfBufferCopyRectSpeed.cc
hipPerfBufferCopySpeed.cc
hipPerfDevMemReadSpeed.cc
hipPerfDevMemWriteSpeed.cc
hipPerfMemFill.cc
hipPerfMemMallocCpyFree.cc
hipPerfMemset.cc
hipPerfSampleRate.cc
hipPerfSharedMemReadSpeed.cc
)
all: square.out
if(HIP_PLATFORM MATCHES "amd")
set(TEST_SRC
${TEST_SRC}
hipPerfHostNumaAlloc.cc)
# Step
square.cpp: square.cu
$(HIP_PATH)/bin/hipify-perl square.cu > square.cpp
square.out: $(SOURCES)
$(HIPCC) $(CXXFLAGS) $(SOURCES) -o $@
clean:
rm -f *.o *.out square.cpp
hip_add_exe_to_target(NAME perfMemoryTest
TEST_SRC ${TEST_SRC}
TEST_TARGET_NAME perf_test
LINKER_LIBS numa)
else()
hip_add_exe_to_target(NAME perfMemoryTest
TEST_SRC ${TEST_SRC}
TEST_TARGET_NAME perf_test)
endif()
+242
Просмотреть файл
@@ -0,0 +1,242 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/**
* @addtogroup hipMemcpy2DAsync hipMemcpy2DAsync
* @{
* @ingroup perfMemoryTest
* `hipMemcpy2DAsync(void* dst, size_t dpitch, const void* src, size_t spitch,
* size_t width, size_t height, hipMemcpyKind kind, hipStream_t stream = 0)` -
* Copies data between host and device.
*/
#include <hip_test_common.hh>
#define NUM_SIZES 8
// 4KB, 8KB, 64KB, 256KB, 1 MB, 4MB, 16 MB, 16MB+10
static const unsigned int Sizes[NUM_SIZES] =
{4096, 8192, 65536, 262144, 1048576, 4194304, 16777216, 16777216+10};
static const unsigned int Iterations[2] = {1, 1000};
#define BUF_TYPES 4
// 16 ways to combine 4 different buffer types
#define NUM_SUBTESTS (BUF_TYPES*BUF_TYPES)
static void setData(void *ptr, unsigned int size, char value) {
char *ptr2 = reinterpret_cast<char *>(ptr);
for (unsigned int i = 0; i < size ; i++) {
ptr2[i] = value;
}
}
static bool hipPerfBufferCopyRectSpeed_test(int p_tests) {
unsigned int bufSize_;
unsigned int numIter;
bool hostMalloc[2] = {false};
bool hostRegister[2] = {false};
bool unpinnedMalloc[2] = {false};
void *memptr[2] = {NULL};
void *alignedmemptr[2] = {NULL};
void *srcBuffer = NULL;
void *dstBuffer = NULL;
int numTests = (p_tests == -1) ? (NUM_SIZES*NUM_SUBTESTS*2 - 1) : p_tests;
int test = (p_tests == -1) ? 0 : p_tests;
for ( ; test <= numTests ; test++ ) {
unsigned int srcTest = (test / NUM_SIZES) % BUF_TYPES;
unsigned int dstTest = (test / (NUM_SIZES*BUF_TYPES)) % BUF_TYPES;
bufSize_ = Sizes[test % NUM_SIZES];
hostMalloc[0] = hostMalloc[1] = false;
hostRegister[0] = hostRegister[1] = false;
unpinnedMalloc[0] = unpinnedMalloc[1] = false;
srcBuffer = dstBuffer = 0;
memptr[0] = memptr[1] = 0;
alignedmemptr[0] = alignedmemptr[1] = NULL;
size_t width = static_cast<size_t>(sqrt(static_cast<float>(bufSize_)));
if (srcTest == 3) {
hostRegister[0] = true;
} else if (srcTest == 2) {
hostMalloc[0] = true;
} else if (srcTest == 1) {
unpinnedMalloc[0] = true;
}
if (dstTest == 1) {
unpinnedMalloc[1] = true;
} else if (dstTest == 2) {
hostMalloc[1] = true;
} else if (dstTest == 3) {
hostRegister[1] = true;
}
numIter = Iterations[test / (NUM_SIZES * NUM_SUBTESTS)];
if (hostMalloc[0]) {
HIP_CHECK(hipHostMalloc(reinterpret_cast<void**>(&srcBuffer),
bufSize_, 0));
setData(srcBuffer, bufSize_, 0xd0);
} else if (hostRegister[0]) {
memptr[0] = malloc(bufSize_ + 4096);
alignedmemptr[0] = reinterpret_cast<void*>(memptr[0]);
srcBuffer = alignedmemptr[0];
setData(srcBuffer, bufSize_, 0xd0);
HIP_CHECK(hipHostRegister(srcBuffer, bufSize_, 0));
} else if (unpinnedMalloc[0]) {
memptr[0] = malloc(bufSize_ + 4096);
alignedmemptr[0] = reinterpret_cast<void*>(memptr[0]);
srcBuffer = alignedmemptr[0];
setData(srcBuffer, bufSize_, 0xd0);
} else {
HIP_CHECK(hipMalloc(&srcBuffer, bufSize_));
HIP_CHECK(hipMemset(srcBuffer, 0xd0, bufSize_));
}
if (hostMalloc[1]) {
HIP_CHECK(hipHostMalloc(reinterpret_cast<void**>(&dstBuffer),
bufSize_, 0));
} else if (hostRegister[1]) {
memptr[1] = malloc(bufSize_ + 4096);
alignedmemptr[1] = reinterpret_cast<void*>(memptr[0]);
dstBuffer = alignedmemptr[1];
HIP_CHECK(hipHostRegister(dstBuffer, bufSize_, 0));
} else if (unpinnedMalloc[1]) {
memptr[1] = malloc(bufSize_ + 4096);
alignedmemptr[1] = reinterpret_cast<void*>(memptr[0]);
dstBuffer = alignedmemptr[1];
} else {
HIP_CHECK(hipMalloc(&dstBuffer, bufSize_));
}
// warm up
HIP_CHECK(hipMemcpy2D(dstBuffer, width, srcBuffer,
width, width, width, hipMemcpyDefault));
// measure performance based on host time
auto all_start = std::chrono::steady_clock::now();
for (unsigned int i = 0; i < numIter; i++) {
HIP_CHECK(hipMemcpy2DAsync(dstBuffer, width, srcBuffer,
width, width, width, hipMemcpyDefault, NULL));
}
HIP_CHECK(hipDeviceSynchronize());
auto all_end = std::chrono::steady_clock::now();
std::chrono::duration<double> elapsed_secs = all_end - all_start;
// read speed in GB/s
double perf = (static_cast<double>(bufSize_ * numIter) *
static_cast<double>(1e-09)) / elapsed_secs.count();
const char *strSrc = NULL;
const char *strDst = NULL;
if (hostMalloc[0])
strSrc = "hHM";
else if (hostRegister[0])
strSrc = "hHR";
else if (unpinnedMalloc[0])
strSrc = "unp";
else
strSrc = "hM";
if (hostMalloc[1])
strDst = "hHM";
else if (hostRegister[1])
strDst = "hHR";
else if (unpinnedMalloc[1])
strDst = "unp";
else
strDst = "hM";
// Double results when src and dst are both on device
if ((!hostMalloc[0] && !hostRegister[0] && !unpinnedMalloc[0]) &&
(!hostMalloc[1] && !hostRegister[1] && !unpinnedMalloc[1]))
perf *= 2.0;
// Double results when src and dst are both in sysmem
if ((hostMalloc[0] || hostRegister[0] || unpinnedMalloc[0]) &&
(hostMalloc[1] || hostRegister[1] || unpinnedMalloc[1]))
perf *= 2.0;
INFO("hipPerfBufferCopyRectSpeed[" << test << "]\t( " << bufSize_ <<
")\ts:" << strSrc << " d:" << strDst << "\ti:" << numIter <<
"\t(GB/s) perf\t" << (float)perf);
// Free src
if (hostMalloc[0]) {
HIP_CHECK(hipHostFree(srcBuffer));
} else if (hostRegister[0]) {
HIP_CHECK(hipHostUnregister(srcBuffer));
free(memptr[0]);
} else if (unpinnedMalloc[0]) {
free(memptr[0]);
} else {
HIP_CHECK(hipFree(srcBuffer));
}
// Free dst
if (hostMalloc[1]) {
HIP_CHECK(hipHostFree(dstBuffer));
} else if (hostRegister[1]) {
HIP_CHECK(hipHostUnregister(dstBuffer));
free(memptr[1]);
} else if (unpinnedMalloc[1]) {
free(memptr[1]);
} else {
HIP_CHECK(hipFree(dstBuffer));
}
}
return true;
}
/**
* Test Description
* ------------------------
*  - Verify hipPerfBufferCopy status.
* Test source
* ------------------------
*  - perftests/memory/hipPerfBufferCopyRectSpeed.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
TEST_CASE("Perf_hipPerfBufferCopyRectSpeed_test") {
int numDevices = 0;
HIP_CHECK(hipGetDeviceCount(&numDevices));
if (numDevices <= 0) {
SUCCEED("Skipped testcase hipPerfBufferCopyRectSpeed"
"as there is no device to test.");
} else {
int deviceId = 0;
HIP_CHECK(hipSetDevice(deviceId));
hipDeviceProp_t props = {0};
HIP_CHECK(hipGetDeviceProperties(&props, deviceId));
INFO("hipPerfBufferCopyRectSpeed - info: Set device to " << deviceId
<< " : " << props.name << "Legend: unp - unpinned(malloc),"
" hM - hipMalloc(device)\n hHR - hipHostRegister(pinned),"
" hHM - hipHostMalloc(prePinned)\n");
REQUIRE(true == hipPerfBufferCopyRectSpeed_test(1));
}
}
+258
Просмотреть файл
@@ -0,0 +1,258 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/**
* @addtogroup hipMemcpyAsync hipMemcpyAsync
* @{
* @ingroup perfMemoryTest
* `hipMemcpyAsync(void* dst, const void* src, size_t count,
* hipMemcpyKind kind, hipStream_t stream = 0)` -
* Copies data between host and device.
*/
#include <hip_test_common.hh>
#define NUM_SIZES 9
// 4KB, 8KB, 64KB, 256KB, 1 MB, 4MB, 16 MB, 16MB+10
static const unsigned int Sizes[NUM_SIZES] =
{4096, 8192, 65536, 262144, 524288, 1048576, 4194304, 16777216, 16777216+10};
static const unsigned int Iterations[2] = {1, 1000};
#define BUF_TYPES 4
// 16 ways to combine 4 different buffer types
#define NUM_SUBTESTS (BUF_TYPES*BUF_TYPES)
static void setData(void *ptr, unsigned int size, char value) {
char *ptr2 = reinterpret_cast<char *>(ptr);
for (unsigned int i = 0; i < size ; i++) {
ptr2[i] = value;
}
}
static void checkData(void *ptr, unsigned int size, char value) {
char *ptr2 = reinterpret_cast<char *>(ptr);
for (unsigned int i = 0; i < size; i++) {
if (ptr2[i] != value) {
INFO("Validation failed at " << i << " Got " << ptr2[i] <<
" Expected " << value);
REQUIRE(false);
}
}
}
static bool hipPerfBufferCopySpeed_test(int p_tests) {
unsigned int bufSize_;
unsigned int numIter;
bool hostMalloc[2] = {false};
bool hostRegister[2] = {false};
bool unpinnedMalloc[2] = {false};
void *memptr[2] = {NULL};
void *alignedmemptr[2] = {NULL};
void *srcBuffer = NULL;
void *dstBuffer = NULL;
int numTests = (p_tests == -1) ? (NUM_SIZES*NUM_SUBTESTS*2 - 1) : p_tests;
int test = (p_tests == -1) ? 0 : p_tests;
for ( ; test <= numTests; test++ ) {
unsigned int srcTest = (test / NUM_SIZES) % BUF_TYPES;
unsigned int dstTest = (test / (NUM_SIZES*BUF_TYPES)) % BUF_TYPES;
bufSize_ = Sizes[test % NUM_SIZES];
hostMalloc[0] = hostMalloc[1] = false;
hostRegister[0] = hostRegister[1] = false;
unpinnedMalloc[0] = unpinnedMalloc[1] = false;
srcBuffer = dstBuffer = 0;
memptr[0] = memptr[1] = NULL;
alignedmemptr[0] = alignedmemptr[1] = NULL;
if (srcTest == 3) {
hostRegister[0] = true;
} else if (srcTest == 2) {
hostMalloc[0] = true;
} else if (srcTest == 1) {
unpinnedMalloc[0] = true;
}
if (dstTest == 1) {
unpinnedMalloc[1] = true;
} else if (dstTest == 2) {
hostMalloc[1] = true;
} else if (dstTest == 3) {
hostRegister[1] = true;
}
numIter = Iterations[test / (NUM_SIZES * NUM_SUBTESTS)];
if (hostMalloc[0]) {
HIP_CHECK(hipHostMalloc(reinterpret_cast<void**>(&srcBuffer),
bufSize_, 0));
setData(srcBuffer, bufSize_, 0xd0);
} else if (hostRegister[0]) {
memptr[0] = malloc(bufSize_ + 4096);
alignedmemptr[0] = reinterpret_cast<void*>(memptr[0]);
srcBuffer = alignedmemptr[0];
setData(srcBuffer, bufSize_, 0xd0);
HIP_CHECK(hipHostRegister(srcBuffer, bufSize_, 0));
} else if (unpinnedMalloc[0]) {
memptr[0] = malloc(bufSize_ + 4096);
alignedmemptr[0] = reinterpret_cast<void*>(memptr[0]);
srcBuffer = alignedmemptr[0];
setData(srcBuffer, bufSize_, 0xd0);
} else {
HIP_CHECK(hipMalloc(&srcBuffer, bufSize_));
HIP_CHECK(hipMemset(srcBuffer, 0xd0, bufSize_));
}
if (hostMalloc[1]) {
HIP_CHECK(hipHostMalloc(reinterpret_cast<void**>(&dstBuffer),
bufSize_, 0));
} else if (hostRegister[1]) {
memptr[1] = malloc(bufSize_ + 4096);
alignedmemptr[1] = reinterpret_cast<void*>(memptr[1]);
dstBuffer = alignedmemptr[1];
HIP_CHECK(hipHostRegister(dstBuffer, bufSize_, 0));
} else if (unpinnedMalloc[1]) {
memptr[1] = malloc(bufSize_ + 4096);
alignedmemptr[1] = reinterpret_cast<void*>(memptr[1]);
dstBuffer = alignedmemptr[1];
} else {
HIP_CHECK(hipMalloc(&dstBuffer, bufSize_));
}
// warm up
HIP_CHECK(hipMemcpy(dstBuffer, srcBuffer, bufSize_, hipMemcpyDefault));
// measure performance based on host time
auto all_start = std::chrono::steady_clock::now();
for (unsigned int i = 0; i < numIter; i++) {
HIP_CHECK(hipMemcpyAsync(dstBuffer, srcBuffer, bufSize_,
hipMemcpyDefault, NULL));
}
HIP_CHECK(hipDeviceSynchronize());
auto all_end = std::chrono::steady_clock::now();
std::chrono::duration<double> elapsed_secs = all_end - all_start;
// read speed in GB/s
double perf = (static_cast<double>(bufSize_ * numIter) *
static_cast<double>(1e-09)) / elapsed_secs.count();
const char *strSrc = NULL;
const char *strDst = NULL;
if (hostMalloc[0])
strSrc = "hHM";
else if (hostRegister[0])
strSrc = "hHR";
else if (unpinnedMalloc[0])
strSrc = "unp";
else
strSrc = "hM";
if (hostMalloc[1])
strDst = "hHM";
else if (hostRegister[1])
strDst = "hHR";
else if (unpinnedMalloc[1])
strDst = "unp";
else
strDst = "hM";
// Double results when src and dst are both on device
if ((!hostMalloc[0] && !hostRegister[0] && !unpinnedMalloc[0]) &&
(!hostMalloc[1] && !hostRegister[1] && !unpinnedMalloc[1]))
perf *= 2.0;
// Double results when src and dst are both in sysmem
if ((hostMalloc[0] || hostRegister[0] || unpinnedMalloc[0]) &&
(hostMalloc[1] || hostRegister[1] || unpinnedMalloc[1]))
perf *= 2.0;
INFO("HIPPerfBufferCopySpeed[" << test << "]\t( " << bufSize_ <<
")\ts:" << strSrc << " d:" << strDst << "\ti:" << numIter <<
"\t(GB/s) perf\t" << (float)perf);
// Verification
void* temp = malloc(bufSize_ + 4096);
void* chkBuf = reinterpret_cast<void*>(temp);
HIP_CHECK(hipMemcpy(chkBuf, dstBuffer, bufSize_, hipMemcpyDefault));
checkData(chkBuf, bufSize_, 0xd0);
free(temp);
// Free src
if (hostMalloc[0]) {
HIP_CHECK(hipHostFree(srcBuffer));
} else if (hostRegister[0]) {
HIP_CHECK(hipHostUnregister(srcBuffer));
free(memptr[0]);
} else if (unpinnedMalloc[0]) {
free(memptr[0]);
} else {
HIP_CHECK(hipFree(srcBuffer));
}
// Free dst
if (hostMalloc[1]) {
HIP_CHECK(hipHostFree(dstBuffer));
} else if (hostRegister[1]) {
HIP_CHECK(hipHostUnregister(dstBuffer));
free(memptr[1]);
} else if (unpinnedMalloc[1]) {
free(memptr[1]);
} else {
HIP_CHECK(hipFree(dstBuffer));
}
}
return true;
}
/**
* Test Description
* ------------------------
*  - Verify hipPerfBufferCopySpeed status.
* Test source
* ------------------------
*  - perftests/memory/hipPerfBufferCopySpeed.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
TEST_CASE("Perf_hipPerfBufferCopySpeed_test") {
int numDevices = 0;
HIP_CHECK(hipGetDeviceCount(&numDevices));
if (numDevices <= 0) {
SUCCEED("Skipped testcase hipPerfBufferCopySpeed as"
"there is no device to test.");
} else {
int deviceId = 0;
HIP_CHECK(hipSetDevice(deviceId));
hipDeviceProp_t props = {0};
HIP_CHECK(hipGetDeviceProperties(&props, deviceId));
INFO("hipPerfBufferCopySpeed - info: Set device to " << deviceId
<< " : " << props.name << "Legend: unp - unpinned(malloc),"
" hM - hipMalloc(device)\n hHR - hipHostRegister(pinned),"
" hHM - hipHostMalloc(prePinned)\n");
REQUIRE(true == hipPerfBufferCopySpeed_test(1));
}
}
+154
Просмотреть файл
@@ -0,0 +1,154 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/**
* @addtogroup hipMemcpyKernel hipMemcpyKernel
* @{
* @ingroup perfMemoryTest
* `hipMemcpy(void* dst, const void* src, size_t count, hipMemcpyKind kind)` -
* Copies data between host and device.
*/
#include <hip_test_common.hh>
#define ARRAY_SIZE 16
typedef struct d_uint16 {
uint data[ARRAY_SIZE];
} d_uint16;
__global__ static void read_kernel(d_uint16 *src, ulong N, uint *dst) {
size_t idx = (blockIdx.x * blockDim.x + threadIdx.x);
size_t stride = blockDim.x * gridDim.x;
uint tmp = 0;
for (size_t i = idx; i < N; i += stride) {
for (size_t j = 0; j < ARRAY_SIZE; j++) {
tmp += src[i].data[j];
}
}
atomicAdd(dst, tmp);
}
static bool hipPerfDevMemReadSpeed_test() {
d_uint16 *dSrc, *hSrc;
uint *dDst, *hDst;
hipStream_t stream;
ulong N = 4 * 1024 * 1024;
uint nBytes = N * sizeof(d_uint16);
int deviceId = 0;
HIP_CHECK(hipSetDevice(deviceId));
hipDeviceProp_t props = {0};
HIP_CHECK(hipGetDeviceProperties(&props, deviceId));
INFO("info: running on bus " << "0x" << props.pciBusID << " " <<
props.name << " with " << props.multiProcessorCount << " CUs \n");
const unsigned threadsPerBlock = 64;
const unsigned blocks = props.multiProcessorCount * 4;
uint inputData = 0x1;
int nIter = 1000;
hSrc = new d_uint16[nBytes];
REQUIRE(hSrc != nullptr);
hDst = new uint;
REQUIRE(hDst != nullptr);
hDst[0] = 0;
for (size_t i = 0; i < N; i++) {
for (int j = 0; j < ARRAY_SIZE; j++) {
hSrc[i].data[j] = inputData;
}
}
HIP_CHECK(hipMalloc(&dSrc, nBytes));
HIP_CHECK(hipMalloc(&dDst, sizeof(uint)));
HIP_CHECK(hipStreamCreate(&stream));
HIP_CHECK(hipMemcpy(dSrc, hSrc, nBytes, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(dDst, hDst, sizeof(uint), hipMemcpyHostToDevice));
hipLaunchKernelGGL(read_kernel, dim3(blocks), dim3(threadsPerBlock),
0, stream, dSrc, N, dDst);
HIP_CHECK(hipGetLastError());
HIP_CHECK(hipMemcpy(hDst, dDst, sizeof(uint), hipMemcpyDeviceToHost));
HIP_CHECK(hipDeviceSynchronize());
if (hDst[0] != (nBytes / sizeof(uint))) {
INFO("hipPerfDevMemReadSpeed - Data validation failed for warm up run!" <<
" expected " << nBytes / sizeof(uint) << " got " << hDst[0]);
return false;
}
// measure performance based on host time
auto all_start = std::chrono::steady_clock::now();
for (int i = 0; i < nIter; i++) {
hipLaunchKernelGGL(read_kernel, dim3(blocks), dim3(threadsPerBlock),
0, stream, dSrc, N, dDst);
HIP_CHECK(hipGetLastError());
}
HIP_CHECK(hipDeviceSynchronize());
auto all_end = std::chrono::steady_clock::now();
std::chrono::duration<double> all_kernel_time = all_end - all_start;
// read speed in GB/s
double perf = (static_cast<double>(nBytes * nIter * (1e-09))) /
all_kernel_time.count();
INFO("hipPerfDevMemReadSpeed - info: average read speed of " <<
perf << " GB/s " << "achieved for memory size of " <<
nBytes / (1024 * 1024) << " MB");
delete [] hSrc;
delete hDst;
HIP_CHECK(hipFree(dSrc));
HIP_CHECK(hipFree(dDst));
HIP_CHECK(hipStreamDestroy(stream));
return true;
}
/**
* Test Description
* ------------------------
*  - Verify hipPerfDevMemReadSpeed status.
* Test source
* ------------------------
*  - perftests/memory/hipPerfDevMemReadSpeed.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
TEST_CASE("Perf_hipPerfDevMemReadSpeed_test") {
int numDevices = 0;
HIP_CHECK(hipGetDeviceCount(&numDevices));
if (numDevices <= 0) {
SUCCEED("Skipped testcase hipPerfDevMemReadSpeed as"
"there is no device to test.");
} else {
REQUIRE(true == hipPerfDevMemReadSpeed_test());
}
}
+147
Просмотреть файл
@@ -0,0 +1,147 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/**
* @addtogroup hipMemcpyKernel hipMemcpyKernel
* @{
* @ingroup perfMemoryTest
* `hipMemcpy(void* dst, const void* src, size_t count, hipMemcpyKind kind)` -
* Copies data between host and device.
*/
#include <hip_test_common.hh>
#define ARRAY_SIZE 16
typedef struct d_uint16 {
uint data[ARRAY_SIZE];
} d_uint16;
__global__ void write_kernel(d_uint16 *dst, ulong N, d_uint16 pval) {
size_t idx = (blockIdx.x * blockDim.x + threadIdx.x);
size_t stride = blockDim.x * gridDim.x;
for (size_t i = idx; i < N; i += stride) {
dst[i] = pval;
}
}
static bool hipPerfDevMemWriteSpeed_test() {
d_uint16 *dDst, *hDst;
ulong N = 4 * 1024 * 1024;
uint nBytes = N * sizeof(d_uint16);
uint inputData = 0xabababab;
int nIter = 1000;
d_uint16 pval;
int deviceId = 0;
HIP_CHECK(hipSetDevice(deviceId));
hipDeviceProp_t props = {0};
HIP_CHECK(hipGetDeviceProperties(&props, deviceId));
INFO("info: running on bus " << "0x" << props.pciBusID << " " <<
props.name << " with " << props.multiProcessorCount << " CUs \n");
const unsigned threadsPerBlock = 64;
const unsigned blocks = props.multiProcessorCount * 4;
for (int i = 0; i < ARRAY_SIZE; i++) {
pval.data[i] = inputData;
}
hDst = new d_uint16[nBytes];
REQUIRE(hDst != nullptr);
for (size_t i = 0; i < N; i++) {
for (size_t j = 0; j < ARRAY_SIZE; j++) {
hDst[i].data[j] = 0;
}
}
hipStream_t stream;
HIP_CHECK(hipStreamCreate(&stream));
HIP_CHECK(hipMalloc(&dDst, nBytes));
hipLaunchKernelGGL(write_kernel, dim3(blocks), dim3(threadsPerBlock),
0, stream, dDst, N, pval);
HIP_CHECK(hipGetLastError());
HIP_CHECK(hipMemcpy(hDst, dDst, nBytes , hipMemcpyDeviceToHost));
HIP_CHECK(hipDeviceSynchronize());
for (uint i = 0; i < N; i++) {
for (uint j = 0; j < ARRAY_SIZE; j++) {
if (hDst[i].data[j] != inputData) {
INFO("hipPerfDevMemWriteSpeed - Data validation failed for warm up run!"
<< "at index i: " << i << " element j: " << j <<
"expected " << inputData << " but got " << hDst[i].data[j]);
return false;
}
}
}
// measure performance based on host time
auto all_start = std::chrono::steady_clock::now();
for (int i = 0; i < nIter; i++) {
hipLaunchKernelGGL(write_kernel, dim3(blocks), dim3(threadsPerBlock),
0, stream, dDst, N, pval);
HIP_CHECK(hipGetLastError());
}
HIP_CHECK(hipDeviceSynchronize());
auto all_end = std::chrono::steady_clock::now();
std::chrono::duration<double> all_kernel_time = all_end - all_start;
// read speed in GB/s
double perf = (static_cast<double>(nBytes * nIter * (1e-09))) /
all_kernel_time.count();
INFO("hipPerfDevMemReadSpeed - info: average write speed of " <<
perf << " GB/s " << "achieved for memory size of " <<
nBytes / (1024 * 1024) << " MB");
delete [] hDst;
HIP_CHECK(hipFree(dDst));
HIP_CHECK(hipStreamDestroy(stream));
return true;
}
/**
* Test Description
* ------------------------
*  - Verify hipPerfDevMemWriteSpeed status.
* Test source
* ------------------------
*  - perftests/memory/hipPerfDevMemWriteSpeed.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
TEST_CASE("Perf_hipPerfDevMemWriteSpeed_test") {
int numDevices = 0;
HIP_CHECK(hipGetDeviceCount(&numDevices));
if (numDevices <= 0) {
SUCCEED("Skipped testcase hipPerfDevMemWriteSpeed as"
"there is no device to test.");
} else {
REQUIRE(true == hipPerfDevMemWriteSpeed_test());
}
}
+191
Просмотреть файл
@@ -0,0 +1,191 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/**
* @addtogroup hipMemcpyKernel hipMemcpyKernel
* @{
* @ingroup perfMemoryTest
* `hipMemcpy(void* dst, const void* src, size_t count, hipMemcpyKind kind)` -
* Copies data between host and device.
*/
#include <numaif.h>
#include <hip_test_common.hh>
// To run it correctly, we must not export HIP_VISIBLE_DEVICES.
// And we must explicitly link libnuma because of numa api move_pages().
#define NUM_PAGES 4
char *h = nullptr;
char *d_h = nullptr;
char *m = nullptr;
char *d_m = nullptr;
int page_size = 1024;
const int mode[] = { MPOL_DEFAULT, MPOL_BIND, MPOL_PREFERRED, MPOL_INTERLEAVE };
const char* modeStr[] = { "MPOL_DEFAULT", "MPOL_BIND",
"MPOL_PREFERRED", "MPOL_INTERLEAVE" };
std::string exeCommand(const char* cmd) {
std::array<char, 128> buff;
std::string result;
std::unique_ptr<FILE, decltype(&pclose)> pipe(popen(cmd, "r"), pclose);
if (!pipe) {
return result;
}
while (fgets(buff.data(), buff.size(), pipe.get()) != nullptr) {
result += buff.data();
}
return result;
}
int getCpuAgentCount() {
const char* cmd =
"cat /proc/cpuinfo | grep \"physical id\" | sort | uniq | wc -l";
int cpuAgentCount = std::atoi(exeCommand(cmd).c_str());
return cpuAgentCount;
}
bool test(int cpuId, int gpuId, int numaMode, unsigned int hostMallocflags) {
void *pages[NUM_PAGES];
int status[NUM_PAGES];
int nodes[NUM_PAGES];
int ret_code;
INFO("set cpu " << cpuId << ", gpu " << gpuId << ", numaMode "
<< numaMode << ", hostMallocflags " << hostMallocflags << "\n");
if (cpuId >= 0) {
unsigned long nodeMask = 1 << cpuId; //NOLINT
unsigned long maxNode = sizeof(nodeMask) * 8; //NOLINT
if (set_mempolicy(numaMode, numaMode == MPOL_DEFAULT ? NULL : &nodeMask,
numaMode == MPOL_DEFAULT ? 0 : maxNode) == -1) {
WARN("set_mempolicy() failed with err " << errno << "\n");
return false;
}
}
if (gpuId >= 0) {
HIP_CHECK(hipSetDevice(gpuId));
}
posix_memalign(reinterpret_cast<void**>(&m), page_size, page_size*NUM_PAGES);
HIP_CHECK(hipHostRegister(m, page_size * NUM_PAGES, hipHostRegisterMapped));
HIP_CHECK(hipHostGetDevicePointer(reinterpret_cast<void**>(&d_m), m, 0));
status[0] = -1;
pages[0] = m;
for (int i = 1; i < NUM_PAGES; i++) {
pages[i] = reinterpret_cast<char*>(pages[0]) + page_size;
}
ret_code = move_pages(0, NUM_PAGES, pages, NULL, status, 0);
INFO("Memory (malloc) ret " << ret_code << " at " << m <<
" (dev " << d_m << "%p) is at node: ");
for (int i = 0; i < NUM_PAGES; i++) {
INFO(status[i]); // Don't verify as it's out of our control
}
INFO("\n");
HIP_CHECK(hipHostMalloc(reinterpret_cast<void**>(&h),
page_size*NUM_PAGES, hostMallocflags));
pages[0] = h;
for (int i = 1; i < NUM_PAGES; i++) {
pages[i] = reinterpret_cast<char*>(pages[0]) + page_size;
}
ret_code = move_pages(0, NUM_PAGES, pages, NULL, status, 0);
d_h = nullptr;
if (hostMallocflags & hipHostMallocMapped) {
HIP_CHECK(hipHostGetDevicePointer(reinterpret_cast<void**>(&d_h), h, 0));
INFO("Memory (hipHostMalloc) ret " << ret_code << " at " << h
<< " (dev " << d_h << ") is at node: ");
} else {
INFO("Memory (hipHostMalloc) ret " << ret_code << " at "
<< h << " is at node: ");
}
for (int i = 0; i < NUM_PAGES; i++) {
INFO(status[i]); // Always print it even if it's wrong. Verify later
}
INFO("\n");
HIP_CHECK(hipHostFree(reinterpret_cast<void*>(h)));
HIP_CHECK(hipHostUnregister(m));
free(m);
if (cpuId >= 0 && (numaMode == MPOL_BIND || numaMode == MPOL_PREFERRED)) {
for (int i = 0; i < NUM_PAGES; i++) {
if (status[i] != cpuId) { // Now verify
WARN("Failed at " << i << " status[i] = " << status[i]
<< " cpuId " << cpuId << "\n");
return false;
}
}
}
return true;
}
bool runTest(const int &cpuCount, const int &gpuCount,
unsigned int hostMallocflags, const std::string &str) {
INFO("Test- " << str.c_str() << "\n");
for (int m = 0; m < sizeof(mode) / sizeof(mode[0]); m++) {
INFO("Testing " << modeStr[m] << "\n");
for (int i = 0; i < cpuCount; i++) {
for (int j = 0; j < gpuCount; j++) {
if (!test(i, j, mode[m], hostMallocflags)) {
return false;
}
}
}
}
return true;
}
/**
* Test Description
* ------------------------
*  - Verify hipPerfHostNumaAlloc status.
* Test source
* ------------------------
*  - perftests/memory/hipPerfHostNumaAlloc.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
TEST_CASE("Perf_hipPerfHostNumaAlloc_test") {
int gpuCount = 0;
HIP_CHECK(hipGetDeviceCount(&gpuCount));
int cpuCount = getCpuAgentCount();
INFO("Cpu count " << cpuCount << ", Gpu count " << gpuCount << "\n");
if (cpuCount < 0 || gpuCount < 0) {
SUCCEED("Skipped testcase hipPerfHostNumaAlloc as "
"there is no device to test.\n");
return;
}
REQUIRE(true == runTest(cpuCount, gpuCount,
hipHostMallocDefault | hipHostMallocNumaUser,
"Testing hipHostMallocDefault | hipHostMallocNumaUser......"));
REQUIRE(true == runTest(cpuCount, gpuCount,
hipHostMallocMapped | hipHostMallocNumaUser,
"Testing hipHostMallocMapped | hipHostMallocNumaUser......."));
}
+545
Просмотреть файл
@@ -0,0 +1,545 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/**
* @addtogroup hipMemcpyKernel hipMemcpyKernel
* @{
* @ingroup perfMemoryTest
* `hipMemcpy(void* dst, const void* src, size_t count, hipMemcpyKind kind)` -
* Copies data between host and device.
*/
#include <hip_test_common.hh>
#define SIMPLY_ASSIGN 0
#define USE_HIPTEST_SETNUMBLOCKS 0
template<class T>
__global__ void vec_fill(T *x, T coef, int N) {
const int istart = threadIdx.x + blockIdx.x * blockDim.x;
const int ishift = blockDim.x * gridDim.x;
for (int i = istart; i < N; i += ishift) {
#if SIMPLY_ASSIGN
x[i] = coef;
#else
x[i] = coef * i;
#endif
}
}
__device__ void print_log(int i, double value, double expected) {
printf("failed at %d: val=%g, expected=%g\n", i, value, expected);
}
__device__ void print_log(int i, int value, int expected) {
printf("failed at %d: val=%d, expected=%d\n", i, value, expected);
}
template<class T>
__global__ void vec_verify(T *x, T coef, int N) {
const int istart = threadIdx.x + blockIdx.x * blockDim.x;
const int ishift = blockDim.x * gridDim.x;
for (int i = istart; i < N; i += ishift) {
#if SIMPLY_ASSIGN
if (x[i] != coef) {
print_log(i, x[i], coef);
}
#else
if (x[i] != coef * i) {
print_log(i, x[i], coef * i);
}
#endif
}
}
template<class T>
__global__ void daxpy(T *__restrict__ x, T *__restrict__ y,
const T coef, int Niter, int N) {
const int istart = threadIdx.x + blockIdx.x * blockDim.x;
const int ishift = blockDim.x * gridDim.x;
for (int iter = 0; iter < Niter; ++iter) {
T iv = coef * iter;
for (int i = istart; i < N; i += ishift)
y[i] = iv * x[i] + y[i];
}
}
template<class T>
class hipPerfMemFill {
private:
static constexpr int NUM_START = 27;
static constexpr int NUM_SIZE = 5;
static constexpr int NUM_ITER = 10;
static constexpr double NUM_1GB = 1024.0 * 1024.0 * 1024.0;
size_t totalSizes_[NUM_SIZE];
hipDeviceProp_t props_;
const T coef_ = getCoefficient(3.14159);
const unsigned int threadsPerBlock_ = 64;
unsigned int blocksPerCU_;
public:
hipPerfMemFill() {
for (int i = 0; i < NUM_SIZE; i++) {
// 128M, 256M, 512M, 1024M, 2048M
totalSizes_[i] = 1ull << (i + NUM_START);
}
}
~hipPerfMemFill() { }
bool supportLargeBar() {
return props_.isLargeBar != 0;
}
bool supportManagedMemory() {
return props_.managedMemory != 0;
}
const T getCoefficient(double val) {
return static_cast<T>(val);
}
void setHostBuffer(T *A, T val, size_t size) {
size_t len = size / sizeof(T);
for (int i = 0; i < len; i++) {
A[i] = val;
}
}
bool open(int deviceId) {
int nGpu = 0;
HIP_CHECK(hipGetDeviceCount(&nGpu));
if (nGpu < 1) {
printf("No GPU!");
return false;
} else if (deviceId >= nGpu) {
printf("Info: wrong GPU Id %d\n", deviceId);
return false;
}
HIP_CHECK(hipSetDevice(deviceId));
memset(&props_, 0, sizeof(props_));
HIP_CHECK(hipGetDeviceProperties(&props_, deviceId));
blocksPerCU_ = props_.multiProcessorCount * 4;
std::cout << "Info: running on device: id: " << deviceId << ", bus: 0x"
<< props_.pciBusID << " " << props_.name << " with "
<< props_.multiProcessorCount << " CUs, large bar: "
<< supportLargeBar() << ", managed memory: " << supportManagedMemory()
<< ", DeviceMallocFinegrained: " << supportDeviceMallocFinegrained()
<< std::endl;
return true;
}
void log_host(const char* title, double GBytes, double sec) {
std::cout << title << " [" << std::setw(7) << GBytes << " GB]: cost "
<< std::setw(10) << sec << " s in bandwidth " << std::setw(10)
<< GBytes / sec << " [GB/s]" << std::endl;
}
void log_kernel(const char* title, double GBytes, double sec,
double sec_hv, double sec_kv) {
std::cout << title << " [" << std::setw(7) << GBytes << " GB]: cost "
<< std::setw(10) << sec << " s in bandwidth " << std::setw(10)
<< GBytes / sec << " [GB/s]" << ", hostVerify cost "
<< std::setw(10) << sec_hv << " s in bandwidth " << std::setw(10)
<< GBytes / sec_hv << " [GB/s]" << ", kernelVerify cost "
<< std::setw(10) << sec_kv << " s in bandwidth " << std::setw(10)
<< GBytes / sec_kv << " [GB/s]" << std::endl;
}
void hostFill(size_t size, T *data, T coef, double *sec) {
size_t num = size / sizeof(T); // Size of elements
auto start = std::chrono::steady_clock::now();
for (int i = 0; i < num; ++i) {
#if SIMPLY_ASSIGN
data[i] = coef;
#else
data[i] = coef * i;
#endif
}
auto end = std::chrono::steady_clock::now();
std::chrono::duration<double> diff = end - start; // in second
*sec = diff.count();
}
void kernelFill(size_t size, T *data, T coef, double *sec) {
size_t num = size / sizeof(T); // Size of elements
unsigned blocks = setNumBlocks(num);
// kernel will be loaded first time
hipLaunchKernelGGL(HIP_KERNEL_NAME(vec_fill<T>), dim3(blocks),
dim3(threadsPerBlock_), 0, 0, data, 0, num);
HIP_CHECK(hipDeviceSynchronize());
auto start = std::chrono::steady_clock::now();
for (int iter = 0; iter < NUM_ITER; ++iter) {
hipLaunchKernelGGL(HIP_KERNEL_NAME(vec_fill<T>), dim3(blocks),
dim3(threadsPerBlock_), 0, 0, data, coef, num);
}
HIP_CHECK(hipDeviceSynchronize());
auto end = std::chrono::steady_clock::now();
std::chrono::duration<double> diff = end - start; // in second
*sec = diff.count() / NUM_ITER; // in second
}
void hostVerify(size_t size, T *data, T coef, double *sec) {
size_t num = size / sizeof(T); // Size of elements
auto start = std::chrono::steady_clock::now();
for (int i = 0; i < num; ++i) {
#if SIMPLY_ASSIGN
if (data[i] != coef) {
std::cout << "hostVerify failed: i=" << i << ", data[i]=" << data[i]
<< ", expected=" << coef << std::endl;
REQUIRE(false);
}
#else
if (data[i] != coef * i) {
std::cout << "hostVerify failed: i=" << i << ", data[i]=" << data[i]
<< ", expected=" << coef * i << std::endl;
REQUIRE(false);
}
#endif
}
auto end = std::chrono::steady_clock::now();
std::chrono::duration<double> diff = end - start; // in second
*sec = diff.count();
}
void kernelVerify(size_t size, T *data, T coef, double *sec) {
size_t num = size / sizeof(T); // Size of elements
unsigned blocks = setNumBlocks(num);
// kernel will be loaded first time
hipLaunchKernelGGL(HIP_KERNEL_NAME(vec_verify<T>), dim3(blocks),
dim3(threadsPerBlock_), 0, 0, data, coef, num);
HIP_CHECK(hipDeviceSynchronize());
// Now all data verified. The following is to test bandwidth.
auto start = std::chrono::steady_clock::now();
for (int iter = 0; iter < NUM_ITER; ++iter) {
hipLaunchKernelGGL(HIP_KERNEL_NAME(vec_verify<T>), dim3(blocks),
dim3(threadsPerBlock_), 0, 0, data, coef, num);
}
HIP_CHECK(hipDeviceSynchronize());
auto end = std::chrono::steady_clock::now();
std::chrono::duration<double> diff = end - start; // in second
*sec = diff.count() / NUM_ITER; // in second
}
bool testLargeBarDeviceMemoryHostFill(size_t size) {
if (!supportLargeBar()) {
return false;
}
double GBytes = static_cast<double>(size) / NUM_1GB;
T *A;
HIP_CHECK(hipMalloc(&A, size));
double sec = 0;
hostFill(size, A, coef_, &sec); // Cpu can access device mem in LB
HIP_CHECK(hipFree(A));
log_host("Largebar: host fill", GBytes, sec);
return true;
}
bool testLargeBar() {
if (!supportLargeBar()) {
return false;
}
std::cout << "Test large bar device memory host filling" << std::endl;
for (int i = 0; i < NUM_SIZE; i++) {
if (!testLargeBarDeviceMemoryHostFill(totalSizes_[i])) {
return false;
}
}
return true;
}
bool testManagedMemoryHostFill(size_t size) {
if (!supportManagedMemory()) {
return false;
}
double GBytes = static_cast<double>(size) / NUM_1GB;
T *A;
HIP_CHECK(hipMallocManaged(&A, size));
double sec = 0;
hostFill(size, A, coef_, &sec); // Cpu can access HMM mem
HIP_CHECK(hipFree(A));
log_host("Managed: host fill", GBytes, sec);
return true;
}
bool testManagedMemoryKernelFill(size_t size) {
if (!supportManagedMemory()) {
return false;
}
double GBytes = static_cast<double>(size) / NUM_1GB;
T *A;
HIP_CHECK(hipMallocManaged(&A, size));
double sec = 0, sec_hv = 0, sec_kv = 0;
kernelFill(size, A, coef_, &sec);
// Managed memory can be verified by host
hostVerify(size, A, coef_, &sec_hv);
kernelVerify(size, A, coef_, &sec_kv);
HIP_CHECK(hipFree(A));
log_kernel("Managed: kernel fill", GBytes, sec, sec_hv, sec_kv);
return true;
}
bool testManagedMemory() {
if (!supportManagedMemory()) {
return false;
}
std::cout << "Test managed memory host filling" << std::endl;
for (int i = 0; i < NUM_SIZE; i++) {
if (!testManagedMemoryHostFill(totalSizes_[i])) {
return false;
}
}
std::cout << "Test managed memory kernel filling" << std::endl;
for (int i = 0; i < NUM_SIZE; i++) {
if (!testManagedMemoryKernelFill(totalSizes_[i])) {
return false;
}
}
return true;
}
bool testHostMemoryHostFill(size_t size, unsigned int flags) {
double GBytes = static_cast<double>(size) / NUM_1GB;
T *A;
HIP_CHECK(hipHostMalloc(&A, size, flags));
double sec = 0;
hostFill(size, A, coef_, &sec);
HIP_CHECK(hipHostFree(A));
log_host("Host: host fill", GBytes, sec);
return true;
}
bool testHostMemoryKernelFill(size_t size, unsigned int flags) {
double GBytes = static_cast<double>(size) / NUM_1GB;
T *A;
HIP_CHECK(hipHostMalloc(reinterpret_cast<void **>(&A), size, flags));
double sec = 0, sec_hv = 0, sec_kv = 0;
kernelFill(size, A, coef_, &sec);
hostVerify(size, A, coef_, &sec_hv);
kernelVerify(size, A, coef_, &sec_kv);
HIP_CHECK(hipHostFree(A));
log_kernel("Host: kernel fill", GBytes, sec, sec_hv, sec_kv);
return true;
}
bool testHostMemory() {
std::cout << "Test coherent host memory host filling" << std::endl;
for (int i = 0; i < NUM_SIZE; i++) {
if (!testHostMemoryHostFill(totalSizes_[i], hipHostMallocCoherent)) {
return false;
}
}
std::cout << "Test non-coherent host memory host filling" << std::endl;
for (int i = 0; i < NUM_SIZE; i++) {
if (!testHostMemoryHostFill(totalSizes_[i], hipHostMallocNonCoherent)) {
return false;
}
}
std::cout << "Test coherent host memory kernel filling" << std::endl;
for (int i = 0; i < NUM_SIZE; i++) {
if (!testHostMemoryKernelFill(totalSizes_[i], hipHostMallocCoherent)) {
return false;
}
}
std::cout << "Test non-coherent host memory kernel filling" << std::endl;
for (int i = 0; i < NUM_SIZE; i++) {
if (!testHostMemoryKernelFill(totalSizes_[i], hipHostMallocNonCoherent)) {
return false;
}
}
return true;
}
/* This function should be via device attribute query*/
bool supportDeviceMallocFinegrained() {
#ifdef __HIP_PLATFORM_AMD__
T *A = nullptr;
hipError_t err;
err = hipExtMallocWithFlags(reinterpret_cast<void**>(&A), sizeof(T),
hipDeviceMallocFinegrained);
if (err || !A) {
return false;
}
HIP_CHECK(hipFree(A));
return true;
#else
return false;
#endif
}
unsigned int setNumBlocks(size_t size) {
size_t num = size/sizeof(T);
#if USE_HIPTEST_SETNUMBLOCKS
return HipTest::setNumBlocks(blocksPerCU_, threadsPerBlock_, num);
#else
return (num + threadsPerBlock_ - 1) / threadsPerBlock_;
#endif
}
#ifdef __HIP_PLATFORM_AMD__
bool testExtDeviceMemoryHostFill(size_t size, unsigned int flags) {
double GBytes = static_cast<double>(size) / NUM_1GB;
T *A = nullptr;
HIP_CHECK(hipExtMallocWithFlags(reinterpret_cast<void **>(&A),
size, flags));
if (!A) {
std::cout << "failed hipExtMallocWithFlags() with size =" <<
size << " flags="<< std::hex << flags << std::endl;
return false;
}
double sec = 0;
hostFill(size, A, coef_, &sec); // Cpu can access this mem
HIP_CHECK(hipFree(A));
log_host("ExtDevice: host fill", GBytes, sec);
return true;
}
bool testExtDeviceMemoryKernelFill(size_t size, unsigned int flags) {
double GBytes = static_cast<double>(size) / NUM_1GB;
T *A = nullptr;
HIP_CHECK(hipExtMallocWithFlags(reinterpret_cast<void **>(&A),
size, flags));
if (!A) {
std::cout << "failed hipExtMallocWithFlags() with size =" <<
size << " flags=" << std::hex << flags << std::endl;
return false;
}
double sec = 0, sec_hv = 0, sec_kv = 0;
kernelFill(size, A, coef_, &sec);
// Fine grained device memory can be verified by host
hostVerify(size, A, coef_, &sec_hv);
kernelVerify(size, A, coef_, &sec_kv);
HIP_CHECK(hipFree(A));
log_kernel("ExtDevice: kernel fill", GBytes, sec, sec_hv, sec_kv);
return true;
}
bool testExtDeviceMemory() {
std::cout << "Test fine grained device memory host filling"
<< std::endl;
for (int i = 0; i < NUM_SIZE; i++) {
if (!testExtDeviceMemoryHostFill(totalSizes_[i],
hipDeviceMallocFinegrained)) {
return false;
}
}
std::cout << "Test fine grained device memory kernel filling"
<< std::endl;
for (int i = 0; i < NUM_SIZE; i++) {
if (!testExtDeviceMemoryKernelFill(totalSizes_[i],
hipDeviceMallocFinegrained)) {
return false;
}
}
return true;
}
#endif
bool run() {
if (supportLargeBar()) {
if (!testLargeBar()) {
return false;
}
}
if (supportManagedMemory()) {
if (!testManagedMemory()) {
return false;
}
}
if (!testHostMemory()) {
return false;
}
#ifdef __HIP_PLATFORM_AMD__
if (supportDeviceMallocFinegrained()) {
if (!testExtDeviceMemory()) {
return false;
}
}
#endif
return true;
}
};
/**
* Test Description
* ------------------------
*  - Verify hipPerfMemFill status.
* Test source
* ------------------------
*  - perftests/memory/hipPerfMemFill.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
TEST_CASE("Perf_hipPerfMemFill_test") {
std::cout << "Test int" << std::endl;
hipPerfMemFill<int> hipPerfMemFillInt;
REQUIRE(true == hipPerfMemFillInt.open(0));
REQUIRE(true == hipPerfMemFillInt.run());
std::cout << "Test double" << std::endl;
hipPerfMemFill<double> hipPerfMemFillDouble;
REQUIRE(true == hipPerfMemFillDouble.open(0));
REQUIRE(true == hipPerfMemFillDouble.run());
}
+144
Просмотреть файл
@@ -0,0 +1,144 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/**
* @addtogroup hipMemcpy hipMemcpy
* @{
* @ingroup perfMemoryTest
* `hipMemcpy(void* dst, const void* src, size_t count, hipMemcpyKind kind)` -
* Copies data between host and device.
*/
#include <time.h>
#include <hip_test_common.hh>
#define NUM_SIZE 19 // size up to 16M
#define NUM_ITER 500 // Total GPU memory up to 16M*500=8G
void valSet(int* A, int val, size_t size) {
size_t len = size / sizeof(int);
for (int i = 0; i < len; i++) {
A[i] = val;
}
}
void setup(size_t *size, int *num, int **pA, const size_t totalGlobalMem) {
for (int i = 0; i < *num; i++) {
size[i] = 1 << (i + 6);
if ((NUM_ITER + 1) * size[i] > totalGlobalMem) {
*num = i;
break;
}
}
*pA = reinterpret_cast<int*>(malloc(size[*num - 1]));
valSet(*pA, 1, size[*num - 1]);
}
void testInit(size_t size, int *A) {
int *Ad;
clock_t start = clock();
HIP_CHECK(hipMalloc(&Ad, size)); // hip::init() will be called
clock_t end = clock();
double uS = (end - start) * 1000000. / CLOCKS_PER_SEC;
INFO("Initial: hipMalloc(" << size << ") cost " << uS << "us" << "\n");
start = clock();
HIP_CHECK(hipMemcpy(Ad, A, size, hipMemcpyHostToDevice));
HIP_CHECK(hipDeviceSynchronize());
end = clock();
uS = (end - start) * 1000000. / CLOCKS_PER_SEC;
INFO("hipMemcpy(" << size << ") cost " << uS << "us" << "\n");
start = clock();
HIP_CHECK(hipFree(Ad));
end = clock();
uS = (end - start) * 1000000. / CLOCKS_PER_SEC;
INFO("hipFree(" << size << ") cost " << uS << "us" << "\n");
}
static bool hipPerfMemMallocCpyFree_test() {
double uS;
clock_t start, end;
size_t size[NUM_SIZE] = { 0 };
int *Ad[NUM_ITER] = { nullptr };
int *A;
hipDeviceProp_t props;
memset(&props, 0, sizeof(props));
HIP_CHECK(hipGetDeviceProperties(&props, 0));
INFO("totalGlobalMem: " << props.totalGlobalMem << "\n");
int num = NUM_SIZE;
setup(size, &num, &A, props.totalGlobalMem);
testInit(size[0], A);
for (int i = 0; i < num; i++) {
start = clock();
for (int j = 0; j < NUM_ITER; j++) {
HIP_CHECK(hipMalloc(&Ad[j], size[i]));
}
end = clock();
uS = (end - start) * 1000000. / (NUM_ITER * CLOCKS_PER_SEC);
INFO("hipMalloc(" << size[i] << ") cost " << uS << "us" << "\n");
start = clock();
for (int j = 0; j < NUM_ITER; j++) {
HIP_CHECK(hipMemcpy(Ad[j], A, size[i], hipMemcpyHostToDevice));
}
HIP_CHECK(hipDeviceSynchronize());
end = clock();
uS = (end - start) * 1000000. / (NUM_ITER * CLOCKS_PER_SEC);
INFO("hipMemcpy(" << size[i] << ") cost " << uS << "us" << "\n");
start = clock();
for (int j = 0; j < NUM_ITER; j++) {
HIP_CHECK(hipFree(Ad[j]));
Ad[j] = nullptr;
}
end = clock();
double uS = (end - start) * 1000000. / (NUM_ITER * CLOCKS_PER_SEC);
INFO("hipFree(" << size[i] << ") cost " << uS << "us" << "\n");
}
free(A);
return true;
}
/**
* Test Description
* ------------------------
*  - Verify hipPerfMemMallocCpyFree status.
* Test source
* ------------------------
*  - perftests/memory/hipPerfMemMallocCpyFree.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
TEST_CASE("Perf_hipPerfMemMallocCpyFree_test") {
int numDevices = 0;
HIP_CHECK(hipGetDeviceCount(&numDevices));
if (numDevices <= 0) {
SUCCEED("Skipped testcase hipPerfDevMemReadSpeed as"
"there is no device to test.");
} else {
REQUIRE(true == hipPerfMemMallocCpyFree_test());
}
}
+118
Просмотреть файл
@@ -0,0 +1,118 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/**
* @addtogroup hipMemcpy hipMemcpy
* @{
* @ingroup perfMemoryTest
* `hipMemcpy(void* dst, const void* src, size_t count, hipMemcpyKind kind)` -
* Copies data between host and device.
*/
#include <hip_test_common.hh>
#define NUM_SIZE 8
#define NUM_ITER 0x40000
class hipPerfMemcpy {
private:
unsigned int numBuffers_;
size_t totalSizes_[NUM_SIZE];
void setHostBuffer(int *A, int val, size_t size);
public:
hipPerfMemcpy();
~hipPerfMemcpy() {}
bool run(unsigned int numTests);
};
hipPerfMemcpy::hipPerfMemcpy() : numBuffers_(0) {
for (int i = 0; i < NUM_SIZE; i++) {
totalSizes_[i] = 1 << (i + 6);
}
}
void hipPerfMemcpy::setHostBuffer(int *A, int val, size_t size) {
size_t len = size / sizeof(int);
for (int i = 0; i < len; i++) {
A[i] = val;
}
}
bool hipPerfMemcpy::run(unsigned int numTests) {
int *A, *Ad;
A = new int[totalSizes_[numTests]];
setHostBuffer(A, 1, totalSizes_[numTests]);
HIP_CHECK(hipMalloc(&Ad, totalSizes_[numTests]));
// measure performance based on host time
auto all_start = std::chrono::steady_clock::now();
for (int j = 0; j < NUM_ITER; j++) {
HIP_CHECK(hipMemcpy(Ad, A, totalSizes_[numTests], hipMemcpyHostToDevice));
}
HIP_CHECK(hipDeviceSynchronize());
auto all_end = std::chrono::steady_clock::now();
std::chrono::duration<double, std::micro> diff = all_end - all_start;
INFO("hipPerfMemcpy[" << numTests << "] " << "Host to Device copy took "
<< diff.count() / NUM_ITER << " sec for memory size of " <<
totalSizes_[numTests] << " Bytes.");
delete [] A;
HIP_CHECK(hipFree(Ad));
return true;
}
/**
* Test Description
* ------------------------
*  - Verify hipPerfMemcpy status.
* Test source
* ------------------------
*  - perftests/memory/hipPerfMemcpy.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
TEST_CASE("Perf_hipPerfMemcpy_test") {
int numDevices = 0;
HIP_CHECK(hipGetDeviceCount(&numDevices));
if (numDevices <= 0) {
SUCCEED("Skipped testcase hipPerfMemcpy as there is no device to test.");
} else {
int deviceId = 0;
HIP_CHECK(hipSetDevice(deviceId));
hipDeviceProp_t props = {0};
HIP_CHECK(hipGetDeviceProperties(&props, deviceId));
INFO("info: running on bus " << "0x" << props.pciBusID << " " <<
props.name << " with " << props.multiProcessorCount << " CUs "
<< " and device id: " << deviceId);
hipPerfMemcpy hipPerfMemcpy;
for (auto testCase = 0; testCase < NUM_SIZE; testCase++) {
REQUIRE(true == hipPerfMemcpy.run(testCase));
}
}
}
+419
Просмотреть файл
@@ -0,0 +1,419 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/**
* @addtogroup hipMemsetKernel hipMemsetKernel
* @{
* @ingroup perfMemoryTest
* `hipMemset(void* devPtr, int value, size_t count)` -
* Initializes or sets device memory to a value.
*/
#include <hip_test_common.hh>
static size_t typeSizeList[] = {
1, 2, 4, 8, 16, 32, 64, 128,
};
static unsigned int sizeList[] = {
256, 512, 1024, 2048, 4096, 8192,
};
static unsigned int eleNumList[] = {
0x0020000, 0x0080000, 0x0200000, 0x0800000, 0x2000000,
};
typedef struct _dataType {
char memsetval = 0x42;
char memsetD8val = 0xDE;
int16_t memsetD16val = 0xDEAD;
int memsetD32val = 0xDEADBEEF;
}dataType;
#define NUM_ITER 100
enum MemsetType {
hipMemsetTypeDefault,
hipMemsetTypeD8,
hipMemsetTypeD16,
hipMemsetTypeD32
};
class hipPerfMemset {
private:
unsigned int bufSize_;
unsigned int num_typeSize_;
unsigned int num_elements_;
size_t testTypeSize_;
unsigned int testNumEle_;
unsigned int _numSubTests = 0;
unsigned int _numSubTests2D = 0;
unsigned int _numSubTests3D = 0;
unsigned int num_sizes_ = 0;
public:
hipPerfMemset() {
num_typeSize_ = sizeof(typeSizeList) / sizeof(size_t);
num_elements_ = sizeof(eleNumList) / sizeof(unsigned int);
_numSubTests = num_elements_ * num_typeSize_;
num_sizes_ = sizeof(sizeList) / sizeof(unsigned int);
_numSubTests2D = num_sizes_;
_numSubTests3D = _numSubTests2D;
}
~hipPerfMemset() {}
bool open(int deviceID);
template<typename T>
void run1D(unsigned int test, T memsetval, enum MemsetType type, bool async);
template<typename T>
void run2D(unsigned int test, T memsetval, enum MemsetType type, bool async);
template<typename T>
void run3D(unsigned int test, T memsetval, enum MemsetType type, bool async);
uint getNumTests() {
return _numSubTests;
}
uint getNumTests2D() {
return _numSubTests2D;
}
uint getNumTests3D() {
return _numSubTests3D;
}
};
bool hipPerfMemset::open(int deviceId) {
int nGpu = 0;
HIP_CHECK(hipGetDeviceCount(&nGpu));
if (nGpu < 1) {
return false;
}
HIP_CHECK(hipSetDevice(deviceId));
hipDeviceProp_t props = {0};
HIP_CHECK(hipGetDeviceProperties(&props, deviceId));
INFO("info: running on bus " << "0x" << props.pciBusID << " " << props.name
<< " with " << props.multiProcessorCount << " CUs and device id: "
<< deviceId << "\n");
return true;
}
template<typename T>
void hipPerfMemset::run1D(unsigned int test, T memsetval,
enum MemsetType type, bool async) {
T *A_h, *A_d;
testTypeSize_ = typeSizeList[(test / num_elements_) % num_typeSize_];
testNumEle_ = eleNumList[test % num_elements_];
bufSize_ = testNumEle_ * 4;
HIP_CHECK(hipMalloc(&A_d, bufSize_));
A_h = reinterpret_cast<T*> (malloc(bufSize_));
hipStream_t stream;
HIP_CHECK(hipStreamCreate(&stream));
// Warm-up
HIP_CHECK(hipMemset(reinterpret_cast<void *>(A_d), memsetval, bufSize_));
auto start = std::chrono::steady_clock::now();
for (uint i = 0; i < NUM_ITER; i++) {
if (type == hipMemsetTypeDefault && !async) {
HIP_CHECK(hipMemset(reinterpret_cast<void *>(A_d), memsetval, bufSize_));
} else if (type == hipMemsetTypeDefault && async) {
HIP_CHECK(hipMemsetAsync(A_d, memsetval, bufSize_, stream));
} else if (type == hipMemsetTypeD8 && !async) {
HIP_CHECK(hipMemsetD8((hipDeviceptr_t)A_d, memsetval, bufSize_));
} else if (type == hipMemsetTypeD8 && async) {
HIP_CHECK(hipMemsetD8Async((hipDeviceptr_t)A_d, memsetval, bufSize_));
} else if (type == hipMemsetTypeD16 && !async) {
HIP_CHECK(hipMemsetD16((hipDeviceptr_t)A_d, memsetval,
bufSize_/sizeof(T)));
} else if (type == hipMemsetTypeD16 && async) {
HIP_CHECK(hipMemsetD16Async((hipDeviceptr_t)A_d, memsetval,
bufSize_/sizeof(T)));
} else if (type == hipMemsetTypeD32 && !async) {
HIP_CHECK(hipMemsetD32((hipDeviceptr_t)A_d, memsetval,
bufSize_/sizeof(T)));
} else if (type == hipMemsetTypeD32 && async) {
HIP_CHECK(hipMemsetD32Async((hipDeviceptr_t)A_d, memsetval,
bufSize_/sizeof(T)));
}
}
HIP_CHECK(hipDeviceSynchronize());
auto end = std::chrono::steady_clock::now();
HIP_CHECK(hipMemcpy(A_h, A_d, bufSize_, hipMemcpyDeviceToHost) );
for (int i = 0; i < bufSize_/testTypeSize_; i++) {
if (A_h[i] != memsetval) {
INFO("mismatch at index " << i << " computed: " <<
static_cast<int> (A_h[i]) << ", memsetval: " <<
static_cast<int> (memsetval) << "\n");
REQUIRE(false);
}
}
HIP_CHECK(hipFree(A_d));
free(A_h);
std::chrono::duration<double> diff = end - start;
auto sec = diff.count();
auto perf = static_cast<double>((bufSize_ * NUM_ITER * (1e-09)) / sec);
INFO("hipPerf1DMemset[" << test << "] " << (int)bufSize_/1024 << " Kb "
<< std::setw(4) << " typeSize " << (int) testTypeSize_ << ":"
<< std::setw(5) << perf << " GB/s \n");
}
template<typename T>
void hipPerfMemset::run2D(unsigned int test, T memsetval,
enum MemsetType type, bool async) {
bufSize_ = sizeList[test % num_sizes_];
size_t numH = bufSize_;
size_t numW = bufSize_;
size_t pitch_A;
size_t width = numW * sizeof(char);
size_t sizeElements = width * numH;
size_t elements = numW* numH;
T * A_h, * A_d;
HIP_CHECK(hipMallocPitch(reinterpret_cast<void**>(&A_d),
&pitch_A, width, numH));
A_h = reinterpret_cast<char*>(malloc(sizeElements));
for (size_t i=0; i < elements; i++) {
A_h[i] = 1;
}
hipStream_t stream;
HIP_CHECK(hipStreamCreate(&stream));
// Warm-up
HIP_CHECK(hipMemset2D(A_d, pitch_A, memsetval, numW, numH));
auto start = std::chrono::steady_clock::now();
for (uint i = 0; i < NUM_ITER; i++) {
if (type == hipMemsetTypeDefault && !async) {
HIP_CHECK(hipMemset2D(A_d, pitch_A, memsetval, numW, numH));
} else if (type == hipMemsetTypeDefault && async) {
HIP_CHECK(hipMemset2DAsync(A_d, pitch_A, memsetval, numW, numH, stream));
}
}
HIP_CHECK(hipStreamSynchronize(stream));
auto end = std::chrono::steady_clock::now();
HIP_CHECK(hipMemcpy2D(A_h, width, A_d, pitch_A, numW, numH,
hipMemcpyDeviceToHost));
for (int i=0; i < elements; i++) {
if (A_h[i] != memsetval) {
INFO("mismatch at index " << i << " computed: " <<
static_cast<int> (A_h[i]) << ", memsetval: " <<
static_cast<int> (memsetval) << "\n");
REQUIRE(false);
}
}
std::chrono::duration<double> diff = end - start;
auto sec = diff.count();
auto perf = static_cast<double>((sizeElements* NUM_ITER * (1e-09)) / sec);
INFO("hipPerf2DMemset[" << test << "] " <<" " << "(GB/s) for " <<
(int)bufSize_ << " x " << bufSize_ << " bytes : " << std::setw(5) <<
perf << "\n");
HIP_CHECK(hipStreamDestroy(stream));
HIP_CHECK(hipFree(A_d));
free(A_h);
}
template<typename T>
void hipPerfMemset::run3D(unsigned int test, T memsetval,
enum MemsetType type, bool async) {
bufSize_ = sizeList[test % num_sizes_];
size_t numH = bufSize_;
size_t numW = bufSize_;
size_t depth = 10;
size_t width = numW * sizeof(char);
size_t sizeElements = width * numH * depth;
size_t elements = numW* numH* depth;
hipStream_t stream;
HIP_CHECK(hipStreamCreate(&stream));
T *A_h;
hipExtent extent = make_hipExtent(width, numH, depth);
hipPitchedPtr devPitchedPtr;
HIP_CHECK(hipMalloc3D(&devPitchedPtr, extent));
A_h = reinterpret_cast<char*>(malloc(sizeElements));
HIPASSERT(A_h != NULL);
for (size_t i = 0; i < elements; i++) {
A_h[i] = 1;
}
// Warm up
HIP_CHECK(hipMemset3D(devPitchedPtr, memsetval, extent));
auto start = std::chrono::steady_clock::now();
for (uint i = 0; i < NUM_ITER; i++) {
if (type == hipMemsetTypeDefault && !async) {
HIP_CHECK(hipMemset3D(devPitchedPtr, memsetval, extent));
} else if (type == hipMemsetTypeDefault && async) {
HIP_CHECK(hipMemset3DAsync(devPitchedPtr, memsetval, extent, stream));
}
}
HIP_CHECK(hipStreamSynchronize(stream));
auto end = std::chrono::steady_clock::now();
hipMemcpy3DParms myparms = {0};
myparms.srcPos = make_hipPos(0, 0, 0);
myparms.dstPos = make_hipPos(0, 0, 0);
myparms.dstPtr = make_hipPitchedPtr(A_h, width , numW, numH);
myparms.srcPtr = devPitchedPtr;
myparms.extent = extent;
myparms.kind = hipMemcpyDeviceToHost;
HIP_CHECK(hipMemcpy3D(&myparms));
for (int i=0; i < elements; i++) {
if (A_h[i] != memsetval) {
INFO("mismatch at index " << i << " computed: " <<
static_cast<int> (A_h[i]) << ", memsetval: " <<
static_cast<int> (memsetval) << "\n");
REQUIRE(false);
}
}
std::chrono::duration<double> diff = end - start;
auto sec = diff.count();
auto perf = static_cast<double>((sizeElements * NUM_ITER * (1e-09)) / sec);
INFO("hipPerf3DMemset[" << test << "] " <<" " << "(GB/s) for " <<
(int)bufSize_ << " x " << bufSize_ << " x " <<depth << " bytes : " <<
std::setw(5) << perf << "\n");
HIP_CHECK(hipFree(devPitchedPtr.ptr));
free(A_h);
}
/**
* Test Description
* ------------------------
*  - Verify hipPerfMemset status.
* Test source
* ------------------------
*  - perftests/memory/hipPerfMemset.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
TEST_CASE("Perf_hipPerfMemset_test") {
hipPerfMemset hipPerfMemset;
int deviceId = 0;
REQUIRE(hipPerfMemset.open(deviceId));
dataType pattern;
int numTests = hipPerfMemset.getNumTests();
int numTests2D = hipPerfMemset.getNumTests2D();
int numTests3D = hipPerfMemset.getNumTests3D();
bool async = false;
for (uint i = 0; i < 2 ; i++) {
if (async) {
INFO("Perf of hipMemsetAsync for 1D arrays \n");
} else {
INFO("Perf of hipMemset for 1D arrays \n");
}
for (auto testCase = 0; testCase < numTests; testCase++) {
if (testCase < 5) {
INFO("API: hipMemset \n");
hipPerfMemset.run1D(testCase, pattern.memsetval,
hipMemsetTypeDefault, async);
} else if (testCase < 10) {
INFO("API: hipMemsetD16 \n");
hipPerfMemset.run1D(testCase, pattern.memsetD16val,
hipMemsetTypeD16, async);
} else if (testCase < 15) {
INFO("API: hipMemsetD32 \n");
hipPerfMemset.run1D(testCase, pattern.memsetD32val,
hipMemsetTypeD32, async);
} else {
INFO("API: hipMemset \n");
hipPerfMemset.run1D(testCase, pattern.memsetval,
hipMemsetTypeDefault, async);
}
}
async = true;
}
for (uint i = 0; i < 2; i++) {
if (async) {
INFO("Perf of hipMemset2DAsync for 2D arrays \n");
} else {
INFO("Perf of hipMemset2D for 2D arrays \n");
}
for (uint test = 0; test < numTests2D; test++) {
hipPerfMemset.run2D(test, pattern.memsetval, hipMemsetTypeDefault, async);
}
async = false;
}
for (uint i = 0; i < 2; i++) {
if (async) {
INFO("Perf of hipMemset3DAsync for 3D arrays \n");
} else {
INFO("Perf of hipMemset3D for 3D arrays \n");
}
for (uint test = 0; test < numTests3D; test++) {
hipPerfMemset.run3D(test, pattern.memsetval, hipMemsetTypeDefault, async);
}
}
}
+311
Просмотреть файл
@@ -0,0 +1,311 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/**
* @addtogroup hipMemcpyKernel hipMemcpyKernel
* @{
* @ingroup perfMemoryTest
* `hipMemcpy(void* dst, const void* src, size_t count, hipMemcpyKind kind)` -
* Copies data between host and device.
*/
#include <hip_test_common.hh>
#define NUM_TYPES 3
std::vector<std::string> types = {"float", "float2", "float4"};
std::vector<unsigned int> typeSizes = {4, 8, 16};
#define NUM_SIZES 12
std::vector<unsigned int> sizes = {1, 2, 4, 8, 16, 32,
64, 128, 256, 512, 1024, 2048};
#define NUM_BUFS 6
#define MAX_BUFS (1 << (NUM_BUFS - 1))
#ifdef __HIP_PLATFORM_NVIDIA__
__host__ __device__ void operator+=(float2 &a, float2 b) { //NOLINT
a.x += b.x; a.y += b.y;
}
__host__ __device__ void operator+=(float4 &a, float4 b) { //NOLINT
a.x += b.x; a.y += b.y; a.z += b.z; a.w += b.w;
}
#endif
template <typename T>
__global__ void sampleRate(T * outBuffer, unsigned int inBufSize,
unsigned int writeIt, T **inBuffer, int numBufs) {
uint gid = (blockIdx.x * blockDim.x + threadIdx.x);
uint inputIdx = gid % inBufSize;
T tmp;
memset(&tmp, 0, sizeof(T));
for (int i = 0; i < numBufs; i++) {
tmp += *(*(inBuffer+i)+inputIdx);
}
if (writeIt*(unsigned int)tmp.x) {
outBuffer[gid] = tmp;
}
}
template <typename T>
__global__ void sampleRateFloat(T * outBuffer, unsigned int inBufSize,
unsigned int writeIt, T ** inBuffer, int numBufs) {
uint gid = (blockIdx.x * blockDim.x + threadIdx.x);
uint inputIdx = gid % inBufSize;
T tmp = (T)0.0f;
for (int i = 0; i < numBufs; i++) {
tmp += *((*inBuffer+i)+inputIdx);
}
if (writeIt*(unsigned int)tmp) {
outBuffer[gid] = tmp;
}
}
class hipPerfSampleRate {
public:
hipPerfSampleRate();
~hipPerfSampleRate();
bool open(void);
void run(unsigned int testCase);
void close(void);
// array of funtion pointers
typedef void (hipPerfSampleRate::*funPtr)(void * outBuffer, unsigned int
inBufSize, unsigned int writeIt, void **inBuffer, int numBufs,
int grids, int blocks, int threads_per_block);
// Wrappers
void float_kernel(void * outBuffer, unsigned int inBufSize,
unsigned int writeIt, void **inBuffer, int numBufs,
int grids, int blocks, int threads_per_block);
void float2_kernel(void * outBuffer, unsigned int inBufSize,
unsigned int writeIt, void **inBuffer, int numBufs,
int grids, int blocks, int threads_per_block);
void float4_kernel(void * outBuffer, unsigned int inBufSize,
unsigned int writeIt, void **inBuffer, int numBufs,
int grids, int blocks, int threads_per_block);
private:
void setData(void *ptr, unsigned int value);
void checkData(uint *ptr);
unsigned int width_;
unsigned int bufSize_;
int numCUs;
unsigned int outBufSize_;
static const unsigned int MAX_ITERATIONS = 25;
unsigned int numBufs_;
unsigned int typeIdx_;
};
hipPerfSampleRate::hipPerfSampleRate() {}
hipPerfSampleRate::~hipPerfSampleRate() {}
void hipPerfSampleRate::close() {}
bool hipPerfSampleRate::open(void) {
int nGpu = 0;
HIP_CHECK(hipGetDeviceCount(&nGpu));
if (nGpu < 1) {
return false;
}
int deviceId = 0;
hipDeviceProp_t props = {0};
props = {0};
HIP_CHECK(hipSetDevice(deviceId));
HIP_CHECK(hipGetDeviceProperties(&props, deviceId));
INFO("info: running on bus " << "0x" << props.pciBusID << " " <<
props.name << " with " << props.multiProcessorCount <<
" CUs" << " and device id: " << deviceId << "\n");
numCUs = props.multiProcessorCount;
return true;
}
// Wrappers for the kernel launches
void hipPerfSampleRate::float_kernel(void * outBuffer, unsigned int inBufSize,
unsigned int writeIt, void **inBuffer, int numBufs,
int grids, int blocks, int threads_per_block) {
hipLaunchKernelGGL(sampleRateFloat<float>, dim3(grids, grids, grids),
dim3(blocks), 0, 0, reinterpret_cast<float*>(outBuffer),
inBufSize, writeIt, reinterpret_cast<float**>(inBuffer), numBufs);
}
void hipPerfSampleRate::float2_kernel(void * outBuffer, unsigned int inBufSize,
unsigned int writeIt, void **inBuffer, int grids,
int blocks, int threads_per_block, int numBufs) {
hipLaunchKernelGGL(sampleRate<float2>, dim3(grids, grids, grids),
dim3(blocks), 0, 0, reinterpret_cast<float2 *>(outBuffer),
inBufSize, writeIt, reinterpret_cast<float2 **>(inBuffer), numBufs);
}
void hipPerfSampleRate::float4_kernel(void * outBuffer, unsigned int inBufSize,
unsigned int writeIt, void **inBuffer, int grids,
int blocks, int threads_per_block, int numBufs) {
hipLaunchKernelGGL(sampleRate<float4>, dim3(grids, grids, grids),
dim3(blocks), 0, 0, reinterpret_cast<float4 *>(outBuffer),
inBufSize, writeIt, reinterpret_cast<float4 **>(inBuffer), numBufs);
}
void hipPerfSampleRate::run(unsigned int test) {
funPtr p[] = {&hipPerfSampleRate::float_kernel,
&hipPerfSampleRate::float2_kernel,
&hipPerfSampleRate::float4_kernel};
// We compute a square domain
width_ = sizes[test % NUM_SIZES];
typeIdx_ = (test / NUM_SIZES) % NUM_TYPES;
bufSize_ = width_ * width_ * typeSizes[typeIdx_];
numBufs_ = (1 << (test / (NUM_SIZES * NUM_TYPES)));
void ** dPtr;
void * hOutPtr;
void * dOutPtr;
void * hInPtr[numBufs_];
void * dInPtr[numBufs_];
outBufSize_ =
sizes[NUM_SIZES - 1] * sizes[NUM_SIZES - 1] * typeSizes[NUM_TYPES - 1];
// Allocate memory on the host and device
HIP_CHECK(hipHostMalloc(reinterpret_cast<void **>(&hOutPtr), outBufSize_,
hipHostMallocDefault));
setData(reinterpret_cast<void *>(hOutPtr), 0xdeadbeef);
HIP_CHECK(hipMalloc(reinterpret_cast<uint **>(&dOutPtr), outBufSize_));
// Allocate 2D array in Device
HIP_CHECK(hipMalloc(reinterpret_cast<void **>(&dPtr),
numBufs_* sizeof(void *)));
for (uint i = 0; i < numBufs_; i++) {
HIP_CHECK(hipHostMalloc(reinterpret_cast<void **>(&hInPtr[i]), bufSize_,
hipHostMallocDefault));
HIP_CHECK(hipMalloc(reinterpret_cast<uint **>(&dInPtr[i]), bufSize_));
setData(hInPtr[i], 0x3f800000);
}
// Populate array of pointers with array addresses
HIP_CHECK(hipMemcpy(dPtr, dInPtr, numBufs_* sizeof(void *),
hipMemcpyHostToDevice));
// Copy memory from host to device
for (uint i = 0; i < numBufs_; i++) {
HIP_CHECK(hipMemcpy(dInPtr[i], hInPtr[i], bufSize_, hipMemcpyHostToDevice));
}
HIP_CHECK(hipMemcpy(dOutPtr, hOutPtr, outBufSize_, hipMemcpyHostToDevice));
// Prepare kernel launch parameters
// outBufSize_/sizeof(uint) - Grid size in 3D
int grids = 64;
int blocks = 64;
int threads_per_block = 1;
unsigned int maxIter = MAX_ITERATIONS * (MAX_BUFS / numBufs_);
unsigned int sizeDW = width_ * width_;
unsigned int writeIt = 0;
int idx = 0;
if (!types[typeIdx_].compare("float")) {
idx = 0;
} else if (!types[typeIdx_].compare("float2")) {
idx = 1;
} else if (!types[typeIdx_].compare("float4")) {
idx = 2;
}
// Time the kernel execution
auto all_start = std::chrono::steady_clock::now();
for (uint i = 0; i < maxIter; i++) {
(this->*p[idx]) (reinterpret_cast<void *>(dOutPtr), sizeDW, writeIt,
dPtr, numBufs_, grids, blocks, threads_per_block);
}
HIP_CHECK(hipDeviceSynchronize());
auto all_end = std::chrono::steady_clock::now();
std::chrono::duration<double> all_kernel_time = all_end - all_start;
double perf = (static_cast<double>(outBufSize_ * numBufs_ *
maxIter * (1e-09))) / all_kernel_time.count();
INFO("Domain " << sizes[NUM_SIZES - 1] << "x"<< sizes[NUM_SIZES - 1]
<< " bufs " << numBufs_ << " " << types[typeIdx_] << " " << width_
<< "x" <<width_<< " (GB/s) " << perf << "\n");
HIP_CHECK(hipFree(dOutPtr));
// Free host and device memory
for (uint i = 0; i < numBufs_; i++) {
HIP_CHECK(hipHostFree(hInPtr[i]));
HIP_CHECK(hipFree(dInPtr[i]));
}
HIP_CHECK(hipHostFree(hOutPtr));
HIP_CHECK(hipFree(dPtr));
}
void hipPerfSampleRate::setData(void *ptr, unsigned int value) {
unsigned int *ptr2 = (unsigned int *)ptr;
for (unsigned int i = 0; i < bufSize_ / sizeof(unsigned int); i++) {
ptr2[i] = value;
}
}
void hipPerfSampleRate::checkData(uint *ptr) {
for (unsigned int i = 0; i < outBufSize_ / sizeof(float); i++) {
if (ptr[i] != static_cast<float>(numBufs_)) {
INFO("Data validation failed at "<< i << " Got "<< ptr[i]
<< ", expected " << (float)numBufs_ << "\n");
REQUIRE(false);
}
}
}
/**
* Test Description
* ------------------------
*  - Verify hipPerfSampleRate status.
* Test source
* ------------------------
*  - perftests/memory/hipPerfSampleRate.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
TEST_CASE("Perf_hipPerfSampleRate_test") {
hipPerfSampleRate sampleTypes;
REQUIRE(true == sampleTypes.open());
for (unsigned int testCase = 0; testCase < 216 ; testCase+=36) {
sampleTypes.run(testCase);
}
}
+262
Просмотреть файл
@@ -0,0 +1,262 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/**
* @addtogroup hipMemcpyKernel hipMemcpyKernel
* @{
* @ingroup perfMemoryTest
* `hipMemcpy(void* dst, const void* src, size_t count, hipMemcpyKind kind)` -
* Copies data between host and device.
*/
#include <hip_test_common.hh>
#define sharedMemSize1 2048
#define sharedMemSize2 256
__global__ void sharedMemReadSpeed1(float *outBuf, ulong N) {
size_t gid = (blockIdx.x * blockDim.x + threadIdx.x);
size_t lid = threadIdx.x;
__shared__ float local[sharedMemSize1];
float val1 = 0;
float val2 = 0;
float val3 = 0;
float val4 = 0;
for (int i = 0; i < (sharedMemSize1 / 64); i++) {
local[lid + i * 64] = lid;
}
__syncthreads();
val1 += local[lid];
val2 += local[lid + 64];
val3 += local[lid + 128];
val4 += local[lid + 192];
val1 += local[lid + 256];
val2 += local[lid + 320];
val3 += local[lid + 384];
val4 += local[lid + 448];
val1 += local[lid + 512];
val2 += local[lid + 576];
val3 += local[lid + 640];
val4 += local[lid + 704];
val1 += local[lid + 768];
val2 += local[lid + 832];
val3 += local[lid + 896];
val4 += local[lid + 960];
val1 += local[lid + 1024];
val2 += local[lid + 1088];
val3 += local[lid + 1152];
val4 += local[lid + 1216];
val1 += local[lid + 1280];
val2 += local[lid + 1344];
val3 += local[lid + 1408];
val4 += local[lid + 1472];
val1 += local[lid + 1536];
val2 += local[lid + 1600];
val3 += local[lid + 1664];
val4 += local[lid + 1728];
val1 += local[lid + 1792];
val2 += local[lid + 1856];
val3 += local[lid + 1920];
val4 += local[lid + 1984];
if (gid < N) {
outBuf[gid] = val1 + val2 + val3 + val4;
}
}
__global__ void sharedMemReadSpeed2(float *outBuf, ulong N) {
size_t gid = (blockIdx.x * blockDim.x + threadIdx.x);
size_t lid = threadIdx.x;
__shared__ float local[sharedMemSize2];
float val0 = 0.0f;
float val1 = 0.0f;
for (int i = 0; i < (sharedMemSize2 / 64); i++) {
local[lid + i * 64] = lid;
}
__syncthreads();
#pragma nounroll
for (uint i = 0; i < 32; i++) {
val0 += local[8 * i + 0];
val1 += local[8 * i + 1];
val0 += local[8 * i + 2];
val1 += local[8 * i + 3];
val0 += local[8 * i + 4];
val1 += local[8 * i + 5];
val0 += local[8 * i + 6];
val1 += local[8 * i + 7];
}
if (gid < N) {
outBuf[gid] = val0 + val1;
}
}
static bool hipPerfSharedMemReadSpeed_test() {
float *dDst;
float *hDst;
hipStream_t stream;
constexpr uint numSizes = 4;
constexpr uint Sizes[numSizes] = {262144, 1048576, 4194304, 16777216};
uint numReads1 = 32;
uint numReads2 = 256;
uint sharedMemSizeBytes1 = sharedMemSize1 * sizeof(float);
uint sharedMemSizeBytes2 = sharedMemSize2 * sizeof(float);
int nIter = 1000;
const unsigned threadsPerBlock = 64;
static int device = 0;
HIP_CHECK(hipSetDevice(device));
hipDeviceProp_t props;
HIP_CHECK(hipGetDeviceProperties(&props, device));
INFO("info: running on bus " << "0x" << props.pciBusID << " " << props.name
<< " with " << props.multiProcessorCount << " CUs \n");
HIP_CHECK(hipStreamCreate(&stream));
for (int nTest = 0; nTest < numSizes; nTest++) {
uint nBytes = Sizes[nTest % numSizes];
ulong N = nBytes / sizeof(float);
const unsigned blocks = N / threadsPerBlock;
hDst = new float[nBytes];
HIP_CHECK(hDst == 0 ? hipErrorOutOfMemory : hipSuccess);
memset(hDst, 0, nBytes);
HIP_CHECK(hipMalloc(&dDst, nBytes));
HIP_CHECK(hipMemcpy(dDst, hDst, nBytes, hipMemcpyHostToDevice));
hipLaunchKernelGGL(sharedMemReadSpeed1, dim3(blocks),
dim3(threadsPerBlock), 0, stream, dDst, N);
HIP_CHECK(hipMemcpy(hDst, dDst, nBytes, hipMemcpyDeviceToHost));
HIP_CHECK(hipDeviceSynchronize());
int tmp = 0;
for (int i = 0; i < N; i++) {
if (i % threadsPerBlock == 0) {
tmp = 0;
}
if (hDst[i] != tmp) {
INFO("info: Data validation failed for warm up run! \n");
INFO("info: expected " << tmp << " got " << hDst[i] << " \n");
return false;
}
tmp += threadsPerBlock / 2;
}
auto all_start = std::chrono::steady_clock::now();
for (int i = 0; i < nIter; i++) {
hipLaunchKernelGGL(sharedMemReadSpeed1, dim3(blocks),
dim3(threadsPerBlock), 0, stream, dDst, N);
}
HIP_CHECK(hipDeviceSynchronize());
auto all_end = std::chrono::steady_clock::now();
std::chrono::duration<double> all_kernel_time = all_end - all_start;
// read speed in GB/s
double perf = (static_cast<double>(blocks * threadsPerBlock)
* (numReads1 * sizeof(float) + sharedMemSizeBytes1 / 64)
* nIter * (1e-09)) / all_kernel_time.count();
INFO("info: read speed = " << std::setw(8) << perf << " GB/s for " <<
sharedMemSizeBytes1 / 1024 << " KB shared memory with " <<
std::setw(8) << blocks * threadsPerBlock << " threads, "
<< std::setw(4) << numReads1 <<
" reads in sharedMemReadSpeed1 kernel \n");
delete[] hDst;
HIP_CHECK(hipFree(dDst));
}
for (int nTest = 0; nTest < numSizes; nTest++) {
uint nBytes = Sizes[nTest % numSizes];
ulong N = nBytes / sizeof(float);
const unsigned blocks = N / threadsPerBlock;
hDst = new float[nBytes];
HIP_CHECK(hDst == 0 ? hipErrorOutOfMemory : hipSuccess);
memset(hDst, 0, nBytes);
HIP_CHECK(hipMalloc(&dDst, nBytes));
HIP_CHECK(hipMemcpy(dDst, hDst, nBytes, hipMemcpyHostToDevice));
hipLaunchKernelGGL(sharedMemReadSpeed2, dim3(blocks),
dim3(threadsPerBlock), 0, stream, dDst, N);
HIP_CHECK(hipMemcpy(hDst, dDst, nBytes, hipMemcpyDeviceToHost));
HIP_CHECK(hipDeviceSynchronize());
auto all_start = std::chrono::steady_clock::now();
for (int i = 0; i < nIter; i++) {
hipLaunchKernelGGL(sharedMemReadSpeed2, dim3(blocks),
dim3(threadsPerBlock), 0, stream, dDst, N);
}
HIP_CHECK(hipDeviceSynchronize());
auto all_end = std::chrono::steady_clock::now();
std::chrono::duration<double> all_kernel_time = all_end - all_start;
// read speed in GB/s
double perf = (static_cast<double>(blocks * threadsPerBlock)
* (numReads2 * sizeof(float) + sharedMemSizeBytes2 / 64)
* nIter * (1e-09)) / all_kernel_time.count();
INFO("info: read speed = " << std::setw(8) << perf << " GB/s for "
<< sharedMemSizeBytes2 / 1024 << " KB shared memory with "
<< std::setw(8) << blocks * threadsPerBlock << " threads, "
<< std::setw(4) << numReads2 <<
" reads in sharedMemReadSpeed2 kernel \n");
delete[] hDst;
HIP_CHECK(hipFree(dDst));
}
HIP_CHECK(hipStreamDestroy(stream));
return true;
}
/**
* Test Description
* ------------------------
*  - Verify hipPerfSharedMemReadSpeed status.
* Test source
* ------------------------
*  - perftests/memory/hipPerfSharedMemReadSpeed.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
TEST_CASE("Perf_hipPerfSharedMemReadSpeed_test") {
int numDevices = 0;
HIP_CHECK(hipGetDeviceCount(&numDevices));
if (numDevices <= 0) {
SUCCEED("Skipped testcase hipPerfSharedMemReadSpeed as"
"there is no device to test.\n");
} else {
REQUIRE(true == hipPerfSharedMemReadSpeed_test());
}
}
+45 -9
Просмотреть файл
@@ -1,5 +1,5 @@
/*
Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
@@ -17,8 +17,10 @@ OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include "hip_test_common.hh"
#include "hip_test_helper.hh"
#include <hip_test_common.hh>
#include <hip_test_helper.hh>
#define ADDITIONAL_MEMORY_PERCENT 10
// Stress allocation tests
// Try to allocate as much memory as possible
@@ -27,26 +29,60 @@ THE SOFTWARE.
TEST_CASE("Stress_hipHostMalloc_MaxAllocation") {
size_t devMemAvail{0}, devMemFree{0};
HIP_CHECK(hipMemGetInfo(&devMemFree, &devMemAvail));
auto hostMemFree = HipTest::getMemoryAmount() /* In MB */ * 1024 * 1024; // In bytes
auto hostMemFree = HipTest::getMemoryAmount() * 1024 * 1024; // In bytes
REQUIRE(devMemFree > 0);
REQUIRE(devMemAvail > 0);
REQUIRE(hostMemFree > 0);
size_t memFree = std::min(devMemFree, hostMemFree); // which is the limiter cpu or gpu
// which is the limiter cpu or gpu
size_t memFree = std::min(devMemFree, hostMemFree);
char* d_ptr{nullptr};
size_t counter{0};
INFO("Max Allocation of " << memFree << " bytes!");
while (hipHostMalloc(&d_ptr, memFree) != hipSuccess && memFree > 1) {
counter++;
INFO("Attempt to allocate " << memFree << " bytes out of " << devMemFree << "bytes Failed!");
INFO("Attempt to allocate " << memFree << \
" bytes out of " << devMemFree << "bytes Failed!");
memFree >>= 1; // reduce the memory to be allocated by half
REQUIRE(counter <= 2); // Make sure that we are atleast able to allocate 1/4th of max memory
REQUIRE(counter <= 2); // Make sure that we are atleast able to allocate
// 1/4th of max memory
}
HIP_CHECK(hipMemset(d_ptr, 1, memFree));
HIP_CHECK(hipDeviceSynchronize()); // Flush caches
REQUIRE(std::all_of(d_ptr, d_ptr + memFree, [](unsigned char n) { return n == 1; }));
REQUIRE(std::all_of(d_ptr, d_ptr + memFree,
[](unsigned char n) { return n == 1; }));
HIP_CHECK(hipHostFree(d_ptr));
}
// Allocate more memory than total GPU memory in each available GPU.
// hipHostMalloc should return hipSuccess.
TEST_CASE("Stress_hipHostMalloc_MaxAllocation_AllGpu") {
char* A = nullptr;
size_t maxGpuMem = 0, availableMem = 0;
int count = 0;
HIP_CHECK(hipGetDeviceCount(&count));
for (int dev = 0; dev < count; dev++) {
// Get available GPU memory and total GPU memory
HIP_CHECK(hipSetDevice(dev));
HIP_CHECK(hipMemGetInfo(&availableMem, &maxGpuMem));
size_t allocsize = maxGpuMem +
((maxGpuMem*ADDITIONAL_MEMORY_PERCENT)/100);
// Get free host In bytes
size_t hostMemFree = HipTest::getMemoryAmount() * 1024 * 1024;
if (allocsize < hostMemFree) {
HIP_CHECK(hipHostMalloc(reinterpret_cast<void**>(&A), allocsize));
// Check accessibility of memory
constexpr size_t samplesize = 1024;
constexpr int val = 32;
// Write at beginning of memory chunk for a size of samplesize
HIP_CHECK(hipMemset(A, val, samplesize));
// Write at end of memory chunk for a size of samplesize
HIP_CHECK(hipMemset((A + allocsize - 1 - samplesize), val, samplesize));
HIP_CHECK(hipHostFree(A));
} else {
WARN("Skipping test as CPU memory is less than GPU memory");
}
}
}
+1 -1
Просмотреть файл
@@ -31,7 +31,7 @@ THE SOFTWARE.
#include <hip/hip_cooperative_groups.h>
#include <stdio.h>
#include <vector>
#pragma clang diagnostic ignored "-Wunused-variable"
using namespace cooperative_groups;
#define ASSERT_EQUAL(lhs, rhs) assert(lhs == rhs)
+2 -2
Просмотреть файл
@@ -30,7 +30,7 @@ THE SOFTWARE.
#include <hip/hip_cooperative_groups.h>
#include <stdio.h>
#include <vector>
#pragma clang diagnostic ignored "-Wunused-variable"
using namespace cooperative_groups;
#define ASSERT_EQUAL(lhs, rhs) assert(lhs == rhs)
@@ -247,4 +247,4 @@ TEST_CASE("Unit_coalesced_groups_shfl_up") {
}
}
/* Kogge-Stone algorithm */
/* Kogge-Stone algorithm */
+2 -2
Просмотреть файл
@@ -143,7 +143,7 @@ TEST_CASE("Unit_Grid_Group_Getters_Positive_Basic") {
HIP_CHECK(hipDeviceSynchronize());
// Verify grid_group.is_valid() values
ArrayAllOf(uint_arr.ptr(), grid.thread_count_, [](uint32_t i) { return 1; });
ArrayAllOf(uint_arr.ptr(), grid.thread_count_, [](uint32_t) { return 1; });
}
/**
@@ -282,4 +282,4 @@ TEST_CASE("Unit_Grid_Group_Sync_Positive_Basic") {
}
REQUIRE(uint_arr.ptr()[i * grid.block_count_ + j] == max_in_this_loop - 1);
}
}
}
+6 -6
Просмотреть файл
@@ -34,10 +34,10 @@ bool UNSETENV(std::string var) {
return (result == 0) ? true: false;
}
bool SETENV(std::string var, std::string value, int overwrite) {
bool SETENV(std::string var, std::string value) {
int result = -1;
#ifdef __unix__
result = setenv(var.c_str(), value.c_str(), overwrite);
result = setenv(var.c_str(), value.c_str(), 1);
#else
result = _putenv((var + '=' + value).c_str());
#endif
@@ -59,7 +59,7 @@ int main(int argc, char** argv) {
// disable visible_devices env from shell
#ifdef __HIP_PLATFORM_NVCC__
UNSETENV("CUDA_VISIBLE_DEVICES");
SETENV("CUDA_VISIBLE_DEVICES", argv[1], 1);
SETENV("CUDA_VISIBLE_DEVICES", argv[1]);
auto init_res = hipInit(0);
if (hipSuccess != init_res) {
std::cerr << "CUDA INIT API returned : " << hipGetErrorString(init_res) << std::endl;
@@ -68,8 +68,8 @@ int main(int argc, char** argv) {
#else
UNSETENV("ROCR_VISIBLE_DEVICES");
UNSETENV("HIP_VISIBLE_DEVICES");
SETENV("ROCR_VISIBLE_DEVICES", argv[1], 1);
SETENV("HIP_VISIBLE_DEVICES", argv[1], 1);
SETENV("ROCR_VISIBLE_DEVICES", argv[1]);
SETENV("HIP_VISIBLE_DEVICES", argv[1]);
#endif
int count = 0;
@@ -86,4 +86,4 @@ int main(int argc, char** argv) {
UNSETENV("HIP_VISIBLE_DEVICES");
#endif
return count;
}
}
+5 -5
Просмотреть файл
@@ -32,10 +32,10 @@ bool UNSETENV(std::string var) {
return (result == 0) ? true: false;
}
bool SETENV(std::string var, std::string value, int overwrite) {
bool SETENV(std::string var, std::string value) {
int result = -1;
#ifdef __unix__
result = setenv(var.c_str(), value.c_str(), overwrite);
result = setenv(var.c_str(), value.c_str(), 1);
#else
result = _putenv((var + '=' + value).c_str());
#endif
@@ -44,10 +44,10 @@ bool SETENV(std::string var, std::string value, int overwrite) {
void inline hideDevices(const char* devices) {
#if HT_NVIDIA
SETENV("CUDA_VISIBLE_DEVICES", devices, 1);
SETENV("CUDA_VISIBLE_DEVICES", devices);
#else
SETENV("HIP_VISIBLE_DEVICES", devices, 1);
SETENV("ROCR_VISIBLE_DEVICES", devices, 1);
SETENV("HIP_VISIBLE_DEVICES", devices);
SETENV("ROCR_VISIBLE_DEVICES", devices);
#endif
}
+1 -1
Просмотреть файл
@@ -53,7 +53,7 @@ TEST_CASE("Unit_hipDeviceGetUuid_Positive") {
// Atleast one non zero value
size_t uuidSize = sizeof(uuid.bytes) / sizeof(uuid.bytes[0]);
for (int i = 0; i < uuidSize; i++) {
for (size_t i = 0; i < uuidSize; i++) {
if (uuid.bytes[i] != 0) {
uuidValid = true;
break;
+4 -4
Просмотреть файл
@@ -198,8 +198,8 @@ TEST_CASE("Unit_BuiltInAtomicAdd_CoherentGlobalMemWithRtc") {
void* config_d[] = {HIP_LAUNCH_PARAM_BUFFER_POINTER, &args_f,
HIP_LAUNCH_PARAM_BUFFER_SIZE,
&size, HIP_LAUNCH_PARAM_END};
hipModuleLaunchKernel(fmaxkernel, 1, 1, 1, 1, 1, 1, 0,
nullptr, nullptr, config_d);
HIP_CHECK(hipModuleLaunchKernel(fmaxkernel, 1, 1, 1, 1, 1, 1, 0,
nullptr, nullptr, config_d));
HIP_CHECK(hipDeviceSynchronize());
HIP_CHECK(hipMemcpy(B_h, result, sizeof(double), hipMemcpyDeviceToHost));
REQUIRE(A_h[0] == INITIAL_VAL);
@@ -278,8 +278,8 @@ TEST_CASE("Unit_BuiltInAtomicAdd_NonCoherentGlobalMemWithRtc") {
void* config_d[] = {HIP_LAUNCH_PARAM_BUFFER_POINTER, &args_f,
HIP_LAUNCH_PARAM_BUFFER_SIZE,
&size, HIP_LAUNCH_PARAM_END};
hipModuleLaunchKernel(fmaxkernel, 1, 1, 1, 1, 1, 1, 0,
nullptr, nullptr, config_d);
HIP_CHECK(hipModuleLaunchKernel(fmaxkernel, 1, 1, 1, 1, 1, 1, 0,
nullptr, nullptr, config_d));
HIP_CHECK(hipDeviceSynchronize());
HIP_CHECK(hipMemcpy(B_h, result, sizeof(double), hipMemcpyDeviceToHost));
REQUIRE(A_h[0] == INITIAL_VAL + INC_VAL);
+4 -4
Просмотреть файл
@@ -229,8 +229,8 @@ TEST_CASE("Unit_BuiltinAtomicsRTC_fmaxCoherentGlobalMem") {
void* config_d[] = {HIP_LAUNCH_PARAM_BUFFER_POINTER, &args_f,
HIP_LAUNCH_PARAM_BUFFER_SIZE,
&size, HIP_LAUNCH_PARAM_END};
hipModuleLaunchKernel(fmaxkernel, 1, 1, 1, 1, 1, 1, 0,
nullptr, nullptr, config_d);
HIP_CHECK(hipModuleLaunchKernel(fmaxkernel, 1, 1, 1, 1, 1, 1, 0,
nullptr, nullptr, config_d));
HIP_CHECK(hipDeviceSynchronize());
HIP_CHECK(hipMemcpy(B_h, result, sizeof(double), hipMemcpyDeviceToHost));
REQUIRE(*B_h == 0);
@@ -324,8 +324,8 @@ TEST_CASE("Unit_BuiltinAtomicsRTC_fmaxNonCoherentGlobalFlatMem") {
void* config_d[] = {HIP_LAUNCH_PARAM_BUFFER_POINTER, &args_f,
HIP_LAUNCH_PARAM_BUFFER_SIZE,
&size, HIP_LAUNCH_PARAM_END};
hipModuleLaunchKernel(fmaxkernel, 1, 1, 1, 1, 1, 1, 0,
nullptr, nullptr, config_d);
HIP_CHECK(hipModuleLaunchKernel(fmaxkernel, 1, 1, 1, 1, 1, 1, 0,
nullptr, nullptr, config_d));
HIP_CHECK(hipDeviceSynchronize());
HIP_CHECK(hipMemcpy(B_h, result, sizeof(double), hipMemcpyDeviceToHost));
REQUIRE(*B_h == INITIAL_VAL);
+4 -4
Просмотреть файл
@@ -230,8 +230,8 @@ TEST_CASE("Unit_BuiltinAtomicsRTC__fminCoherentGlobalMem") {
void* config_d[] = {HIP_LAUNCH_PARAM_BUFFER_POINTER, &args_f,
HIP_LAUNCH_PARAM_BUFFER_SIZE,
&size, HIP_LAUNCH_PARAM_END};
hipModuleLaunchKernel(fmaxkernel, 1, 1, 1, 1, 1, 1, 0,
nullptr, nullptr, config_d);
HIP_CHECK(hipModuleLaunchKernel(fmaxkernel, 1, 1, 1, 1, 1, 1, 0,
nullptr, nullptr, config_d));
HIP_CHECK(hipDeviceSynchronize());
HIP_CHECK(hipMemcpy(B_h, result, sizeof(double), hipMemcpyDeviceToHost));
REQUIRE(*B_h == 0);
@@ -327,8 +327,8 @@ TEST_CASE("Unit_BuiltinAtomicsRTC_fminNonCoherentGlobalFlatMem") {
void* config_d[] = {HIP_LAUNCH_PARAM_BUFFER_POINTER, &args_f,
HIP_LAUNCH_PARAM_BUFFER_SIZE,
&size, HIP_LAUNCH_PARAM_END};
hipModuleLaunchKernel(fmaxkernel, 1, 1, 1, 1, 1, 1, 0,
nullptr, nullptr, config_d);
HIP_CHECK(hipModuleLaunchKernel(fmaxkernel, 1, 1, 1, 1, 1, 1, 0,
nullptr, nullptr, config_d));
HIP_CHECK(hipDeviceSynchronize());
HIP_CHECK(hipMemcpy(B_h, result, sizeof(double), hipMemcpyDeviceToHost));
REQUIRE(*B_h == INITIAL_VAL);
+46
Просмотреть файл
@@ -1,3 +1,23 @@
# Copyright (c) 2023 Advanced Micro Devices, Inc. All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in
# all copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
# THE SOFTWARE.
# Common Tests - Test independent of all platforms
set(TEST_SRC
floatMath.cc
@@ -27,7 +47,26 @@ set(TEST_SRC
hipTestAtomicAdd.cc
hipStdComplex.cc
hipTestClock.cc
hip_trig.cc
hipDeviceMemcpy.cc
hipTestIncludeMath.cc
hipTestDotFunctions.cc
hipTestDeviceSymbol.cc
hipTestNew.cc
hipThreadFence.cc
hipTestDevice.cc
hipTestDeviceLimit.cc
hipTestDeviceDouble.cc
hipTestHost.cc
)
if(HIP_PLATFORM MATCHES "nvidia")
set_source_files_properties(hipTestHost.cc PROPERTIES COMPILE_OPTIONS "--expt-relaxed-constexpr")
endif()
if(UNIX)
set(TEST_SRC ${TEST_SRC}
deviceAllocation.cc)
endif()
# AMD only tests
set(AMD_TEST_SRC
@@ -38,6 +77,13 @@ set(AMD_TEST_SRC
floatTM.cc
hipMathFunctions.cc
hmax_hmin.cc
hipBfloat16.cc
hipVectorTypes.cc
hipTestHalf.cc
hipComplex.cc
hipTestFMA.cc
hipTestNativeHalf.cc
hip_test_make_type.cc
bfloat16.cc
)
set(AMD_ARCH_SPEC_TEST_SRC
+130
Просмотреть файл
@@ -0,0 +1,130 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANNTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip_test_common.hh>
#include <hip/hip_bfloat16.h>
#include <type_traits>
#include <random>
#include <climits>
#define SIZE 100
static std::random_device dev;
static std::mt19937 rng(dev());
inline float getRandomFloat(int16_t min = 10, int64_t max = LONG_MAX) {
std::uniform_real_distribution<float> gen(min, max);
return gen(rng);
}
__host__ __device__ bool testRelativeAccuracy(float a, hip_bfloat16 b) {
float c = static_cast<float>(b);
// float relative error should be less than 1/(2^7) since bfloat16
// has 7 bits mantissa.
if (fabs(c - a) / a <= 1.0 / 128) {
return true;
}
return false;
}
__host__ __device__ bool testOperations(const float &fa, const float &fb) {
bool testPass = true;
hip_bfloat16 bf_a(fa);
hip_bfloat16 bf_b(fb);
float fc = static_cast<float>(bf_a);
float fd = static_cast<float>(bf_b);
testPass &= testRelativeAccuracy(fa, bf_a);
testPass &= testRelativeAccuracy(fb, bf_b);
testPass &= testRelativeAccuracy(fc + fd, bf_a + bf_b);
// when checked as above for add, operation sub fails on GPU
if (hip_bfloat16(fc - fd) == (bf_a - bf_b)) {
testPass &= true;
}
testPass &= testRelativeAccuracy(fc * fd, bf_a * bf_b);
testPass &= testRelativeAccuracy(fc / fd, bf_a / bf_b);
hip_bfloat16 bf_x;
bf_x = bf_a;
bf_x++;
bf_x--;
++bf_x;
--bf_x;
// hip_bfloat16 is converted to float and then inc/decremented,
// hence check with reduced precision
testPass &= testRelativeAccuracy(bf_x, bf_a);
bf_x = bf_a;
bf_x += bf_b;
bf_x = bf_a;
bf_x -= bf_b;
bf_x = bf_a;
bf_x *= bf_b;
bf_x = bf_a;
bf_x /= bf_b;
hip_bfloat16 bf_rounded = hip_bfloat16::round_to_bfloat16(fa);
if (std::isnan(bf_rounded)) {
if (std::isnan(bf_rounded) || std::isinf(bf_rounded)) {
testPass &= true;
}
}
return testPass;
}
__global__ void testOperationsGPU(float* d_a, float* d_b, bool *testPass) {
int id = threadIdx.x;
if (id > SIZE) return;
float &a = d_a[id];
float &b = d_b[id];
*testPass = testOperations(a, b);
}
TEST_CASE("Unit_hipBfloat16") {
float *h_fa, *h_fb;
float *d_fa, *d_fb;
bool *d_fc, h_fc = false;
h_fa = new float[SIZE];
h_fb = new float[SIZE];
bool result = false;
for (int i = 0; i < SIZE; i++) {
h_fa[i] = getRandomFloat();
h_fb[i] = getRandomFloat();
result = testOperations(h_fa[i], h_fb[i]);
REQUIRE(result == true);
}
HIP_CHECK(hipMalloc(&d_fa, sizeof(float) * SIZE));
HIP_CHECK(hipMalloc(&d_fb, sizeof(float) * SIZE));
HIP_CHECK(hipMalloc(&d_fc, sizeof(bool)));
HIP_CHECK(hipMemcpy(d_fa, h_fa, sizeof(float) * SIZE, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(d_fb, h_fb, sizeof(float) * SIZE, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(d_fc, &h_fc, sizeof(bool), hipMemcpyHostToDevice));
hipLaunchKernelGGL(testOperationsGPU, 1, SIZE, 0, 0, d_fa, d_fb, d_fc);
HIP_CHECK(hipDeviceSynchronize());
HIP_CHECK(hipMemcpy(&h_fc, d_fc, sizeof(bool), hipMemcpyDeviceToHost));
REQUIRE(h_fc == true);
delete[] h_fa;
delete[] h_fb;
HIP_CHECK(hipFree(d_fa));
HIP_CHECK(hipFree(d_fb));
HIP_CHECK(hipFree(d_fc));
}
+438
Просмотреть файл
@@ -0,0 +1,438 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANNTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip_test_common.hh>
#include <hip/hip_complex.h>
#include <math.h>
#include <iostream>
#include <type_traits>
#define LEN 64
/* Comparing 2 floating point/double variables using floating point
precision. The precision is set at compile time using EPSILON. */
#define COMPARE_REALNUM(A, B, EPSILON) (fabs(A-B) < EPSILON)
enum ComplexFuncType {
COMPLEX_ADD,
COMPLEX_SUB,
COMPLEX_MUL,
COMPLEX_DIV,
COMPLEX_CONJ,
COMPLEX_REAL,
COMPLEX_IMAG,
COMPLEX_SQABS,
COMPLEX_ABS
};
__global__ static void testMakeComplexFunc(float* A, float* B,
hipFloatComplex* C) {
int tx = threadIdx.x + blockIdx.x * blockDim.x;
C[tx] = make_hipFloatComplex(A[tx], B[tx]);
}
__global__ static void testMakeComplexFunc(double* A, double* B,
hipDoubleComplex* C) {
int tx = threadIdx.x + blockIdx.x * blockDim.x;
C[tx] = make_hipDoubleComplex(A[tx], B[tx]);
}
__global__ static void testComplexMathFunc1(hipFloatComplex* A,
hipFloatComplex* B,
hipFloatComplex* C,
enum ComplexFuncType type) {
int tx = threadIdx.x + blockIdx.x * blockDim.x;
switch (type) {
case COMPLEX_ADD:
C[tx] = hipCaddf(A[tx], B[tx]);
break;
case COMPLEX_SUB:
C[tx] = hipCsubf(A[tx], B[tx]);
break;
case COMPLEX_MUL:
C[tx] = hipCmulf(A[tx], B[tx]);
break;
case COMPLEX_DIV:
C[tx] = hipCdivf(A[tx], B[tx]);
break;
case COMPLEX_CONJ:
C[tx] = hipConjf(A[tx]);
break;
default:
break;
}
}
__global__ static void testComplexMathFunc1(hipDoubleComplex* A,
hipDoubleComplex* B,
hipDoubleComplex* C,
enum ComplexFuncType type) {
int tx = threadIdx.x + blockIdx.x * blockDim.x;
switch (type) {
case COMPLEX_ADD:
C[tx] = hipCadd(A[tx], B[tx]);
break;
case COMPLEX_SUB:
C[tx] = hipCsub(A[tx], B[tx]);
break;
case COMPLEX_MUL:
C[tx] = hipCmul(A[tx], B[tx]);
break;
case COMPLEX_DIV:
C[tx] = hipCdiv(A[tx], B[tx]);
break;
case COMPLEX_CONJ:
C[tx] = hipConj(A[tx]);
break;
default:
break;
}
}
__global__ static void testComplexMathFunc2(hipFloatComplex* A,
float* B,
enum ComplexFuncType type) {
int tx = threadIdx.x + blockIdx.x * blockDim.x;
switch (type) {
case COMPLEX_REAL:
B[tx] = hipCrealf(A[tx]);
break;
case COMPLEX_IMAG:
B[tx] = hipCimagf(A[tx]);
break;
case COMPLEX_SQABS:
B[tx] = hipCsqabsf(A[tx]);
break;
case COMPLEX_ABS:
B[tx] = hipCabsf(A[tx]);
break;
default:
break;
}
}
__global__ static void testComplexMathFunc2(hipDoubleComplex* A,
double* B,
enum ComplexFuncType type) {
int tx = threadIdx.x + blockIdx.x * blockDim.x;
switch (type) {
case COMPLEX_REAL:
B[tx] = hipCreal(A[tx]);
break;
case COMPLEX_IMAG:
B[tx] = hipCimag(A[tx]);
break;
case COMPLEX_SQABS:
B[tx] = hipCsqabs(A[tx]);
break;
case COMPLEX_ABS:
B[tx] = hipCabs(A[tx]);
break;
default:
break;
}
}
/**
* Validates all hipComplex inline functions on device
* Functions validated are: make_hipDoubleComplex, make_hipFloatComplex
*/
template<typename T1, typename T2> bool test_makehipComplex_dev() {
T2 *A, *Ad, *B, *Bd;
T1 *C, *Cd;
bool TestPassed = true;
A = new T2[LEN];
B = new T2[LEN];
C = new T1[LEN];
for (uint32_t i = 0; i < LEN; i++) {
A[i] = 2*i*1.0;
B[i] = (2*i + 1)*1.0;
}
unsigned int size2 = LEN * sizeof(T2);
unsigned int size1 = LEN * sizeof(T1);
HIPCHECK(hipMalloc(reinterpret_cast<void**>(&Ad), size2));
HIPCHECK(hipMalloc(reinterpret_cast<void**>(&Bd), size2));
HIPCHECK(hipMalloc(reinterpret_cast<void**>(&Cd), size1));
HIPCHECK(hipMemcpy(Ad, A, size2, hipMemcpyHostToDevice));
HIPCHECK(hipMemcpy(Bd, B, size2, hipMemcpyHostToDevice));
hipLaunchKernelGGL(testMakeComplexFunc, dim3(1), dim3(LEN),
0, 0, Ad, Bd, Cd);
HIPCHECK(hipMemcpy(C, Cd, size1, hipMemcpyDeviceToHost));
// Validate the output of the kernel functions.
for (uint32_t i = 0; i < LEN; i++) {
if ((A[i] != C[i].x) || (B[i] != C[i].y)) {
TestPassed = false;
break;
}
}
HIPCHECK(hipFree(Cd));
HIPCHECK(hipFree(Bd));
HIPCHECK(hipFree(Ad));
delete[] C;
delete[] B;
delete[] A;
return TestPassed;
}
/**
* Validates all hipComplex inline functions on device
* Functions validated are: hipCaddf, hipCsubf, hipCmulf and hipCdivf
* hipCadd, hipCsub, hipCmul, hipCdiv
*/
template<typename T1, typename T2>
bool test_complexMathFunc1_dev(enum ComplexFuncType mathFuncType) {
T1 *A, *Ad, *B, *Bd;
T1 *C, *Cd;
bool TestPassed = true;
A = new T1[LEN];
B = new T1[LEN];
C = new T1[LEN];
for (uint32_t i = 0; i < LEN; i++) {
A[i].x = 2*i*1.0;
A[i].y = (2*i + 1)*1.0;
B[i].x = 2*i*1.0 + 0.5;
B[i].y = (2*i + 1)*1.0 + 0.5;
}
unsigned int size = LEN * sizeof(T1);
HIPCHECK(hipMalloc(reinterpret_cast<void**>(&Ad), size));
HIPCHECK(hipMalloc(reinterpret_cast<void**>(&Bd), size));
HIPCHECK(hipMalloc(reinterpret_cast<void**>(&Cd), size));
HIPCHECK(hipMemcpy(Ad, A, size, hipMemcpyHostToDevice));
HIPCHECK(hipMemcpy(Bd, B, size, hipMemcpyHostToDevice));
hipLaunchKernelGGL(testComplexMathFunc1, dim3(1), dim3(LEN),
0, 0, Ad, Bd, Cd, mathFuncType);
HIPCHECK(hipMemcpy(C, Cd, size, hipMemcpyDeviceToHost));
// Validate the output of the kernel functions.
T2 epsilon = 0.0001f;
T2 real, imag;
for (uint32_t i = 0; i < LEN; i++) {
if (mathFuncType == COMPLEX_ADD) {
real = (A[i].x + B[i].x);
imag = (A[i].y + B[i].y);
} else if (mathFuncType == COMPLEX_SUB) {
real = (A[i].x - B[i].x);
imag = (A[i].y - B[i].y);
} else if (mathFuncType == COMPLEX_MUL) {
real = (A[i].x*B[i].x - A[i].y*B[i].y);
imag = (A[i].y*B[i].x + A[i].x*B[i].y);
} else if (mathFuncType == COMPLEX_DIV) {
T2 sqabs = (B[i].x*B[i].x + B[i].y*B[i].y);
real = (A[i].x * B[i].x + A[i].y * B[i].y)/sqabs;
imag = (A[i].y * B[i].x - A[i].x * B[i].y)/sqabs;
} else if (mathFuncType == COMPLEX_CONJ) {
real = A[i].x;
imag = -A[i].y;
}
if (!COMPARE_REALNUM(real, C[i].x, epsilon) ||
!COMPARE_REALNUM(imag, C[i].y, epsilon)) {
TestPassed = false;
break;
}
}
HIPCHECK(hipFree(Cd));
HIPCHECK(hipFree(Bd));
HIPCHECK(hipFree(Ad));
delete[] C;
delete[] B;
delete[] A;
return TestPassed;
}
/**
* Validates all hipComplex inline functions on device
* Functions validated are: hipCrealf, hipCimagf, hipCsqabsf and hipCabsf
* hipCreal, hipCimag, hipCsqabs, hipCabs
*/
template<typename T1, typename T2>
bool test_complexMathFunc2_dev(enum ComplexFuncType mathFuncType) {
T1 *A, *Ad;
T2 *B, *Bd;
bool TestPassed = true;
A = new T1[LEN];
B = new T2[LEN];
for (uint32_t i = 0; i < LEN; i++) {
A[i].x = 2*i*1.0;
A[i].y = (2*i + 1)*1.0;
}
unsigned int size1 = LEN * sizeof(T1);
unsigned int size2 = LEN * sizeof(T2);
HIPCHECK(hipMalloc(reinterpret_cast<void**>(&Ad), size1));
HIPCHECK(hipMalloc(reinterpret_cast<void**>(&Bd), size2));
HIPCHECK(hipMemcpy(Ad, A, size1, hipMemcpyHostToDevice));
hipLaunchKernelGGL(testComplexMathFunc2, dim3(1), dim3(LEN),
0, 0, Ad, Bd, mathFuncType);
HIPCHECK(hipMemcpy(B, Bd, size2, hipMemcpyDeviceToHost));
// Validate the output of the kernel functions.
T2 epsilon = 0.0001f;
if (mathFuncType == COMPLEX_REAL) {
for (uint32_t i = 0; i < LEN; i++) {
if (!COMPARE_REALNUM(A[i].x, B[i], epsilon)) {
TestPassed = false;
break;
}
}
} else if (mathFuncType == COMPLEX_IMAG) {
for (uint32_t i = 0; i < LEN; i++) {
if (!COMPARE_REALNUM(A[i].y, B[i], epsilon)) {
TestPassed = false;
break;
}
}
} else if (mathFuncType == COMPLEX_SQABS) {
for (uint32_t i = 0; i < LEN; i++) {
T2 sqabs = A[i].x * A[i].x + A[i].y * A[i].y;
#ifdef __HIP_PLATFORM_NVCC__
/* Setting the Floating Point precision to 0.01 as this scenario
is failing on NVIDIA targets. */
epsilon = 0.01f;
#endif
if (!COMPARE_REALNUM(sqabs, B[i], epsilon)) {
TestPassed = false;
break;
}
}
} else if (mathFuncType == COMPLEX_ABS) {
for (uint32_t i = 0; i < LEN; i++) {
T2 sqabs = A[i].x * A[i].x + A[i].y * A[i].y;
if (!COMPARE_REALNUM(sqrtf(sqabs), B[i], epsilon)) {
TestPassed = false;
break;
}
}
}
HIPCHECK(hipFree(Bd));
HIPCHECK(hipFree(Ad));
delete[] B;
delete[] A;
return TestPassed;
}
// Validates all hipComplex inline functions on host
static bool test_allcomplexMathFunc_host() {
bool TestPassed = true;
float fa = 2.0, fb = 3.0;
hipFloatComplex fc = make_hipFloatComplex(fa, fb);
if ((fc.x != fa) || (fc.y != fb)) {
TestPassed &= false;
}
double da = 2.0, db = 3.0;
hipDoubleComplex dc = make_hipDoubleComplex(da, db);
if ((dc.x != da) || (dc.y != db)) {
TestPassed &= false;
}
hipFloatComplex fp, fq, fx;
fp.x = 2.0;
fp.y = 3.0;
fq.x = 4.0;
fq.y = 5.0;
fx = hipCaddf(fp, fq);
if ((fx.x != (fp.x + fq.x)) || (fx.y != (fp.y + fq.y))) {
TestPassed &= false;
}
fx = hipCsubf(fp, fq);
if ((fx.x != (fp.x - fq.x)) || (fx.y != (fp.y - fq.y))) {
TestPassed &= false;
}
fx = hipCmulf(fp, fq);
if ((fx.x != (fp.x*fq.x - fp.y*fq.y)) ||
(fx.y != (fp.y*fq.x + fp.x*fq.y))) {
TestPassed &= false;
}
fx = hipCdivf(fp, fq);
float fsqabs = fq.x*fq.x + fq.y*fq.y;
float epsilon = 0.0001f;
if ((!COMPARE_REALNUM(fx.x, (fp.x*fq.x + fp.y*fq.y)/fsqabs, epsilon)) ||
(!COMPARE_REALNUM(fx.y, (fp.y*fq.x - fp.x*fq.y)/fsqabs, epsilon))) {
TestPassed &= false;
}
if ((fp.x != hipCrealf(fp)) || (fp.y != hipCimagf(fp))) {
TestPassed &= false;
}
fx = hipConjf(fp);
if ((fx.x != fp.x) || (fx.y != -fp.y)) {
TestPassed &= false;
}
if (!COMPARE_REALNUM((fp.x*fp.x + fp.y*fp.y), hipCsqabsf(fp), epsilon)) {
TestPassed &= false;
}
if (!COMPARE_REALNUM(sqrtf(fp.x*fp.x + fp.y*fp.y), hipCabsf(fp), epsilon)) {
TestPassed &= false;
}
hipDoubleComplex dp, dq, dx;
dp.x = 2.0;
dp.y = 3.0;
dq.x = 4.0;
dq.y = 5.0;
dx = hipCadd(dp, dq);
if ((dx.x != (dp.x + dq.x)) || (dx.y != (dp.y + dq.y))) {
TestPassed &= false;
}
dx = hipCsub(dp, dq);
if ((dx.x != (dp.x - dq.x)) || (dx.y != (dp.y - dq.y))) {
TestPassed &= false;
}
dx = hipCmul(dp, dq);
if ((dx.x != (dp.x*dq.x - dp.y*dq.y)) ||
(dx.y != (dp.y*dq.x + dp.x*dq.y))) {
TestPassed &= false;
}
dx = hipCdiv(dp, dq);
float dsqabs = dq.x*dq.x + dq.y*dq.y;
if ((!COMPARE_REALNUM(dx.x, (dp.x*dq.x + dp.y*dq.y)/dsqabs, epsilon)) ||
(!COMPARE_REALNUM(dx.y, (dp.y*dq.x - dp.x*dq.y)/dsqabs, epsilon))) {
TestPassed &= false;
}
if ((dp.x != hipCreal(dp)) || (dp.y != hipCimag(dp))) {
TestPassed &= false;
}
dx = hipConj(dp);
if ((dx.x != dp.x) || (dx.y != -dp.y)) {
TestPassed &= false;
}
if (!COMPARE_REALNUM((dp.x*dp.x + dp.y*dp.y), hipCsqabs(dp), epsilon)) {
TestPassed &= false;
}
if (!COMPARE_REALNUM(sqrtf(dp.x*dp.x + dp.y*dp.y), hipCabs(dp), epsilon)) {
TestPassed &= false;
}
return TestPassed;
}
TEST_CASE("Unit_TestMathFuncComplex") {
bool TestPassed = false;
TestPassed = test_makehipComplex_dev<hipFloatComplex, float>() &&
test_makehipComplex_dev<float2, float>() &&
test_makehipComplex_dev<hipDoubleComplex, double>() &&
test_makehipComplex_dev<double2, double>() &&
test_complexMathFunc1_dev<hipFloatComplex, float>(COMPLEX_ADD) &&
test_complexMathFunc1_dev<hipDoubleComplex, double>(COMPLEX_ADD)
&& test_complexMathFunc1_dev<hipFloatComplex, float>(COMPLEX_SUB)
&& test_complexMathFunc1_dev<hipDoubleComplex, double>
(COMPLEX_SUB) && test_complexMathFunc1_dev<hipFloatComplex,
float>(COMPLEX_MUL) && test_complexMathFunc1_dev<hipDoubleComplex,
double>(COMPLEX_MUL) && test_complexMathFunc1_dev<hipFloatComplex,
float>(COMPLEX_DIV) && test_complexMathFunc1_dev<hipDoubleComplex,
double>(COMPLEX_DIV) && test_complexMathFunc1_dev<hipFloatComplex,
float>(COMPLEX_CONJ) && test_complexMathFunc1_dev<
hipDoubleComplex, double>(COMPLEX_CONJ) && test_complexMathFunc2_dev
<hipFloatComplex, float>(COMPLEX_REAL) && test_complexMathFunc2_dev
<hipDoubleComplex, double>(COMPLEX_REAL) && test_complexMathFunc2_dev
<hipFloatComplex, float>(COMPLEX_IMAG) && test_complexMathFunc2_dev
<hipDoubleComplex, double>(COMPLEX_IMAG) && test_complexMathFunc2_dev
<hipFloatComplex, float>(COMPLEX_SQABS) && test_complexMathFunc2_dev
<hipDoubleComplex, double>(COMPLEX_SQABS) && test_complexMathFunc2_dev
<hipFloatComplex, float>(COMPLEX_ABS) && test_complexMathFunc2_dev
<hipDoubleComplex, double>(COMPLEX_ABS) &&test_allcomplexMathFunc_host();
REQUIRE(TestPassed == true);
}
+60
Просмотреть файл
@@ -0,0 +1,60 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANNTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip_test_common.hh>
#define LEN 1024
#define SIZE (LEN << 2)
__global__ static void cpy(uint32_t* Out, uint32_t* In) {
int tx = threadIdx.x;
memcpy(Out + tx, In + tx, sizeof(uint32_t));
}
__global__ static void set(uint32_t* ptr, uint8_t val) {
int tx = threadIdx.x;
memset(ptr + tx, val, sizeof(uint32_t));
}
TEST_CASE("Unit_ToAndFroMemCpyToDevice") {
uint32_t *A, *Ad, *B, *Bd;
A = new uint32_t[LEN];
B = new uint32_t[LEN];
for (int i = 0; i < LEN; i++) {
A[i] = i;
B[i] = 0;
}
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Ad), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Bd), SIZE));
HIP_CHECK(hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice));
hipLaunchKernelGGL(cpy, dim3(1), dim3(LEN), 0, 0, Bd, Ad);
HIP_CHECK(hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost));
for (int i = LEN - 16; i < LEN; i++) {
REQUIRE(A[i] == B[i]);
}
hipLaunchKernelGGL(set, dim3(1), dim3(LEN), 0, 0, Bd, 0x1);
HIP_CHECK(hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost));
for (int i = LEN - 16; i < LEN; i++) {
REQUIRE(0x01010101 == B[i]);
}
delete[] A;
delete[] B;
}
+1
Просмотреть файл
@@ -22,6 +22,7 @@ THE SOFTWARE.
#include <hip_test_checkers.hh>
#include <complex>
#pragma clang diagnostic ignored "-Wunused-variable"
// Tolerance for error
const double tolerance = 1e-6;
+736
Просмотреть файл
@@ -0,0 +1,736 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANNTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip_test_common.hh>
#include <hip/math_functions.h>
#define N 512
#define SIZE (N * sizeof(float))
__global__ void test_sincosf(float* a, float* b, float* c) {
int tid = threadIdx.x;
sincosf(a[tid], b + tid, c + tid);
}
__global__ void test_sincospif(float* a, float* b, float* c) {
int tid = threadIdx.x;
sincospif(a[tid], b + tid, c + tid);
}
__global__ void test_fdividef(float* a, float* b, float* c) {
int tid = threadIdx.x;
c[tid] = fdividef(a[tid], b[tid]);
}
__global__ void test_llrintf(float* a, int64_t* b) {
int tid = threadIdx.x;
b[tid] = llrintf(a[tid]);
}
__global__ void test_lrintf(float* a, int64_t* b) {
int tid = threadIdx.x;
b[tid] = lrintf(a[tid]);
}
__global__ void test_rintf(float* a, float* b) {
int tid = threadIdx.x;
b[tid] = rintf(a[tid]);
}
__global__ void test_llroundf(float* a, int64_t* b) {
int tid = threadIdx.x;
b[tid] = llroundf(a[tid]);
}
__global__ void test_lroundf(float* a, int64_t* b) {
int tid = threadIdx.x;
b[tid] = lroundf(a[tid]);
}
__global__ void test_rhypotf(float* a, float* b, float* c) {
int tid = threadIdx.x;
c[tid] = rhypotf(a[tid], b[tid]);
}
__global__ void test_norm3df(float* a, float* b, float* c, float* d) {
int tid = threadIdx.x;
d[tid] = norm3df(a[tid], b[tid], c[tid]);
}
__global__ void test_norm4df(float* a, float* b, float* c, float* d, float* e) {
int tid = threadIdx.x;
e[tid] = norm4df(a[tid], b[tid], c[tid], d[tid]);
}
__global__ void test_normf(float* a, float* b) {
int tid = threadIdx.x;
b[tid] = normf(N, a);
}
__global__ void test_rnorm3df(float* a, float* b, float* c, float* d) {
int tid = threadIdx.x;
d[tid] = rnorm3df(a[tid], b[tid], c[tid]);
}
__global__ void test_rnorm4df(float* a, float* b, float* c, float* d,
float* e) {
int tid = threadIdx.x;
e[tid] = rnorm4df(a[tid], b[tid], c[tid], d[tid]);
}
__global__ void test_rnormf(float* a, float* b) {
int tid = threadIdx.x;
b[tid] = rnormf(N, a);
}
__global__ void test_erfinvf(float* a, float* b) {
int tid = threadIdx.x;
b[tid] = erff(erfinvf(a[tid]));
}
bool run_sincosf() {
float *A, *Ad, *B, *C, *Bd, *Cd;
A = new float[N];
B = new float[N];
C = new float[N];
for (int i = 0; i < N; i++) {
A[i] = 1.0f;
}
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Ad), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Bd), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Cd), SIZE));
HIP_CHECK(hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice));
hipLaunchKernelGGL(test_sincosf, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd);
HIP_CHECK(hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost));
HIP_CHECK(hipMemcpy(C, Cd, SIZE, hipMemcpyDeviceToHost));
int passed = 0;
for (int i = 0; i < 512; i++) {
if (B[i] == sinf(1.0f)) {
passed = 1;
}
}
passed = 0;
for (int i = 0; i < 512; i++) {
if (C[i] == cosf(1.0f)) {
passed = 1;
}
}
delete[] A;
delete[] B;
delete[] C;
HIP_CHECK(hipFree(Ad));
HIP_CHECK(hipFree(Bd));
HIP_CHECK(hipFree(Cd));
if (passed == 1) {
return true;
} else {
return false;
}
}
bool run_sincospif() {
float *A, *Ad, *B, *C, *Bd, *Cd;
A = new float[N];
B = new float[N];
C = new float[N];
for (int i = 0; i < N; i++) {
A[i] = 1.0f;
}
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Ad), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Bd), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Cd), SIZE));
HIP_CHECK(hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice));
hipLaunchKernelGGL(test_sincospif, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd);
HIP_CHECK(hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost));
HIP_CHECK(hipMemcpy(C, Cd, SIZE, hipMemcpyDeviceToHost));
int passed = 0;
for (int i = 0; i < 512; i++) {
if (B[i] - sinf(3.14 * 1.0f) < 0.1) {
passed = 1;
}
}
passed = 0;
for (int i = 0; i < 512; i++) {
if (C[i] - cosf(3.14 * 1.0f) < 0.1) {
passed = 1;
}
}
delete[] A;
delete[] B;
delete[] C;
HIP_CHECK(hipFree(Ad));
HIP_CHECK(hipFree(Bd));
HIP_CHECK(hipFree(Cd));
if (passed == 1) {
return true;
} else {
return false;
}
}
bool run_fdividef() {
float *A, *Ad, *B, *C, *Bd, *Cd;
A = new float[N];
B = new float[N];
C = new float[N];
for (int i = 0; i < N; i++) {
A[i] = 1.0f;
B[i] = 2.0f;
}
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Ad), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Bd), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Cd), SIZE));
HIP_CHECK(hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice));
hipLaunchKernelGGL(test_fdividef, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd);
HIP_CHECK(hipMemcpy(C, Cd, SIZE, hipMemcpyDeviceToHost));
int passed = 0;
for (int i = 0; i < 512; i++) {
if (C[i] == A[i] / B[i]) {
passed = 1;
}
}
delete[] A;
delete[] B;
delete[] C;
HIP_CHECK(hipFree(Ad));
HIP_CHECK(hipFree(Bd));
HIP_CHECK(hipFree(Cd));
if (passed == 1) {
return true;
} else {
return false;
}
}
bool run_llrintf() {
float *A, *Ad;
int64_t *B, *Bd;
A = new float[N];
B = new int64_t[N];
for (int i = 0; i < N; i++) {
A[i] = 1.345f;
}
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Ad), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Bd), N * sizeof(int64_t)));
HIP_CHECK(hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice));
hipLaunchKernelGGL(test_llrintf, dim3(1), dim3(N), 0, 0, Ad, Bd);
HIP_CHECK(hipMemcpy(B, Bd, N * sizeof(int64_t), hipMemcpyDeviceToHost));
int passed = 0;
for (int i = 0; i < 512; i++) {
int x = roundf(A[i]);
if (B[i] == x) {
passed = 1;
}
}
delete[] A;
delete[] B;
HIP_CHECK(hipFree(Ad));
HIP_CHECK(hipFree(Bd));
if (passed == 1) {
return true;
} else {
return false;
}
}
bool run_lrintf() {
float *A, *Ad;
int64_t *B, *Bd;
A = new float[N];
B = new int64_t[N];
for (int i = 0; i < N; i++) {
A[i] = 1.345f;
}
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Ad), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Bd), N * sizeof(int64_t)));
HIP_CHECK(hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice));
hipLaunchKernelGGL(test_lrintf, dim3(1), dim3(N), 0, 0, Ad, Bd);
HIP_CHECK(hipMemcpy(B, Bd, N * sizeof(int64_t), hipMemcpyDeviceToHost));
int passed = 0;
for (int i = 0; i < 512; i++) {
int x = roundf(A[i]);
if (B[i] == x) {
passed = 1;
}
}
delete[] A;
delete[] B;
HIP_CHECK(hipFree(Ad));
HIP_CHECK(hipFree(Bd));
if (passed == 1) {
return true;
} else {
return false;
}
}
bool run_rintf() {
float *A, *Ad;
float *B, *Bd;
A = new float[N];
B = new float[N];
for (int i = 0; i < N; i++) {
A[i] = 1.345f;
}
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Ad), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Bd), SIZE));
HIP_CHECK(hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice));
hipLaunchKernelGGL(test_rintf, dim3(1), dim3(N), 0, 0, Ad, Bd);
HIP_CHECK(hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost));
int passed = 0;
for (int i = 0; i < 512; i++) {
float x = roundf(A[i]);
if (B[i] == x) {
passed = 1;
}
}
delete[] A;
delete[] B;
HIP_CHECK(hipFree(Ad));
HIP_CHECK(hipFree(Bd));
if (passed == 1) {
return true;
} else {
return false;
}
}
bool run_llroundf() {
float *A, *Ad;
int64_t *B, *Bd;
A = new float[N];
B = new int64_t[N];
for (int i = 0; i < N; i++) {
A[i] = 1.345f;
}
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Ad), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Bd), N * sizeof(int64_t)));
HIP_CHECK(hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice));
hipLaunchKernelGGL(test_llroundf, dim3(1), dim3(N), 0, 0, Ad, Bd);
HIP_CHECK(hipMemcpy(B, Bd, N * sizeof(int64_t), hipMemcpyDeviceToHost));
int passed = 0;
for (int i = 0; i < 512; i++) {
int x = roundf(A[i]);
if (B[i] == x) {
passed = 1;
}
}
delete[] A;
delete[] B;
HIP_CHECK(hipFree(Ad));
HIP_CHECK(hipFree(Bd));
if (passed == 1) {
return true;
} else {
return false;
}
}
bool run_lroundf() {
float *A, *Ad;
int64_t *B, *Bd;
A = new float[N];
B = new int64_t[N];
for (int i = 0; i < N; i++) {
A[i] = 1.345f;
}
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Ad), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Bd), N * sizeof(int64_t)));
HIP_CHECK(hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice));
hipLaunchKernelGGL(test_lroundf, dim3(1), dim3(N), 0, 0, Ad, Bd);
HIP_CHECK(hipMemcpy(B, Bd, N * sizeof(int64_t), hipMemcpyDeviceToHost));
int passed = 0;
for (int i = 0; i < 512; i++) {
int x = roundf(A[i]);
if (B[i] == x) {
passed = 1;
}
}
delete[] A;
delete[] B;
HIP_CHECK(hipFree(Ad));
HIP_CHECK(hipFree(Bd));
if (passed == 1) {
return true;
} else {
return false;
}
}
bool run_norm3df() {
float *A, *Ad, *B, *Bd, *C, *Cd, *D, *Dd;
A = new float[N];
B = new float[N];
C = new float[N];
D = new float[N];
float val = 0.0f;
for (int i = 0; i < N; i++) {
A[i] = 1.0f;
B[i] = 2.0f;
C[i] = 3.0f;
}
val = sqrtf(1.0f + 4.0f + 9.0f);
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Ad), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Bd), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Cd), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Dd), SIZE));
HIP_CHECK(hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(Cd, C, SIZE, hipMemcpyHostToDevice));
hipLaunchKernelGGL(test_norm3df, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd, Dd);
HIP_CHECK(hipMemcpy(D, Dd, SIZE, hipMemcpyDeviceToHost));
int passed = 0;
for (int i = 0; i < 512; i++) {
if (D[i] - val < 0.000001) {
passed = 1;
}
}
delete[] A;
delete[] B;
delete[] C;
delete[] D;
HIP_CHECK(hipFree(Ad));
HIP_CHECK(hipFree(Bd));
HIP_CHECK(hipFree(Cd));
HIP_CHECK(hipFree(Dd));
if (passed == 1) {
return true;
} else {
return false;
}
}
bool run_norm4df() {
float *A, *Ad, *B, *Bd, *C, *Cd, *D, *Dd, *E, *Ed;
A = new float[N];
B = new float[N];
C = new float[N];
D = new float[N];
E = new float[N];
float val = 0.0f;
for (int i = 0; i < N; i++) {
A[i] = 1.0f;
B[i] = 2.0f;
C[i] = 3.0f;
D[i] = 4.0f;
}
val = sqrtf(1.0f + 4.0f + 9.0f + 16.0f);
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Ad), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Bd), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Cd), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Dd), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Ed), SIZE));
HIP_CHECK(hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(Cd, C, SIZE, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(Dd, D, SIZE, hipMemcpyHostToDevice));
hipLaunchKernelGGL(test_norm4df, dim3(1), dim3(N), 0, 0, Ad,
Bd, Cd, Dd, Ed);
HIP_CHECK(hipMemcpy(E, Ed, SIZE, hipMemcpyDeviceToHost));
int passed = 0;
for (int i = 0; i < 512; i++) {
if (E[i] - val < 0.000001) {
passed = 1;
}
}
delete[] A;
delete[] B;
delete[] C;
delete[] D;
delete[] E;
HIP_CHECK(hipFree(Ad));
HIP_CHECK(hipFree(Bd));
HIP_CHECK(hipFree(Cd));
HIP_CHECK(hipFree(Dd));
HIP_CHECK(hipFree(Ed));
if (passed == 1) {
return true;
} else {
return false;
}
}
bool run_normf() {
float *A, *Ad, *B, *Bd;
A = new float[N];
B = new float[N];
float val = 0.0f;
for (int i = 0; i < N; i++) {
A[i] = 1.0f;
B[i] = 0.0f;
val += 1.0f;
}
val = sqrtf(val);
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Ad), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Bd), SIZE));
HIP_CHECK(hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice));
hipLaunchKernelGGL(test_normf, dim3(1), dim3(N), 0, 0, Ad, Bd);
HIP_CHECK(hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost));
int passed = 0;
for (int i = 0; i < 512; i++) {
if (B[0] - val < 0.000001) {
passed = 1;
}
}
delete[] A;
delete[] B;
HIP_CHECK(hipFree(Ad));
HIP_CHECK(hipFree(Bd));
if (passed == 1) {
return true;
} else {
return false;
}
}
bool run_rhypotf() {
float *A, *Ad, *B, *Bd, *C, *Cd;
A = new float[N];
B = new float[N];
C = new float[N];
float val = 0.0f;
for (int i = 0; i < N; i++) {
A[i] = 1.0f;
B[i] = 2.0f;
}
val = 1 / sqrtf(1.0f + 4.0f);
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Ad), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Bd), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Cd), SIZE));
HIP_CHECK(hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice));
hipLaunchKernelGGL(test_rhypotf, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd);
HIP_CHECK(hipMemcpy(C, Cd, SIZE, hipMemcpyDeviceToHost));
int passed = 0;
for (int i = 0; i < 512; i++) {
if (C[i] - val < 0.000001) {
passed = 1;
}
}
delete[] A;
delete[] B;
delete[] C;
HIP_CHECK(hipFree(Ad));
HIP_CHECK(hipFree(Bd));
HIP_CHECK(hipFree(Cd));
if (passed == 1) {
return true;
} else {
return false;
}
}
bool run_rnorm3df() {
float *A, *Ad, *B, *Bd, *C, *Cd, *D, *Dd;
A = new float[N];
B = new float[N];
C = new float[N];
D = new float[N];
float val = 0.0f;
for (int i = 0; i < N; i++) {
A[i] = 1.0f;
B[i] = 2.0f;
C[i] = 3.0f;
}
val = 1 / sqrtf(1.0f + 4.0f + 9.0f);
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Ad), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Bd), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Cd), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Dd), SIZE));
HIP_CHECK(hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(Cd, C, SIZE, hipMemcpyHostToDevice));
hipLaunchKernelGGL(test_rnorm3df, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd, Dd);
HIP_CHECK(hipMemcpy(D, Dd, SIZE, hipMemcpyDeviceToHost));
int passed = 0;
for (int i = 0; i < 512; i++) {
if (D[i] - val < 0.000001) {
passed = 1;
}
}
delete[] A;
delete[] B;
delete[] C;
delete[] D;
HIP_CHECK(hipFree(Ad));
HIP_CHECK(hipFree(Bd));
HIP_CHECK(hipFree(Cd));
HIP_CHECK(hipFree(Dd));
if (passed == 1) {
return true;
} else {
return false;
}
}
bool run_rnorm4df() {
float *A, *Ad, *B, *Bd, *C, *Cd, *D, *Dd, *E, *Ed;
A = new float[N];
B = new float[N];
C = new float[N];
D = new float[N];
E = new float[N];
float val = 0.0f;
for (int i = 0; i < N; i++) {
A[i] = 1.0f;
B[i] = 2.0f;
C[i] = 3.0f;
D[i] = 4.0f;
}
val = 1 / sqrtf(1.0f + 4.0f + 9.0f + 16.0f);
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Ad), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Bd), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Cd), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Dd), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Ed), SIZE));
HIP_CHECK(hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(Cd, C, SIZE, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(Dd, D, SIZE, hipMemcpyHostToDevice));
hipLaunchKernelGGL(test_rnorm4df, dim3(1), dim3(N), 0, 0, Ad,
Bd, Cd, Dd, Ed);
HIP_CHECK(hipMemcpy(E, Ed, SIZE, hipMemcpyDeviceToHost));
int passed = 0;
for (int i = 0; i < 512; i++) {
if (E[i] - val < 0.000001) {
passed = 1;
}
}
delete[] A;
delete[] B;
delete[] C;
delete[] D;
delete[] E;
HIP_CHECK(hipFree(Ad));
HIP_CHECK(hipFree(Bd));
HIP_CHECK(hipFree(Cd));
HIP_CHECK(hipFree(Dd));
HIP_CHECK(hipFree(Ed));
if (passed == 1) {
return true;
} else {
return false;
}
}
bool run_rnormf() {
float *A, *Ad, *B, *Bd;
A = new float[N];
B = new float[N];
float val = 0.0f;
for (int i = 0; i < N; i++) {
A[i] = 1.0f;
B[i] = 0.0f;
val += 1.0f;
}
val = 1 / sqrtf(val);
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Ad), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Bd), SIZE));
HIP_CHECK(hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice));
hipLaunchKernelGGL(test_rnormf, dim3(1), dim3(N), 0, 0, Ad, Bd);
HIP_CHECK(hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost));
int passed = 0;
for (int i = 0; i < 512; i++) {
if (B[0] - val < 0.000001) {
passed = 1;
}
}
delete[] A;
delete[] B;
HIP_CHECK(hipFree(Ad));
HIP_CHECK(hipFree(Bd));
if (passed == 1) {
return true;
} else {
return false;
}
}
bool run_erfinvf() {
float *A, *Ad, *B, *Bd;
A = new float[N];
B = new float[N];
for (int i = 0; i < N; i++) {
A[i] = -0.6f;
B[i] = 0.0f;
}
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Ad), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Bd), SIZE));
HIP_CHECK(hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice));
hipLaunchKernelGGL(test_erfinvf, dim3(1), dim3(N), 0, 0, Ad, Bd);
HIP_CHECK(hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost));
int passed = 0;
for (int i = 0; i < 512; i++) {
if (B[i] - A[i] < 0.000001) {
passed = 1;
}
}
delete[] A;
delete[] B;
HIP_CHECK(hipFree(Ad));
HIP_CHECK(hipFree(Bd));
if (passed == 1) {
return true;
} else {
return false;
}
}
TEST_CASE("Unit_hipDeviceTrigFunc_Float") {
bool result = false;
result = run_sincosf() && run_sincospif() && run_fdividef() &&
run_llrintf() && run_norm3df() && run_norm4df() &&
run_normf() && run_rnorm3df() && run_rnorm4df() &&
run_rnormf() && run_lroundf() && run_llroundf() &&
run_rintf() && run_rhypotf() && run_erfinvf();
REQUIRE(result == true);
}
+629
Просмотреть файл
@@ -0,0 +1,629 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANNTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip_test_common.hh>
#include <hip/math_functions.h>
#define N 512
#define SIZE (N * sizeof(double))
__global__ void test_sincos(double* a, double* b, double* c) {
int tid = threadIdx.x;
sincos(a[tid], b + tid, c + tid);
}
__global__ void test_sincospi(double* a, double* b, double* c) {
int tid = threadIdx.x;
sincospi(a[tid], b + tid, c + tid);
}
__global__ void test_llrint(double* a, int64_t* b) {
int tid = threadIdx.x;
b[tid] = llrint(a[tid]);
}
__global__ void test_lrint(double* a, int64_t* b) {
int tid = threadIdx.x;
b[tid] = lrint(a[tid]);
}
__global__ void test_rint(double* a, double* b) {
int tid = threadIdx.x;
b[tid] = rint(a[tid]);
}
__global__ void test_llround(double* a, int64_t* b) {
int tid = threadIdx.x;
b[tid] = llround(a[tid]);
}
__global__ void test_lround(double* a, int64_t* b) {
int tid = threadIdx.x;
b[tid] = lround(a[tid]);
}
__global__ void test_rhypot(double* a, double* b, double* c) {
int tid = threadIdx.x;
c[tid] = rhypot(a[tid], b[tid]);
}
__global__ void test_norm3d(double* a, double* b, double* c, double* d) {
int tid = threadIdx.x;
d[tid] = norm3d(a[tid], b[tid], c[tid]);
}
__global__ void test_norm4d(double* a, double* b, double* c, double* d,
double* e) {
int tid = threadIdx.x;
e[tid] = norm4d(a[tid], b[tid], c[tid], d[tid]);
}
__global__ void test_rnorm3d(double* a, double* b, double* c, double* d) {
int tid = threadIdx.x;
d[tid] = rnorm3d(a[tid], b[tid], c[tid]);
}
__global__ void test_rnorm4d(double* a, double* b, double* c, double* d,
double* e) {
int tid = threadIdx.x;
e[tid] = rnorm4d(a[tid], b[tid], c[tid], d[tid]);
}
__global__ void test_rnorm(double* a, double* b) {
int tid = threadIdx.x;
b[tid] = rnorm(N, a);
}
__global__ void test_erfinv(double* a, double* b) {
int tid = threadIdx.x;
b[tid] = erf(erfinv(a[tid]));
}
bool run_sincos() {
double *A, *Ad, *B, *C, *Bd, *Cd;
A = new double[N];
B = new double[N];
C = new double[N];
for (int i = 0; i < N; i++) {
A[i] = 1.0;
}
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Ad), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Bd), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Cd), SIZE));
HIP_CHECK(hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice));
hipLaunchKernelGGL(test_sincos, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd);
HIP_CHECK(hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost));
HIP_CHECK(hipMemcpy(C, Cd, SIZE, hipMemcpyDeviceToHost));
int passed = 0;
for (int i = 0; i < 512; i++) {
if ((B[i] == sin(1.0)) && (C[i] == cos(1.0))) {
passed = 1;
}
}
delete[] A;
delete[] B;
delete[] C;
HIP_CHECK(hipFree(Ad));
HIP_CHECK(hipFree(Bd));
HIP_CHECK(hipFree(Cd));
if (passed == 1) {
return true;
}
return false;
}
bool run_sincospi() {
double *A, *Ad, *B, *C, *Bd, *Cd;
A = new double[N];
B = new double[N];
C = new double[N];
for (int i = 0; i < N; i++) {
A[i] = 1.0;
}
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Ad), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Bd), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Cd), SIZE));
HIP_CHECK(hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice));
hipLaunchKernelGGL(test_sincospi, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd);
HIP_CHECK(hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost));
HIP_CHECK(hipMemcpy(C, Cd, SIZE, hipMemcpyDeviceToHost));
int passed = 0;
for (int i = 0; i < 512; i++) {
if ((B[i] - sin(3.14 * 1.0) < 0.1) && (C[i] - cos(3.14 * 1.0) < 0.1)) {
passed = 1;
}
}
delete[] A;
delete[] B;
delete[] C;
HIP_CHECK(hipFree(Ad));
HIP_CHECK(hipFree(Bd));
HIP_CHECK(hipFree(Cd));
if (passed == 1) {
return true;
}
return false;
}
bool run_llrint() {
double *A, *Ad;
int64_t *B, *Bd;
A = new double[N];
B = new int64_t[N];
for (int i = 0; i < N; i++) {
A[i] = 1.345;
}
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Ad), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Bd),
N * sizeof(int64_t)));
HIP_CHECK(hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice));
hipLaunchKernelGGL(test_llrint, dim3(1), dim3(N), 0, 0, Ad, Bd);
HIP_CHECK(hipMemcpy(B, Bd, N * sizeof(int64_t),
hipMemcpyDeviceToHost));
int passed = 0;
for (int i = 0; i < 512; i++) {
int x = round(A[i]);
if (B[i] == x) {
passed = 1;
}
}
delete[] A;
delete[] B;
HIP_CHECK(hipFree(Ad));
HIP_CHECK(hipFree(Bd));
if (passed == 1) {
return true;
}
return false;
}
bool run_lrint() {
double *A, *Ad;
int64_t *B, *Bd;
A = new double[N];
B = new int64_t[N];
for (int i = 0; i < N; i++) {
A[i] = 1.345;
}
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Ad), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Bd), N * sizeof(int64_t)));
HIP_CHECK(hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice));
hipLaunchKernelGGL(test_lrint, dim3(1), dim3(N), 0, 0, Ad, Bd);
HIP_CHECK(hipMemcpy(B, Bd, N * sizeof(int64_t), hipMemcpyDeviceToHost));
int passed = 0;
for (int i = 0; i < 512; i++) {
int64_t x = round(A[i]);
if (B[i] == x) {
passed = 1;
}
}
delete[] A;
delete[] B;
HIP_CHECK(hipFree(Ad));
HIP_CHECK(hipFree(Bd));
if (passed == 1) {
return true;
}
return false;
}
bool run_rint() {
double *A, *Ad;
double *B, *Bd;
A = new double[N];
B = new double[N];
for (int i = 0; i < N; i++) {
A[i] = 1.345;
}
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Ad), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Bd), SIZE));
HIP_CHECK(hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice));
hipLaunchKernelGGL(test_rint, dim3(1), dim3(N), 0, 0, Ad, Bd);
HIP_CHECK(hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost));
int passed = 0;
for (int i = 0; i < 512; i++) {
double x = round(A[i]);
if (B[i] == x) {
passed = 1;
}
}
delete[] A;
delete[] B;
HIP_CHECK(hipFree(Ad));
HIP_CHECK(hipFree(Bd));
if (passed == 1) {
return true;
}
return false;
}
bool run_llround() {
double *A, *Ad;
int64_t *B, *Bd;
A = new double[N];
B = new int64_t[N];
for (int i = 0; i < N; i++) {
A[i] = 1.345;
}
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Ad), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Bd),
N * sizeof(int64_t)));
HIP_CHECK(hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice));
hipLaunchKernelGGL(test_llround, dim3(1), dim3(N), 0, 0, Ad, Bd);
HIP_CHECK(hipMemcpy(B, Bd, N * sizeof(int64_t),
hipMemcpyDeviceToHost));
int passed = 0;
for (int i = 0; i < 512; i++) {
int64_t x = round(A[i]);
if (B[i] == x) {
passed = 1;
}
}
delete[] A;
delete[] B;
HIP_CHECK(hipFree(Ad));
HIP_CHECK(hipFree(Bd));
if (passed == 1) {
return true;
}
return false;
}
bool run_lround() {
double *A, *Ad;
int64_t *B, *Bd;
A = new double[N];
B = new int64_t[N];
for (int i = 0; i < N; i++) {
A[i] = 1.345;
}
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Ad), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Bd), N * sizeof(int64_t)));
HIP_CHECK(hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice));
hipLaunchKernelGGL(test_lround, dim3(1), dim3(N), 0, 0, Ad, Bd);
HIP_CHECK(hipMemcpy(B, Bd, N * sizeof(int64_t), hipMemcpyDeviceToHost));
int passed = 0;
for (int i = 0; i < 512; i++) {
int64_t x = round(A[i]);
if (B[i] == x) {
passed = 1;
}
}
delete[] A;
delete[] B;
HIP_CHECK(hipFree(Ad));
HIP_CHECK(hipFree(Bd));
if (passed == 1) {
return true;
}
return false;
}
bool run_norm3d() {
double *A, *Ad, *B, *Bd, *C, *Cd, *D, *Dd;
A = new double[N];
B = new double[N];
C = new double[N];
D = new double[N];
double val = 0.0;
for (int i = 0; i < N; i++) {
A[i] = 1.0;
B[i] = 2.0;
C[i] = 3.0;
}
val = sqrt(1.0 + 4.0 + 9.0);
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Ad), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Bd), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Cd), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Dd), SIZE));
HIP_CHECK(hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(Cd, C, SIZE, hipMemcpyHostToDevice));
hipLaunchKernelGGL(test_norm3d, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd, Dd);
HIP_CHECK(hipMemcpy(D, Dd, SIZE, hipMemcpyDeviceToHost));
int passed = 0;
for (int i = 0; i < 512; i++) {
if (D[i] - val < 0.000001) {
passed = 1;
}
}
delete[] A;
delete[] B;
delete[] C;
delete[] D;
HIP_CHECK(hipFree(Ad));
HIP_CHECK(hipFree(Bd));
HIP_CHECK(hipFree(Cd));
HIP_CHECK(hipFree(Dd));
if (passed == 1) {
return true;
}
return false;
}
bool run_norm4d() {
double *A, *Ad, *B, *Bd, *C, *Cd, *D, *Dd, *E, *Ed;
A = new double[N];
B = new double[N];
C = new double[N];
D = new double[N];
E = new double[N];
double val = 0.0;
for (int i = 0; i < N; i++) {
A[i] = 1.0;
B[i] = 2.0;
C[i] = 3.0;
D[i] = 4.0;
}
val = sqrt(1.0 + 4.0 + 9.0 + 16.0);
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Ad), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Bd), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Cd), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Dd), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Ed), SIZE));
HIP_CHECK(hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(Cd, C, SIZE, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(Dd, D, SIZE, hipMemcpyHostToDevice));
hipLaunchKernelGGL(test_norm4d, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd, Dd, Ed);
HIP_CHECK(hipMemcpy(E, Ed, SIZE, hipMemcpyDeviceToHost));
int passed = 0;
for (int i = 0; i < 512; i++) {
if (E[i] - val < 0.000001) {
passed = 1;
}
}
delete[] A;
delete[] B;
delete[] C;
delete[] D;
delete[] E;
HIP_CHECK(hipFree(Ad));
HIP_CHECK(hipFree(Bd));
HIP_CHECK(hipFree(Cd));
HIP_CHECK(hipFree(Dd));
HIP_CHECK(hipFree(Ed));
if (passed == 1) {
return true;
}
return false;
}
bool run_rhypot() {
double *A, *Ad, *B, *Bd, *C, *Cd;
A = new double[N];
B = new double[N];
C = new double[N];
double val = 0.0;
for (int i = 0; i < N; i++) {
A[i] = 1.0;
B[i] = 2.0;
}
val = 1 / sqrt(1.0 + 4.0);
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Ad), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Bd), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Cd), SIZE));
HIP_CHECK(hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice));
hipLaunchKernelGGL(test_rhypot, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd);
HIP_CHECK(hipMemcpy(C, Cd, SIZE, hipMemcpyDeviceToHost));
int passed = 0;
for (int i = 0; i < 512; i++) {
if (C[i] - val < 0.000001) {
passed = 1;
}
}
delete[] A;
delete[] B;
delete[] C;
HIP_CHECK(hipFree(Ad));
HIP_CHECK(hipFree(Bd));
HIP_CHECK(hipFree(Cd));
if (passed == 1) {
return true;
}
return false;
}
bool run_rnorm3d() {
double *A, *Ad, *B, *Bd, *C, *Cd, *D, *Dd;
A = new double[N];
B = new double[N];
C = new double[N];
D = new double[N];
double val = 0.0;
for (int i = 0; i < N; i++) {
A[i] = 1.0;
B[i] = 2.0;
C[i] = 3.0;
}
val = 1 / sqrt(1.0 + 4.0 + 9.0);
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Ad), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Bd), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Cd), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Dd), SIZE));
HIP_CHECK(hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(Cd, C, SIZE, hipMemcpyHostToDevice));
hipLaunchKernelGGL(test_rnorm3d, dim3(1), dim3(N), 0, 0, Ad, Bd, Cd, Dd);
HIP_CHECK(hipMemcpy(D, Dd, SIZE, hipMemcpyDeviceToHost));
int passed = 0;
for (int i = 0; i < 512; i++) {
if (D[i] - val < 0.000001) {
passed = 1;
}
}
delete[] A;
delete[] B;
delete[] C;
delete[] D;
HIP_CHECK(hipFree(Ad));
HIP_CHECK(hipFree(Bd));
HIP_CHECK(hipFree(Cd));
HIP_CHECK(hipFree(Dd));
if (passed == 1) {
return true;
}
return false;
}
bool run_rnorm4d() {
double *A, *Ad, *B, *Bd, *C, *Cd, *D, *Dd, *E, *Ed;
A = new double[N];
B = new double[N];
C = new double[N];
D = new double[N];
E = new double[N];
double val = 0.0;
for (int i = 0; i < N; i++) {
A[i] = 1.0;
B[i] = 2.0;
C[i] = 3.0;
D[i] = 4.0;
}
val = 1 / sqrt(1.0 + 4.0 + 9.0 + 16.0);
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Ad), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Bd), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Cd), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Dd), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Ed), SIZE));
HIP_CHECK(hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(Cd, C, SIZE, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(Dd, D, SIZE, hipMemcpyHostToDevice));
hipLaunchKernelGGL(test_rnorm4d, dim3(1), dim3(N), 0, 0, Ad,
Bd, Cd, Dd, Ed);
HIP_CHECK(hipMemcpy(E, Ed, SIZE, hipMemcpyDeviceToHost));
int passed = 0;
for (int i = 0; i < 512; i++) {
if (E[i] - val < 0.000001) {
passed = 1;
}
}
delete[] A;
delete[] B;
delete[] C;
delete[] D;
delete[] E;
HIP_CHECK(hipFree(Ad));
HIP_CHECK(hipFree(Bd));
HIP_CHECK(hipFree(Cd));
HIP_CHECK(hipFree(Dd));
HIP_CHECK(hipFree(Ed));
if (passed == 1) {
return true;
}
return false;
}
bool run_rnorm() {
double *A, *Ad, *B, *Bd;
A = new double[N];
B = new double[N];
double val = 0.0;
for (int i = 0; i < N; i++) {
A[i] = 1.0;
B[i] = 0.0;
val += 1.0;
}
val = 1 / sqrt(val);
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Ad), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Bd), SIZE));
HIP_CHECK(hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice));
hipLaunchKernelGGL(test_rnorm, dim3(1), dim3(N), 0, 0, Ad, Bd);
HIP_CHECK(hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost));
int passed = 0;
for (int i = 0; i < 512; i++) {
if (B[0] - val < 0.000001) {
passed = 1;
}
}
delete[] A;
delete[] B;
HIP_CHECK(hipFree(Ad));
HIP_CHECK(hipFree(Bd));
if (passed == 1) {
return true;
}
return false;
}
bool run_erfinv() {
double *A, *Ad, *B, *Bd;
A = new double[N];
B = new double[N];
for (int i = 0; i < N; i++) {
A[i] = -0.6;
B[i] = 0.0;
}
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Ad), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Bd), SIZE));
HIP_CHECK(hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice));
hipLaunchKernelGGL(test_erfinv, dim3(1), dim3(N), 0, 0, Ad, Bd);
HIP_CHECK(hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost));
int passed = 0;
for (int i = 0; i < 512; i++) {
if (B[i] - A[i] < 0.000001) {
passed = 1;
}
}
delete[] A;
delete[] B;
HIP_CHECK(hipFree(Ad));
HIP_CHECK(hipFree(Bd));
if (passed == 1) {
return true;
}
return false;
}
TEST_CASE("Unit_hipTrigDeviceFunc_Double") {
bool result = false;
result = run_sincos() && run_sincospi() && run_llrint() &&
run_norm3d() && run_norm4d() && run_rnorm3d() &&
run_rnorm4d() && run_rnorm() && run_lround() && run_llround()
&& run_rint() && run_rhypot() && run_erfinv();
REQUIRE(result == true);
}
+24
Просмотреть файл
@@ -0,0 +1,24 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANNTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip_test_common.hh>
TEST_CASE("Unit_hipTestDeviceLimit_Basic") {
size_t heap;
HIP_CHECK(hipDeviceGetLimit(&heap, hipLimitMallocHeapSize));
REQUIRE(heap != 0);
}
+63 -62
Просмотреть файл
@@ -1,5 +1,5 @@
/*
Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
@@ -33,25 +33,32 @@ constexpr size_t SIZE = 1024 * 4;
__device__ int globalIn[NUM];
__device__ int globalOut[NUM];
__global__ void Assign(int* Out) {
__global__ static void Assign(int* Out) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
Out[tid] = globalIn[tid];
globalOut[tid] = globalIn[tid];
}
__device__ __constant__ int globalConst[NUM];
__device__ static __constant__ float statConstVar[NUM];
__global__ void checkAddress(int* addr, bool* out) { *out = (globalConst == addr); }
__global__ void checkAddress(int* addr, bool* out) {
*out = (globalConst == addr);
}
__global__ void checkStaticConstVarAddress(float* addr, bool* out) {
*out = (statConstVar == addr);
}
TEST_CASE("Unit_hipMemcpyToSymbolAsync_ToNFrom") {
int *A{nullptr}, *Am{nullptr}, *B{nullptr}, *Ad{nullptr}, *C{nullptr}, *Cm{nullptr};
int *A{nullptr}, *Am{nullptr}, *B{nullptr}, *Ad{nullptr},
*C{nullptr}, *Cm{nullptr};
A = new int[NUM];
B = new int[NUM];
C = new int[NUM];
HIP_CHECK(hipMalloc((void**)&Ad, SIZE));
HIP_CHECK(hipHostMalloc((void**)&Am, SIZE));
HIP_CHECK(hipHostMalloc((void**)&Cm, SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Ad), SIZE));
HIP_CHECK(hipHostMalloc(reinterpret_cast<void**>(&Am), SIZE));
HIP_CHECK(hipHostMalloc(reinterpret_cast<void**>(&Cm), SIZE));
for (size_t i = 0; i < NUM; i++) {
A[i] = -1 * static_cast<int>(i);
@@ -66,13 +73,14 @@ TEST_CASE("Unit_hipMemcpyToSymbolAsync_ToNFrom") {
hipStream_t stream{};
HIP_CHECK(hipStreamCreate(&stream));
HIP_CHECK(
hipMemcpyToSymbolAsync(HIP_SYMBOL(globalIn), Am, SIZE, 0, hipMemcpyHostToDevice, stream));
hipMemcpyToSymbolAsync(HIP_SYMBOL(globalIn), Am, SIZE, 0,
hipMemcpyHostToDevice, stream));
HIP_CHECK(hipStreamSynchronize(stream));
hipLaunchKernelGGL(Assign, dim3(1, 1, 1), dim3(NUM, 1, 1), 0, 0, Ad);
HIP_CHECK(hipGetLastError());
HIP_CHECK(hipGetLastError());
HIP_CHECK(hipMemcpy(B, Ad, SIZE, hipMemcpyDeviceToHost));
HIP_CHECK(hipMemcpyFromSymbolAsync(Cm, HIP_SYMBOL(globalOut), SIZE, 0, hipMemcpyDeviceToHost,
stream));
HIP_CHECK(hipMemcpyFromSymbolAsync(Cm, HIP_SYMBOL(globalOut), SIZE, 0,
hipMemcpyDeviceToHost, stream));
HIP_CHECK(hipStreamSynchronize(stream));
HIP_CHECK(hipStreamDestroy(stream));
for (size_t i = 0; i < NUM; i++) {
@@ -82,11 +90,13 @@ TEST_CASE("Unit_hipMemcpyToSymbolAsync_ToNFrom") {
}
SECTION("Calling hipMemcpyTo/FromSymbol - validate value in host memory") {
HIP_CHECK(hipMemcpyToSymbol(HIP_SYMBOL(globalIn), A, SIZE, 0, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpyToSymbol(HIP_SYMBOL(globalIn), A, SIZE, 0,
hipMemcpyHostToDevice));
hipLaunchKernelGGL(Assign, dim3(1, 1, 1), dim3(NUM, 1, 1), 0, 0, Ad);
HIP_CHECK(hipGetLastError());
HIP_CHECK(hipGetLastError());
HIP_CHECK(hipMemcpy(B, Ad, SIZE, hipMemcpyDeviceToHost));
HIP_CHECK(hipMemcpyFromSymbol(C, HIP_SYMBOL(globalOut), SIZE, 0, hipMemcpyDeviceToHost));
HIP_CHECK(hipMemcpyFromSymbol(C, HIP_SYMBOL(globalOut), SIZE, 0,
hipMemcpyDeviceToHost));
for (size_t i = 0; i < NUM; i++) {
REQUIRE(A[i] == B[i]);
@@ -98,13 +108,15 @@ TEST_CASE("Unit_hipMemcpyToSymbolAsync_ToNFrom") {
hipStream_t stream{};
HIP_CHECK(hipStreamCreate(&stream));
HIP_CHECK(
hipMemcpyToSymbolAsync(HIP_SYMBOL(globalIn), A, SIZE, 0, hipMemcpyHostToDevice, stream));
hipMemcpyToSymbolAsync(HIP_SYMBOL(globalIn), A, SIZE, 0,
hipMemcpyHostToDevice, stream));
HIP_CHECK(hipStreamSynchronize(stream));
hipLaunchKernelGGL(Assign, dim3(1, 1, 1), dim3(NUM, 1, 1), 0, 0, Ad);
HIP_CHECK(hipGetLastError());
HIP_CHECK(hipGetLastError());
HIP_CHECK(hipMemcpy(B, Ad, SIZE, hipMemcpyDeviceToHost));
HIP_CHECK(
hipMemcpyFromSymbolAsync(C, HIP_SYMBOL(globalOut), SIZE, 0, hipMemcpyDeviceToHost, stream));
hipMemcpyFromSymbolAsync(C, HIP_SYMBOL(globalOut), SIZE, 0,
hipMemcpyDeviceToHost, stream));
HIP_CHECK(hipStreamSynchronize(stream));
HIP_CHECK(hipStreamDestroy(stream));
@@ -115,14 +127,14 @@ TEST_CASE("Unit_hipMemcpyToSymbolAsync_ToNFrom") {
}
SECTION("Calling hipMemcpyTo/FromSymbol using hipStreamPerThread") {
HIP_CHECK(hipMemcpyToSymbolAsync(HIP_SYMBOL(globalIn), A, SIZE, 0, hipMemcpyHostToDevice,
hipStreamPerThread));
HIP_CHECK(hipMemcpyToSymbolAsync(HIP_SYMBOL(globalIn), A, SIZE, 0,
hipMemcpyHostToDevice, hipStreamPerThread));
HIP_CHECK(hipStreamSynchronize(hipStreamPerThread));
hipLaunchKernelGGL(Assign, dim3(1, 1, 1), dim3(NUM, 1, 1), 0, 0, Ad);
HIP_CHECK(hipGetLastError());
HIP_CHECK(hipGetLastError());
HIP_CHECK(hipMemcpy(B, Ad, SIZE, hipMemcpyDeviceToHost));
HIP_CHECK(hipMemcpyFromSymbolAsync(C, HIP_SYMBOL(globalOut), SIZE, 0, hipMemcpyDeviceToHost,
hipStreamPerThread));
HIP_CHECK(hipMemcpyFromSymbolAsync(C, HIP_SYMBOL(globalOut), SIZE, 0,
hipMemcpyDeviceToHost, hipStreamPerThread));
HIP_CHECK(hipStreamSynchronize(hipStreamPerThread));
for (size_t i = 0; i < NUM; i++) {
@@ -140,14 +152,18 @@ TEST_CASE("Unit_hipMemcpyToSymbolAsync_ToNFrom") {
size_t symbolSize = 0;
int* symbolAddress{nullptr};
HIP_CHECK(hipGetSymbolSize(&symbolSize, HIP_SYMBOL(globalConst)));
HIP_CHECK(hipGetSymbolAddress((void**)&symbolAddress, HIP_SYMBOL(globalConst)));
HIP_CHECK(hipMalloc((void**)&checkOkD, sizeof(bool)));
hipLaunchKernelGGL(checkAddress, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0, symbolAddress, checkOkD);
HIP_CHECK(hipGetLastError());
HIP_CHECK(hipMemcpy(&checkOk, checkOkD, sizeof(bool), hipMemcpyDeviceToHost));
HIP_CHECK(hipGetSymbolAddress(reinterpret_cast<void**>(&symbolAddress),
HIP_SYMBOL(globalConst)));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&checkOkD),
sizeof(bool)));
hipLaunchKernelGGL(checkAddress, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0,
symbolAddress, checkOkD);
HIP_CHECK(hipGetLastError());
HIP_CHECK(hipMemcpy(&checkOk, checkOkD, sizeof(bool),
hipMemcpyDeviceToHost));
HIP_CHECK(hipFree(checkOkD));
HIP_ASSERT(checkOk);
HIP_ASSERT((symbolSize == SIZE));
REQUIRE(checkOk);
REQUIRE((symbolSize == SIZE));
}
HIP_CHECK(hipHostFree(Am));
@@ -157,44 +173,29 @@ TEST_CASE("Unit_hipMemcpyToSymbolAsync_ToNFrom") {
delete[] B;
delete[] C;
}
/**
1) Validate get symbol address/size for global const array.
2) Validate get symbol address/size for static const variable.
*/
/*
1) Validate get symbol address/size for static const variable.
*/
TEST_CASE("Unit_hipGetSymbolAddressAndSize_Validation") {
bool* checkOkD{nullptr};
bool checkOk = false;
size_t symbolSize{};
int* symbolArrAddress{};
float* symbolVarAddress{};
SECTION("Validate symbol size/address of global const array") {
HIP_CHECK(hipGetSymbolSize(&symbolSize, HIP_SYMBOL(globalConstArr)));
HIP_CHECK(hipGetSymbolAddress(reinterpret_cast<void**>(&symbolArrAddress),
HIP_SYMBOL(globalConstArr)));
HIP_CHECK(hipMalloc(&checkOkD, sizeof(bool)));
hipLaunchKernelGGL(checkGlobalConstAddress, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0,
symbolArrAddress, checkOkD);
HIP_CHECK(hipGetLastError());
HIP_CHECK(hipMemcpy(&checkOk, checkOkD, sizeof(bool), hipMemcpyDeviceToHost));
HIP_CHECK(hipFree(checkOkD));
HIP_ASSERT(checkOk);
HIP_ASSERT(symbolSize == SIZE);
}
SECTION("Validate symbol size/address of static const variable") {
HIP_CHECK(hipGetSymbolSize(&symbolSize, HIP_SYMBOL(statConstVar)));
HIP_CHECK(
hipGetSymbolAddress(reinterpret_cast<void**>(&symbolVarAddress), HIP_SYMBOL(statConstVar)));
hipGetSymbolAddress(reinterpret_cast<void**>(&symbolVarAddress),
HIP_SYMBOL(statConstVar)));
HIP_CHECK(hipMalloc(&checkOkD, sizeof(bool)));
hipLaunchKernelGGL(checkStaticConstVarAddress, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0,
symbolVarAddress, checkOkD);
HIP_CHECK(hipGetLastError());
HIP_CHECK(hipMemcpy(&checkOk, checkOkD, sizeof(bool), hipMemcpyDeviceToHost));
hipLaunchKernelGGL(checkStaticConstVarAddress, dim3(1, 1, 1),
dim3(1, 1, 1), 0, 0, symbolVarAddress, checkOkD);
HIP_CHECK(hipGetLastError());
HIP_CHECK(hipMemcpy(&checkOk, checkOkD, sizeof(bool),
hipMemcpyDeviceToHost));
HIP_CHECK(hipFree(checkOkD));
HIP_ASSERT(checkOk);
HIP_ASSERT(symbolSize == sizeof(float));
REQUIRE(checkOk);
REQUIRE(symbolSize == SIZE);
}
}
@@ -202,15 +203,14 @@ TEST_CASE("Unit_hipGetSymbolAddress_Negative") {
SECTION("Invalid symbol") {
int notADeviceSymbol{0};
int* addr{nullptr};
HIP_CHECK_ERROR(
hipGetSymbolAddress(reinterpret_cast<void**>(&addr), HIP_SYMBOL(notADeviceSymbol)),
hipErrorInvalidSymbol);
HIP_CHECK_ERROR(hipGetSymbolAddress(reinterpret_cast<void**>(&addr),
HIP_SYMBOL(notADeviceSymbol)), hipErrorInvalidSymbol);
}
SECTION("Nullptr symbol") {
int* addr{nullptr};
HIP_CHECK_ERROR(hipGetSymbolAddress(reinterpret_cast<void**>(&addr), nullptr),
hipErrorInvalidSymbol);
HIP_CHECK_ERROR(hipGetSymbolAddress(reinterpret_cast<void**>(&addr),
nullptr), hipErrorInvalidSymbol);
}
}
@@ -218,7 +218,8 @@ TEST_CASE("Unit_hipGetSymbolSize_Negative") {
SECTION("Invalid symbol") {
int notADeviceSymbol{0};
size_t dsize{0};
HIP_CHECK_ERROR(hipGetSymbolSize(&dsize, HIP_SYMBOL(notADeviceSymbol)), hipErrorInvalidSymbol);
HIP_CHECK_ERROR(hipGetSymbolSize(&dsize, HIP_SYMBOL(notADeviceSymbol)),
hipErrorInvalidSymbol);
}
SECTION("Nullptr symbol") {
+54
Просмотреть файл
@@ -0,0 +1,54 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANNTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip/hip_runtime.h>
#include <hip/math_functions.h>
#include <hip_test_common.hh>
__global__ static void DotFunctions(bool* result) {
// Dot Functions
#if HT_AMD
short2 sa{1}, sb{1};
result[0] = amd_mixed_dot(sa, sb, 1, result[0]) && result[0];
ushort2 usa{1}, usb{1};
result[0] = amd_mixed_dot(usa, usb, (uint) 1, result[0]) && result[0];
char4 ca{1}, cb{1};
result[0] = amd_mixed_dot(ca, cb, 1, result[0]) && result[0];
uchar4 uca{1}, ucb{1};
result[0] = amd_mixed_dot(uca, ucb, (uint) 1, result[0]) && result[0];
int ia{1}, ib{1};
result[0] = amd_mixed_dot(ia, ib, 1, result[0]) && result[0];
uint ua{1}, ub{1};
result[0] = amd_mixed_dot(ua, ub, (uint) 1, result[0]) && result[0];
#endif
}
TEST_CASE("Unit_hipTestDotFunctions") {
bool* result{nullptr};
HIP_CHECK(hipHostMalloc(&result, 1));
result[0] = true;
hipLaunchKernelGGL(DotFunctions, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0, result);
HIP_CHECK(hipDeviceSynchronize());
REQUIRE(result[0] == true);
HIP_CHECK(hipHostFree(result));
}
+183
Просмотреть файл
@@ -0,0 +1,183 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANNTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip_test_common.hh>
#include <iostream>
#define LEN 50
#define SIZE (LEN * sizeof(bool))
__global__ void kernelTestFMA(bool *Ad) {
float f = 1.0f / 3.0f;
double d = f;
int i = 0;
auto Check = [&](bool Cond) { Ad[i++] = Cond; };
// f * f + 3.0f will be different if promoted to double.
float floatResult = fma(f, f, 3.0f);
double doubleResult = fma(d, d, 3.0);
Check(floatResult != doubleResult);
if (sizeof(decltype(fma(f, f, 3))) == 8) {
// To align with libcxx, if any argument has integral type,
// it is cast to double.
// Check type promotes to double.
Check(fma(f, f, 3) == doubleResult);
Check(fma(f, f, static_cast<char>(3)) == doubleResult);
Check(fma(f, f, (unsigned char)3) == doubleResult);
Check(fma(f, f, (int32_t)3) == doubleResult);
Check(fma(f, f, (uint32_t)3) == doubleResult);
Check(fma(f, f, static_cast<int>(3)) == doubleResult);
Check(fma(f, f, (unsigned int)3) == doubleResult);
Check(fma(f, f, (int64_t)3) == doubleResult);
Check(fma(f, f, (uint64_t)3) == doubleResult);
Check(fma(f, f, true) == fma(static_cast<double>(f),
static_cast<double>(f), 1.0));
} else if (sizeof(decltype(fma(f, f, 3))) == 4) {
// Previous HIP headers returns float type.
// Delete this to support backwards compatibility.
// check promote to float.
Check(fma(f, f, 3) == floatResult);
Check(fma(f, f, static_cast<char>(3)) == floatResult);
Check(fma(f, f, (unsigned char)3) == floatResult);
Check(fma(f, f, (int32_t)3) == floatResult);
Check(fma(f, f, (uint32_t)3) == floatResult);
Check(fma(f, f, static_cast<int>(3)) == floatResult);
Check(fma(f, f, (unsigned int)3) == floatResult);
Check(fma(f, f, (int64_t)3) == floatResult);
Check(fma(f, f, (uint64_t)3) == floatResult);
Check(fma(f, f, true) == fma(f, f, 1.0f));
} else {
Check(false);
}
Check(fma(d, static_cast<double>(f), 3) == doubleResult);
Check(fma(d, static_cast<double>(f), static_cast<char>(3)) == doubleResult);
Check(fma(d, static_cast<double>(f), (unsigned char)3) == doubleResult);
Check(fma(d, static_cast<double>(f), (int32_t)3) == doubleResult);
Check(fma(d, static_cast<double>(f), (uint32_t)3) == doubleResult);
Check(fma(d, static_cast<double>(f), static_cast<int>(3)) == doubleResult);
Check(fma(d, static_cast<double>(f), (unsigned int)3) == doubleResult);
Check(fma(d, static_cast<double>(f), (int64_t)3) == doubleResult);
Check(fma(d, static_cast<double>(f), (int64_t)3) == doubleResult);
Check(fma(d, static_cast<double>(f), true) ==
fma(static_cast<double>(f), static_cast<double>(f), 1.0));
while (i < LEN)
Check(true);
}
void runTestFMA() {
bool *Ad;
bool A[LEN];
for (unsigned i = 0; i < LEN; i++) {
A[i] = 0;
}
HIP_CHECK(hipMalloc(reinterpret_cast<void **>(&Ad), SIZE));
hipLaunchKernelGGL(kernelTestFMA, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0, Ad);
HIP_CHECK(hipMemcpy(A, Ad, SIZE, hipMemcpyDeviceToHost));
for (unsigned i = 0; i < LEN; i++) {
REQUIRE(A[i] == true);
}
}
__global__ void kernelTestHalfFMA(bool *Ad) {
_Float16 h = (_Float16)(1.0f/3.0f);
float f = h;
double d = f;
int i = 0;
auto Check = [&](bool Cond) { Ad[i++] = Cond; };
// h * h + 3 will be different if promoted to float.
_Float16 halfResult = fma(h, h, (_Float16)3);
float floatResult = fma(f, f, 3.0f);
double doubleResult = fma(d, d, 3.0);
Check(halfResult != floatResult);
Check(halfResult != doubleResult);
// check promote to half.
// fma(_Float16, _Float16, int) should resolve to
// fma(double, double, double). This is similar to
// fma(float, float, int) resolving to fma(double, double, double)
// as required Standard C++ header <cmath>.
if (sizeof(decltype(fma(h, h, 3))) == 8) {
Check(fma(h, h, 3) == doubleResult);
Check(fma(h, h, static_cast<char>(3)) == doubleResult);
Check(fma(h, h, (unsigned char)3) == doubleResult);
Check(fma(h, h, (int32_t)3) == doubleResult);
Check(fma(h, h, (uint32_t)3) == doubleResult);
Check(fma(h, h, static_cast<int>(3)) == doubleResult);
Check(fma(h, h, (unsigned int)3) == doubleResult);
Check(fma(h, h, (int64_t)3) == doubleResult);
Check(fma(h, h, (uint64_t)3) == doubleResult);
Check(fma(h, h, true) == fma(static_cast<double>(h),
static_cast<double>(h), 1.0));
} else if (sizeof(decltype(fma(h, h, 3))) == 2) {
// ToDo: Currently there is a bug in clang header
// __clang_hip_cmath.h due to using
// std::numeric_limits<T>::is_specified to define
// overloaded math functions. Since numeric_limits is
// not specicialized for _Float16, overloaded template
// functions with argument promotion are not defined
// for _Float16. As a result, fma(_Float16, _Float16, int)
// is resolved to fma(_Float16, _Float16, _Float16).
// This part should be removed after __clang_hip_cmath.h
// is fixed.
Check(fma(h, h, 3) == halfResult);
Check(fma(h, h, static_cast<char>(3)) == halfResult);
Check(fma(h, h, (unsigned char)3) == halfResult);
Check(fma(h, h, (int32_t)3) == halfResult);
Check(fma(h, h, (uint32_t)3) == halfResult);
Check(fma(h, h, static_cast<int>(3)) == halfResult);
Check(fma(h, h, (unsigned int)3) == halfResult);
Check(fma(h, h, (int64_t)3) == halfResult);
Check(fma(h, h, (int64_t)3) == halfResult);
Check(fma(h, h, true) == fma(h, h, (_Float16)1));
} else {
Check(false);
}
while (i < LEN)
Check(true);
}
void runTestHalfFMA() {
bool *Ad;
bool A[LEN];
for (unsigned i = 0; i < LEN; i++) {
A[i] = 0;
}
HIP_CHECK(hipMalloc(reinterpret_cast<void **>(&Ad), SIZE));
hipLaunchKernelGGL(kernelTestHalfFMA, dim3(1, 1, 1), dim3(1, 1, 1),
0, 0, Ad);
HIP_CHECK(hipMemcpy(A, Ad, SIZE, hipMemcpyDeviceToHost));
for (unsigned i = 0; i < LEN; i++) {
REQUIRE(A[i] == true);
}
}
TEST_CASE("Unit_hipTestFMA") {
SECTION("test FMA") {
runTestFMA();
}
SECTION("test HalfFMA") {
runTestHalfFMA();
}
}
+248
Просмотреть файл
@@ -0,0 +1,248 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANNTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip/hip_fp16.h>
#include <hip_test_common.hh>
#pragma clang diagnostic ignored "-Wunused-variable"
#pragma clang diagnostic ignored "-Wunused-parameter"
__device__ void test_convert() {
__half x;
float y = static_cast<float>(x);
}
__global__
void __halfMath(bool* result, __half a) {
result[0] = __heq(__hadd(a, __half{1}), __half{2});
result[0] = __heq(__hadd_sat(a, __half{1}), __half{1}) && result[0];
result[0] = __heq(__hfma(a, __half{2}, __half{3}), __half{5}) && result[0];
result[0] =
__heq(__hfma_sat(a, __half{2}, __half{3}), __half{1}) && result[0];
result[0] = __heq(__hsub(a, __half{1}), __half{0}) && result[0];
result[0] = __heq(__hsub_sat(a, __half{2}), __half{0}) && result[0];
result[0] = __heq(__hmul(a, __half{2}), __half{2}) && result[0];
result[0] = __heq(__hmul_sat(a, __half{2}), __half{1}) && result[0];
result[0] = __heq(__hdiv(a, __half{2}), __half{0.5}) && result[0];
}
__device__
bool to_bool(const __half2& x) {
auto r = static_cast<const __half2_raw&>(x);
return r.data.x != 0 && r.data.y != 0;
}
__global__
void __half2Math(bool* result, __half2 a) {
result[0] =
to_bool(__heq2(__hadd2(a, __half2{1, 1}), __half2{2, 2}));
result[0] = to_bool(__heq2(__hadd2_sat(a, __half2{1, 1}), __half2{1, 1})) &&
result[0];
result[0] = to_bool(__heq2(
__hfma2(a, __half2{2, 2}, __half2{3, 3}), __half2{5, 5})) && result[0];
result[0] = to_bool(__heq2(
__hfma2_sat(a, __half2{2, 2}, __half2{3, 3}), __half2{1, 1})) && result[0];
result[0] = to_bool(__heq2(__hsub2(a, __half2{1, 1}), __half2{0, 0})) &&
result[0];
result[0] = to_bool(__heq2(__hsub2_sat(a, __half2{2, 2}), __half2{0, 0})) &&
result[0];
result[0] = to_bool(__heq2(__hmul2(a, __half2{2, 2}), __half2{2, 2})) &&
result[0];
result[0] = to_bool(__heq2(__hmul2_sat(a, __half2{2, 2}), __half2{1, 1})) &&
result[0];
result[0] = to_bool(__heq2(__h2div(a, __half2{2, 2}), __half2{0.5, 0.5})) &&
result[0];
}
__global__
void kernel_hisnan(__half* input, int* output) {
int tx = threadIdx.x;
output[tx] = __hisnan(input[tx]);
}
__global__
void kernel_hisinf(__half* input, int* output) {
int tx = threadIdx.x;
output[tx] = __hisinf(input[tx]);
}
__global__ void testHalfAbs(float* p) {
auto a = __float2half(*p);
a = __habs(a);
*p = __half2float(a);
}
__global__ void testHalf2Abs(float2* p) {
auto a = __float22half2_rn(*p);
a = __habs2(a);
*p = __half22float2(a);
}
__half host_ushort_as_half(uint32_t s) {
union {__half h; uint32_t s; } converter;
converter.s = s;
return converter.h;
}
void check_hisnan(int NUM_INPUTS, __half* inputCPU, __half* inputGPU) {
// allocate memory
auto memsize = NUM_INPUTS * sizeof(int);
int* outputGPU = nullptr;
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&outputGPU), memsize));
// launch the kernel
hipLaunchKernelGGL(
kernel_hisnan, dim3(1), dim3(NUM_INPUTS), 0, 0, inputGPU, outputGPU);
// copy output from device
int* outputCPU = reinterpret_cast<int*> (malloc(memsize));
HIP_CHECK(hipMemcpy(outputCPU, outputGPU, memsize, hipMemcpyDeviceToHost));
// check output
for (int i=0; i < NUM_INPUTS; i++) {
if ((2 <= i) && (i <= 5)) { // inputs are nan, output should be true
REQUIRE(outputCPU[i] == true);
} else { // inputs are NOT nan, output should be false
REQUIRE(outputCPU[i] == false);
}
}
// free memory
free(outputCPU);
HIP_CHECK(hipFree(outputGPU));
}
void check_hisinf(int NUM_INPUTS, __half* inputCPU, __half* inputGPU) {
// allocate memory
auto memsize = NUM_INPUTS * sizeof(int);
int* outputGPU = nullptr;
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&outputGPU), memsize));
// launch the kernel
hipLaunchKernelGGL(
kernel_hisinf, dim3(1), dim3(NUM_INPUTS), 0, 0, inputGPU, outputGPU);
// copy output from device
int* outputCPU = reinterpret_cast<int*> (malloc(memsize));
HIP_CHECK(hipMemcpy(outputCPU, outputGPU, memsize, hipMemcpyDeviceToHost));
// check output
for (int i=0; i < NUM_INPUTS; i++) {
if ((0 <= i) && (i <= 1)) { // inputs are inf, output should be true
REQUIRE(outputCPU[i] == true);
} else { // inputs are NOT inf, output should be false
REQUIRE(outputCPU[i] == false);
}
}
// free memory
free(outputCPU);
HIP_CHECK(hipFree(outputGPU));
}
void checkFunctional() {
// allocate memory
const int NUM_INPUTS = 16;
auto memsize = NUM_INPUTS * sizeof(__half);
__half* inputCPU = reinterpret_cast<__half*> (malloc(memsize));
// populate inputs
inputCPU[0] = host_ushort_as_half(0x7c00); // inf
inputCPU[1] = host_ushort_as_half(0xfc00); // -inf
inputCPU[2] = host_ushort_as_half(0x7c01); // nan
inputCPU[3] = host_ushort_as_half(0x7e00); // nan
inputCPU[4] = host_ushort_as_half(0xfc01); // nan
inputCPU[5] = host_ushort_as_half(0xfe00); // nan
inputCPU[6] = host_ushort_as_half(0x0000); // 0
inputCPU[7] = host_ushort_as_half(0x8000); // -0
inputCPU[8] = host_ushort_as_half(0x7bff); // max +ve normal
inputCPU[9] = host_ushort_as_half(0xfbff); // max -ve normal
inputCPU[10] = host_ushort_as_half(0x0400); // min +ve normal
inputCPU[11] = host_ushort_as_half(0x8400); // min -ve normal
inputCPU[12] = host_ushort_as_half(0x03ff); // max +ve sub-normal
inputCPU[13] = host_ushort_as_half(0x83ff); // max -ve sub-normal
inputCPU[14] = host_ushort_as_half(0x0001); // min +ve sub-normal
inputCPU[15] = host_ushort_as_half(0x8001); // min -ve sub-normal
// copy inputs to the GPU
__half* inputGPU = nullptr;
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&inputGPU), memsize));
HIP_CHECK(hipMemcpy(inputGPU, inputCPU, memsize, hipMemcpyHostToDevice));
// run checks
check_hisnan(NUM_INPUTS, inputCPU, inputGPU);
check_hisinf(NUM_INPUTS, inputCPU, inputGPU);
// free memory
HIP_CHECK(hipFree(inputGPU));
free(inputCPU);
}
void checkHalfAbs() {
SECTION("Half Abs") {
float *p;
HIP_CHECK(hipMalloc(&p, sizeof(float)));
float pp = -2.1f;
HIP_CHECK(hipMemcpy(p, &pp, sizeof(float), hipMemcpyDefault));
hipLaunchKernelGGL(testHalfAbs, 1, 1, 0, 0, p);
HIP_CHECK(hipMemcpy(&pp, p, sizeof(float), hipMemcpyDefault));
HIP_CHECK(hipFree(p));
REQUIRE(pp >= 0.0f);
}
SECTION("Half2 Abs") {
float2 *p;
HIP_CHECK(hipMalloc(&p, sizeof(float2)));
float2 pp;
pp.x = -2.1f;
pp.y = -1.1f;
HIP_CHECK(hipMemcpy(p, &pp, sizeof(float2), hipMemcpyDefault));
hipLaunchKernelGGL(testHalf2Abs, 1, 1, 0, 0, p);
HIP_CHECK(hipMemcpy(&pp, p, sizeof(float2), hipMemcpyDefault));
HIP_CHECK(hipFree(p));
bool result = true;
if (pp.x < 0.0f || pp.y < 0.0f) { result = false; }
REQUIRE(result == true);
}
}
TEST_CASE("Unit_hipTestHalf") {
bool* result{nullptr};
HIP_CHECK(hipHostMalloc(&result, sizeof(result)));
SECTION("Test half math") {
result[0] = false;
hipLaunchKernelGGL(
__halfMath, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0, result, __half{1});
HIP_CHECK(hipDeviceSynchronize());
REQUIRE(result[0] == true);
}
SECTION("Test half math") {
result[0] = false;
hipLaunchKernelGGL(
__half2Math, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0, result, __half2{1, 1});
HIP_CHECK(hipDeviceSynchronize());
REQUIRE(result[0] == true);
}
SECTION("Functional checks") {
checkFunctional();
checkHalfAbs();
}
HIP_CHECK(hipHostFree(result));
}
+402
Просмотреть файл
@@ -0,0 +1,402 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANNTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip_test_common.hh>
#define N 512
__device__ bool check_erfcinvf() {
uint32_t len = 4;
float Val[] = {0.1, 1.2, 1, 0.9};
float Out[] = {1.16309, -0.179144, 0, 0.0889};
for (int i = 0; i < len; i++) {
if ((Out[i] - erfcinvf(Val[i])) > 0.0001) {
return false;
}
}
return true;
}
__device__ bool check_erfcxf() {
uint32_t len = 4;
float Val[] = {-0.5, 15, 3.2, 1};
float Out[] = {1.9524, 0.0375, 0.1687, 0.4276};
for (int i = 0; i < len; i++) {
if (Out[i] - erfcxf(Val[i]) > 0.0001) {
return false;
}
}
return true;
}
__device__ bool check_erfinvf() {
uint32_t len = 4;
float Val[] = {0, -0.5, 0.9, -0.2};
float Out[] = {0, -0.4769, 1.1631, -0.1791};
for (int i = 0; i < len; i++) {
if (Out[i] - erfinvf(Val[i]) > 0.0001) {
return false;
}
}
return true;
}
__device__ bool check_fdividef() {
uint32_t len = 4;
float Val[] = {0, -0.5, 0.9, -0.2};
float Out[] = {1, -0.4769, 1.1631, -0.1791};
for (int i = 0; i < len; i++) {
if (Val[i] / Out[i] - fdividef(Val[i], Out[i]) > 0.0001) {
return false;
}
}
return true;
}
__device__ bool check_erfcinv() {
uint32_t len = 4;
double Val[] = {0.1, 1.2, 1, 0.9};
double Out[] = {1.16309, -0.179144, 0, 0.0889};
for (int i = 0; i < len; i++) {
if (Out[i] - erfcinv(Val[i]) > 0.0001) {
return false;
}
}
return true;
}
__device__ bool check_erfcx() {
uint32_t len = 4;
double Val[] = {-0.5, 15, 3.2, 1};
double Out[] = {1.9524, 0.0375, 0.1687, 0.4276};
for (int i = 0; i < len; i++) {
if (Out[i] - erfcx(Val[i]) > 0.0001) {
return false;
}
}
return true;
}
__device__ bool check_erfinv() {
uint32_t len = 4;
double Val[] = {0, -0.5, 0.9, -0.2};
double Out[] = {0, -0.4769, 1.1631, -0.1791};
for (int i = 0; i < len; i++) {
if (Out[i] - erfinv(Val[i]) > 0.0001) {
return false;
}
}
return true;
}
__device__ bool check_fdivide() {
uint32_t len = 4;
double Val[] = {0, -0.5, 0.9, -0.2};
double Out[] = {1, -0.4769, 1.1631, -0.1791};
for (int i = 0; i < len; i++) {
if (Val[i] / Out[i] - fdividef(Val[i], Out[i]) > 0.0001) {
return false;
}
}
return true;
}
__device__ bool check_modff() {
uint32_t len = 4;
float Val[] = {0, -0.5, 0.9, -0.2};
float iPtr[] = {0, 0, 0, 0};
float frac[] = {0, -0.5, 0.9, -0.2};
float Out[] = {1, 1, 1, 1};
for (int i = 0; i < len; i++) {
if (frac[i] - modff(Val[i], Out + i) > 0.0001 && iPtr[i] == Out[i]) {
return false;
}
}
return true;
}
__device__ bool check_modf() {
uint32_t len = 4;
double Val[] = {0, -0.5, 0.9, -0.2};
double iPtr[] = {0, 0, 0, 0};
double frac[] = {0, -0.5, 0.9, -0.2};
double Out[] = {1, 1, 1, 1};
for (int i = 0; i < len; i++) {
if (frac[i] - modf(Val[i], Out + i) > 0.0001 && iPtr[i] == Out[i]) {
return false;
}
}
return true;
}
__device__ bool check_nextafterf() {
uint32_t len = 4;
float Val[] = {0, -0.5, 0.9, -0.2};
for (int i = 0; i < len; i++) {
if (nextafterf(Val[i], 1) - Val[i] > 0.0001) {
return false;
}
}
return true;
}
__device__ bool check_nextafter() {
uint32_t len = 4;
double Val[] = {0, -0.5, 0.9, -0.2};
for (int i = 0; i < len; i++) {
if (nextafter(Val[i], 1) - Val[i] > 0.0001) {
return false;
}
}
return true;
}
__device__ bool check_norm3df(float* A) {
float f = norm3df(A[0], A[1], A[2]);
float out = sqrt(A[0] * A[0] + A[1] * A[1] + A[2] * A[2]);
if (f - out > 0.0001) {
return false;
}
return true;
}
__device__ bool check_norm3d(double* A) {
double f = norm3d(A[0], A[1], A[2]);
double out = sqrt(A[0] * A[0] + A[1] * A[1] + A[2] * A[2]);
if (f - out > 0.0001) {
return false;
}
return true;
}
__device__ bool check_norm4df(float* A) {
float f = norm4df(A[0], A[1], A[2], A[3]);
float out = sqrt(A[0] * A[0] + A[1] * A[1] + A[2] * A[2] + A[3] * A[3]);
if (f - out > 0.0001) {
return false;
}
return true;
}
__device__ bool check_norm4d(double* A) {
double f = norm4d(A[0], A[1], A[2], A[3]);
double out = sqrt(A[0] * A[0] + A[1] * A[1] + A[2] * A[2] + A[3] * A[3]);
if (f - out > 0.0001) {
return false;
}
return true;
}
__device__ bool check_normcdff() {
uint32_t len = 2;
float Val[] = {0, 1};
float Out[] = {0.5, 0.8413};
for (int i = 0; i < len; i++) {
if (Out[i] - normcdff(Val[i]) > 0.0001) {
return false;
}
}
return true;
}
__device__ bool check_normcdf() {
uint32_t len = 2;
float Val[] = {0, 1};
float Out[] = {0.5, 0.8413};
for (int i = 0; i < len; i++) {
if (Out[i] - normcdf(Val[i]) > 0.0001) {
return false;
}
}
return true;
}
__device__ bool check_normcdfinvf() {
uint32_t len = 2;
double Val[] = {0.5, 0.8413};
for (int i = 0; i < len; i++) {
if (Val[i] - normcdfinvf(normcdff(Val[i])) > 0.0001) {
return false;
}
}
return true;
}
__device__ bool check_normcdfinv() {
uint32_t len = 2;
double Val[] = {0.5, 0.8413};
for (int i = 0; i < len; i++) {
if (Val[i] - normcdfinv(normcdf(Val[i])) > 0.0001) {
return false;
}
}
return true;
}
__device__ bool check_rcbrtf() {
float f = 1.0f;
if (rcbrtf(f) != 1.0f) {
return false;
}
return true;
}
__device__ bool check_rcbrt() {
double f = 1.0;
if (rcbrt(f) != 1.0) {
return false;
}
return true;
}
__device__ bool check_rhypotf() {
float f = 1.0f;
float g = 2.0f;
float val = rhypotf(f, g);
float sq = f * f + g * g;
if (1 / (val * val) - sq > 0.0001) {
return false;
}
return true;
}
__device__ bool check_rhypot() {
double f = 1.0f;
double g = 2.0f;
double val = rhypot(f, g);
double sq = f * f + g * g;
if (1 / (val * val) - sq > 0.0001) {
return false;
}
return true;
}
__device__ bool check_rnorm3df(float* A) {
float f = rnorm3df(A[0], A[1], A[2]);
float out = sqrt(A[0] * A[0] + A[1] * A[1] + A[2] * A[2]);
if (f - 1 / out > 0.0001) {
return false;
}
return true;
}
__device__ bool check_rnorm3d(double* A) {
double f = rnorm3d(A[0], A[1], A[2]);
double out = sqrt(A[0] * A[0] + A[1] * A[1] + A[2] * A[2]);
if (f - 1 / out > 0.0001) {
return false;
}
return true;
}
__device__ bool check_rnorm4df(float* A) {
float f = rnorm4df(A[0], A[1], A[2], A[3]);
float out = sqrt(A[0] * A[0] + A[1] * A[1] + A[2] * A[2] + A[3] * A[3]);
if (f - 1 / out > 0.0001) {
return false;
}
return true;
}
__device__ bool check_rnorm4d(double* A) {
double f = rnorm4d(A[0], A[1], A[2], A[3]);
double out = sqrt(A[0] * A[0] + A[1] * A[1] + A[2] * A[2] + A[3] * A[3]);
if (f - 1 / out > 0.0001) {
return false;
}
return true;
}
__device__ bool check_rnormf(float* A) {
return (rnorm3df(A[0], A[1], A[2]) - rnormf(3, A) < 0.0001) &&
(rnorm4df(A[0], A[1], A[2], A[3]) - rnormf(4, A) < 0.0001);
}
__device__ bool check_rnorm(double* A) {
return (rnorm3d(A[0], A[1], A[2]) - rnorm(3, A) < 0.0001) &&
(rnorm4d(A[0], A[1], A[2], A[3]) - rnorm(4, A) < 0.0001);
}
__device__ bool check_sincospif() {
float s1, c1, s2, c2;
float in1 = 1, in2 = 0.5;
sincospif(in1, &s1, &c1);
sincospif(in2, &s2, &c2);
if ((s1 - 0 < 0.00001) && (s2 - 1 < 0.00001) &&
(c1 + 1 < 0.00001) && (c2 - 0 < 0.00001)) {
return true;
}
return false;
}
__device__ bool check_sincospi() {
double s1, c1, s2, c2;
double in1 = 1, in2 = 0.5;
sincospi(in1, &s1, &c1);
sincospi(in2, &s2, &c2);
if ((s1 - 0 < 0.00001) && (s2 - 1 < 0.00001) &&
(c1 + 1 < 0.00001) && (c2 - 0 < 0.00001)) {
return true;
}
return false;
}
__global__ void testFunctions(bool *result, float *Af, double *A) {
result[0] &= check_erfcinvf() && check_erfcxf() && check_erfcinvf()
&& check_erfcinv() && check_erfcx() && check_erfcinv()
&& check_fdividef() && check_fdivide() && check_modff()
&& check_modf() && check_nextafterf() && check_norm3df(Af)
&& check_norm3d(A) && check_norm4df(Af) && check_norm4d(A)
&& check_normcdff() && check_normcdf() && check_normcdfinvf()
&& check_normcdfinv() && check_rcbrtf() && check_rcbrt() &&
check_rhypotf() && check_rhypot() && check_rnorm3df(Af) &&
check_rnorm3d(A) && check_rnorm4df(Af) && check_rnorm4d(A) &&
check_rnormf(Af) && check_rnorm(A) && check_sincospif() &&
check_sincospi() && check_nextafter();
}
TEST_CASE("Unit_TestDevice_DoublePrecisionMathFunc") {
float* Af = new float[N];
double* A = new double[N];
for (int i = 0; i < N; i++) {
Af[i] = i * 1.0f;
A[i] = i * 1.0;
}
float *Afd;
double *Ad;
bool *srcPtr, *devicePtr;
srcPtr = new bool;
srcPtr[0] = true;
// Device pointers
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&devicePtr), sizeof(bool)));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Afd), sizeof(float)*N));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Ad), sizeof(double)*N));
// MemCpy
HIP_CHECK(hipMemcpy(devicePtr, srcPtr, sizeof(bool), hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(Afd, Af, sizeof(float)*N, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(Ad, A, sizeof(double)*N, hipMemcpyHostToDevice));
// Kernel Launch
hipLaunchKernelGGL(testFunctions, dim3(1), dim3(1), 0, 0, devicePtr, Afd, Ad);
HIP_CHECK(hipMemcpy(srcPtr, devicePtr, sizeof(bool), hipMemcpyDeviceToHost));
// Validation
REQUIRE(srcPtr[0] == true);
HIP_CHECK(hipFree(devicePtr));
delete srcPtr;
delete [] Af;
delete [] A;
}
+134
Просмотреть файл
@@ -0,0 +1,134 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANNTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip_test_common.hh>
#include <new>
// Test __HIP_DEVICE_COMPILE__ is defined after math_functions.h
// is included.
__device__ __host__ inline void throw_std_bad_alloc() {
#ifndef __HIP_DEVICE_COMPILE__
throw std::bad_alloc();
#else
std::size_t kHuge = static_cast<std::size_t>(-1);
new int[kHuge];
#endif
}
__global__ void FloatMathPreciseKernel() {
int iX;
float fX, fY;
acosf(1.0f);
acoshf(1.0f);
asinf(0.0f);
asinhf(0.0f);
atan2f(0.0f, 1.0f);
atanf(0.0f);
atanhf(0.0f);
cbrtf(0.0f);
fX = ceilf(0.0f);
fX = copysignf(1.0f, -2.0f);
cosf(0.0f);
coshf(0.0f);
cospif(0.0f);
cyl_bessel_i0f(0.0f);
cyl_bessel_i1f(0.0f);
erfcf(0.0f);
erfcinvf(2.0f);
erfcxf(0.0f);
erff(0.0f);
erfinvf(1.0f);
exp10f(0.0f);
exp2f(0.0f);
expf(0.0f);
expm1f(0.0f);
fX = fabsf(1.0f);
fdimf(1.0f, 0.0f);
fdividef(0.0f, 1.0f);
fX = floorf(0.0f);
fmaf(1.0f, 2.0f, 3.0f);
fX = fmaxf(0.0f, 0.0f);
fX = fminf(0.0f, 0.0f);
fmodf(0.0f, 1.0f);
frexpf(0.0f, &iX);
hypotf(1.0f, 0.0f);
ilogbf(1.0f);
isfinite(0.0f);
fX = isinf(0.0f);
fX = isnan(0.0f);
j0f(0.0f);
j1f(0.0f);
jnf(-1.0f, 1.0f);
ldexpf(0.0f, 0);
lgammaf(1.0f);
llrintf(0.0f);
llroundf(0.0f);
log10f(1.0f);
log1pf(-1.0f);
log2f(1.0f);
logbf(1.0f);
logf(1.0f);
lrintf(0.0f);
lroundf(0.0f);
modff(0.0f, &fX);
fX = nanf("1");
fX = nearbyintf(0.0f);
nextafterf(0.0f, 0.0f);
norm3df(1.0f, 0.0f, 0.0f);
norm4df(1.0f, 0.0f, 0.0f, 0.0f);
normcdff(0.0f);
normcdfinvf(1.0f);
fX = 1.0f;
normf(1, &fX);
powf(1.0f, 0.0f);
rcbrtf(1.0f);
remainderf(2.0f, 1.0f);
remquof(1.0f, 2.0f, &iX);
rhypotf(0.0f, 1.0f);
fY = rintf(1.0f);
rnorm3df(0.0f, 0.0f, 1.0f);
rnorm4df(0.0f, 0.0f, 0.0f, 1.0f);
fX = 1.0f;
rnormf(1, &fX);
fY = roundf(0.0f);
rsqrtf(1.0f);
scalblnf(0.0f, 1);
scalbnf(0.0f, 1);
signbit(1.0f);
sincosf(0.0f, &fX, &fY);
sincospif(0.0f, &fX, &fY);
sinf(0.0f);
sinhf(0.0f);
sinpif(0.0f);
sqrtf(0.0f);
tanf(0.0f);
tanhf(0.0f);
tgammaf(2.0f);
fY = truncf(0.0f);
y0f(1.0f);
y1f(1.0f);
ynf(1, 1.0f);
}
TEST_CASE("Unit_TestIncludeMathPreciseFloat") {
hipError_t err;
err = hipLaunchKernel(reinterpret_cast<void *>(FloatMathPreciseKernel),
dim3(1, 1, 1),
dim3(1, 1, 1), 0, 0, 0);
REQUIRE(err == hipSuccess);
}
+167
Просмотреть файл
@@ -0,0 +1,167 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANNTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip/hip_fp16.h>
#include <hip_test_common.hh>
#include <type_traits>
__global__
void __halfTest(bool* result, __half a) {
// Construction
result[0] &= std::is_default_constructible<__half>{};
result[0] &= std::is_copy_constructible<__half>{};
result[0] &= std::is_move_constructible<__half>{};
result[0] &= std::is_constructible<__half, float>{};
result[0] &= std::is_constructible<__half, double>{};
result[0] &= std::is_constructible<__half, uint32_t>{};
result[0] &= std::is_constructible<__half, int32_t>{};
result[0] &= std::is_constructible<__half, uint32_t>{};
result[0] &= std::is_constructible<__half, int>{};
result[0] &= std::is_constructible<__half, uint64_t>{};
result[0] &= std::is_constructible<__half, int64_t>{};
result[0] &= std::is_constructible<__half, int64_t>{};
result[0] &= std::is_constructible<__half, uint64_t>{};
result[0] &= std::is_constructible<__half, __half_raw>{};
// Assignment
result[0] &= std::is_copy_assignable<__half>{};
result[0] &= std::is_move_assignable<__half>{};
result[0] &= std::is_assignable<__half, float>{};
result[0] &= std::is_assignable<__half, double>{};
result[0] &= std::is_assignable<__half, uint32_t>{};
result[0] &= std::is_assignable<__half, int32_t>{};
result[0] &= std::is_assignable<__half, uint32_t>{};
result[0] &= std::is_assignable<__half, int>{};
result[0] &= std::is_assignable<__half, uint64_t>{};
result[0] &= std::is_assignable<__half, int64_t>{};
result[0] &= std::is_assignable<__half, int64_t>{};
result[0] &= std::is_assignable<__half, uint64_t>{};
result[0] &= std::is_assignable<__half, __half_raw>{};
result[0] &= std::is_assignable<__half, volatile __half_raw&>{};
result[0] &= std::is_assignable<__half, volatile __half_raw&&>{};
// Conversion
result[0] &= std::is_convertible<__half, float>{};
result[0] &= std::is_convertible<__half, uint32_t>{};
result[0] &= std::is_convertible<__half, int32_t>{};
result[0] &= std::is_convertible<__half, uint32_t>{};
result[0] &= std::is_convertible<__half, int>{};
result[0] &= std::is_convertible<__half, uint64_t>{};
result[0] &= std::is_convertible<__half, int64_t>{};
result[0] &= std::is_convertible<__half, int64_t>{};
result[0] &= std::is_convertible<__half, bool>{};
result[0] &= std::is_convertible<__half, uint64_t>{};
result[0] &= std::is_convertible<__half, __half_raw>{};
result[0] &= std::is_convertible<__half, volatile __half_raw>{};
// Nullary
result[0] &= __heq(a, +a) && result[0];
result[0] &= __heq(__hneg(a), -a) && result[0];
// Unary arithmetic
result[0] &= __heq(a += 0, a) && result[0];
result[0] &= __heq(a -= 0, a) && result[0];
result[0] &= __heq(a *= 1, a) && result[0];
result[0] &= __heq(a /= 1, a) && result[0];
// Binary arithmetic
result[0] &= __heq((a + a), __hadd(a, a)) && result[0];
result[0] &= __heq((a - a), __hsub(a, a)) && result[0];
result[0] &= __heq((a * a), __hmul(a, a)) && result[0];
result[0] &= __heq((a / a), __hdiv(a, a)) && result[0];
// Relations
result[0] &= (a == a) && result[0];
result[0] &= !(a != a) && result[0];
result[0] &= (a <= a) && result[0];
result[0] &= (a >= a) && result[0];
result[0] &= !(a < a) && result[0];
result[0] &= !(a > a) && result[0];
}
__device__
static bool to_bool(const __half2& x) {
auto r = static_cast<const __half2_raw&>(x);
return r.data.x != 0 && r.data.y != 0;
}
__global__
void __half2Test(bool* result, __half2 a) {
// Construction
result[0] &= std::is_default_constructible<__half2>{};
result[0] &= std::is_copy_constructible<__half2>{};
result[0] &= std::is_move_constructible<__half2>{};
result[0] &= std::is_constructible<__half2, __half, __half>{};
result[0] &= std::is_constructible<__half2, __half2_raw>{};
// Assignment
result[0] &= std::is_copy_assignable<__half2>{};
result[0] &= std::is_move_assignable<__half2>{};
result[0] &= std::is_assignable<__half2, __half2_raw>{};
// Conversion
result[0] &= std::is_convertible<__half2, __half2_raw>{};
// Nullary
result[0] &= to_bool(__heq2(a, +a)) && result[0];
result[0] &= to_bool(__heq2(__hneg2(a), -a)) && result[0];
// Unary arithmetic
result[0] &= to_bool(__heq2(a += 0, a)) && result[0];
result[0] &= to_bool(__heq2(a -= 0, a)) && result[0];
result[0] &= to_bool(__heq2(a *= 1, a)) && result[0];
result[0] &= to_bool(__heq2(a /= 1, a)) && result[0];
// Binary arithmetic
result[0] &= to_bool(__heq2((a + a), __hadd2(a, a))) && result[0];
result[0] &= to_bool(__heq2((a - a), __hsub2(a, a))) && result[0];
result[0] &= to_bool(__heq2((a * a), __hmul2(a, a))) && result[0];
result[0] &= to_bool(__heq2((a / a), __h2div(a, a))) && result[0];
// Relations
result[0] &= (a == a) && result[0];
result[0] &= !(a != a) && result[0];
result[0] &= (a <= a) && result[0];
result[0] &= (a >= a) && result[0];
result[0] &= !(a < a) && result[0];
result[0] &= !(a > a) && result[0];
// Dot Functions
result[0] &= amd_mixed_dot(a, a, 1, 1) && result[0];
}
TEST_CASE("Unit_hipTestNativeHalf") {
bool* result{nullptr};
HIP_CHECK(hipHostMalloc(&result, 1));
SECTION("Half Test") {
result[0] = true;
hipLaunchKernelGGL(
__halfTest, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0, result, __half{1});
HIP_CHECK(hipDeviceSynchronize());
REQUIRE(result[0] == true);
}
SECTION("Half2 Test") {
result[0] = true;
hipLaunchKernelGGL(
__half2Test, dim3(1, 1, 1), dim3(1, 1, 1), 0, 0, result, __half2{1, 1});
HIP_CHECK(hipDeviceSynchronize());
REQUIRE(result[0] == true);
}
HIP_CHECK(hipHostFree(result));
}
+54
Просмотреть файл
@@ -0,0 +1,54 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANNTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip_test_common.hh>
#define LEN 512
#define SIZE 2048
class A {
public:
__device__ A() {
a = threadIdx.x + blockIdx.x * blockDim.x;
}
private:
int a;
};
static __global__ void kernel(int* Ad) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
new(Ad+tid) A();
}
TEST_CASE("Unit_hipTest_DeviceNewOperator") {
int *A, *Ad;
A = new int[LEN];
for (unsigned i = 0; i < LEN; i++) {
A[i] = 0;
}
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Ad), SIZE));
hipLaunchKernelGGL(kernel, dim3(1, 1, 1), dim3(LEN, 1, 1), 0, 0, Ad);
HIP_CHECK(hipMemcpy(A, Ad, SIZE, hipMemcpyDeviceToHost));
// Validation
for (unsigned i = 0; i < LEN; i++) {
REQUIRE(i == A[i]);
}
delete[] A;
}
+76
Просмотреть файл
@@ -0,0 +1,76 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANNTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip_test_common.hh>
#define NUM 1024
#define SIZE (NUM * sizeof(float))
__global__ static void vAdd(float* In1, float* In2, float* In3,
float* In4, float* Out) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
In4[tid] = In1[tid] + In2[tid];
__threadfence();
In3[tid] = In3[tid] + In4[tid];
__threadfence_block();
Out[tid] = In4[tid] + In3[tid];
}
TEST_CASE("Unit_hipThreadFence") {
float* In1 = new float[NUM];
float* In2 = new float[NUM];
float* In3 = new float[NUM];
float* In4 = new float[NUM];
float* Out = new float[NUM];
// Initialization
for (uint32_t i = 0; i < NUM; i++) {
In1[i] = 1.0f;
In2[i] = 1.0f;
In3[i] = 1.0f;
In4[i] = 1.0f;
}
float *In1d, *In2d, *In3d, *In4d, *Outd;
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&In1d), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&In2d), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&In3d), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&In4d), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&Outd), SIZE));
HIP_CHECK(hipMemcpy(In1d, In1, SIZE, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(In2d, In2, SIZE, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(In3d, In3, SIZE, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(In4d, In4, SIZE, hipMemcpyHostToDevice));
hipLaunchKernelGGL(vAdd, dim3(32, 1, 1), dim3(32, 1, 1), 0, 0,
In1d, In2d, In3d, In4d, Outd);
HIP_CHECK(hipMemcpy(Out, Outd, SIZE, hipMemcpyDeviceToHost));
for (uint32_t i = 0; i < NUM; i++) {
REQUIRE(Out[i] == 2 * In1[i] + 2 * In2[i] + In3[i]);
}
delete[] In1;
delete[] In2;
delete[] In3;
delete[] In4;
delete[] Out;
HIP_CHECK(hipFree(In1d));
HIP_CHECK(hipFree(In2d));
HIP_CHECK(hipFree(In3d));
HIP_CHECK(hipFree(In4d));
HIP_CHECK(hipFree(Outd));
}
+204
Просмотреть файл
@@ -0,0 +1,204 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANNTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip_test_common.hh>
#include <hip/hip_vector_types.h>
#include <string>
#include <sstream>
#include <type_traits>
using namespace std; // NOLINT
template<typename V,
enable_if_t<!is_integral<decltype(declval<V>().x)>{}>* = nullptr>
bool integer_unary_tests(V&, V&) {
return true;
}
template<typename V,
enable_if_t<!is_integral<decltype(declval<V>().x)>{}>* = nullptr>
bool integer_binary_tests(V&, V&, V&...) {
return true;
}
template<typename V,
enable_if_t<is_integral<decltype(declval<V>().x)>{}>* = nullptr>
bool integer_unary_tests(V f1, V f2) {
f1 %= f2;
if (f1 != V{0}) return false;
f1 &= f2;
if (f1 != V{0}) return false;
f1 |= f2;
if (f1 != V{1}) return false;
f1 ^= f2;
if (f1 != V{0}) return false;
f1 = V{1};
f1 <<= f2;
if (f1 != V{2}) return false;
f1 >>= f2;
if (f1 != V{1}) return false;
f2 = ~f1;
return f2 == V{~1};
}
template<typename V,
enable_if_t<is_integral<decltype(declval<V>().x)>{}>* = nullptr>
bool integer_binary_tests(V f1, V f2, V f3) {
f3 = f1 % f2;
if (f3 != V{0}) return false;
f1 = f3 & f2;
if (f1 != V{0}) return false;
f2 = f1 ^ f3;
if (f2 != V{0}) return false;
f1 = V{1};
f2 = V{2};
f3 = f1 << f2;
if (f3 != V{4}) return false;
f2 = f3 >> f1;
return f2 == V{2};
}
template<typename V>
bool constructor_tests() {
if (is_constructible<V, unsigned char>{} &&
is_constructible<V, signed char>{} &&
is_constructible<V, uint32_t>{} &&
is_constructible<V, int32_t>{} &&
is_constructible<V, unsigned int>{} &&
is_constructible<V, signed int>{} &&
is_constructible<V, uint64_t>{} &&
is_constructible<V, int64_t>{} &&
is_constructible<V, uint64_t>{} &&
is_constructible<V, int64_t>{} &&
is_constructible<V, float>{} &&
is_constructible<V, double>{}) {
return true;
}
}
template<typename V>
bool TestVectorType() {
constexpr V v1{1};
constexpr V v2{2};
constexpr V v3{3};
constexpr V v4{4};
V f1{1};
V f2{1};
V f3 = f1 + f2;
if (f3 != v2) return false;
f2 = f3 - f1;
if (f2 != v1) return false;
f1 = f2 * f3;
if (f1 != v2) return false;
f2 = f1 / f3;
if (f2 != v1) return false;
if (!integer_binary_tests(f1, f2, f3)) return false;
f1 = V{2};
f2 = V{1};
f1 += f2;
if (f1 != v3) return false;
f1 -= f2;
if (f1 != v2) return false;
f1 *= f2;
if (f1 != v2) return false;
f1 /= f2;
if (f1 != v2) return false;
if (!integer_unary_tests(f1, f2)) return false;
f1 = v2;
f2 = f1++;
if (f1 != v3) return false;
if (f2 != v2) return false;
f2 = f1--;
if (f2 != v3) return false;
if (f1 != v2) return false;
f2 = ++f1;
if (f1 != v3) return false;
if (f2 != v3) return false;
f2 = --f1;
if (f1 != v2) return false;
if (f2 != v2) return false;
if (!constructor_tests<V>()) return false;
f1 = v3;
f2 = v4;
f3 = v3;
if (f1 == f2) return false;
if (!(f1 != f2)) return false;
using T = typename V::value_type;
const T& x = f1.x;
T& y = f2.x;
const volatile T& z = f3.x;
volatile T& w = f2.x;
if (x != T{3}) return false;
if (y != T{4}) return false;
if (z != T{3}) return false;
if (w != T{4}) return false;
stringstream str;
str << f1.x;
str >> f2.x;
if (f1.x != f2.x) return false;
return true;
}
template<typename... Ts, enable_if_t<sizeof...(Ts) == 0>* = nullptr>
bool TestVectorTypes() {
return true;
}
template<typename T, typename... Ts>
bool TestVectorTypes() {
if (!TestVectorType<T>()) return false;
return TestVectorTypes<Ts...>();
}
bool CheckVectorTypes() {
return TestVectorTypes<
char1, char2, char3, char4,
uchar1, uchar2, uchar3, uchar4,
short1, short2, short3, short4,
ushort1, ushort2, ushort3, ushort4,
int1, int2, int3, int4,
uint1, uint2, uint3, uint4,
long1, long2, long3, long4,
ulong1, ulong2, ulong3, ulong4,
longlong1, longlong2, longlong3, longlong4,
ulonglong1, ulonglong2, ulonglong3, ulonglong4,
float1, float2, float3, float4,
double1, double2, double3, double4>();
}
TEST_CASE("Unit_TestVectorTypes") {
REQUIRE(sizeof(float1) == 4);
REQUIRE(sizeof(float2) >= 8);
REQUIRE(sizeof(float3) == 12);
REQUIRE(sizeof(float4) >= 16);
bool result = false;
result = CheckVectorTypes();
REQUIRE(result == true);
}
+334
Просмотреть файл
@@ -0,0 +1,334 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANNTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip/hip_runtime.h>
#include <hip_test_common.hh>
#define WIDTH 8
#define HEIGHT 8
#define NUM (WIDTH * HEIGHT)
#define THREADS_PER_BLOCK_X 8
#define THREADS_PER_BLOCK_Y 8
#define THREADS_PER_BLOCK_Z 1
__global__ void vectoradd_char1(char1* a, const char1* bm, const char1* cm,
int width, int height) {
int x = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;
int i = y * width + x;
if (i < (width * height)) {
a[i] = make_char1(bm[i].x) + make_char1(cm[i].x);
}
}
__global__ void vectoradd_char2(char2* a, const char2* bm, const char2* cm,
int width, int height) {
int x = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;
int i = y * width + x;
if (i < (width * height)) {
a[i] = make_char2(bm[i].x, bm[i].y) + make_char2(cm[i].x, cm[i].y);
}
}
__global__ void vectoradd_char3(char3* a, const char3* bm, const char3* cm,
int width, int height) {
int x = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;
int i = y * width + x;
if (i < (width * height)) {
a[i] = make_char3(bm[i].x, bm[i].y, bm[i].z) + make_char3(cm[i].x,
cm[i].y, cm[i].z);
}
}
__global__ void vectoradd_char4(char4* a, const char4* bm, const char4* cm,
int width, int height) {
int x = blockDim.x * blockIdx.x + threadIdx.x;
int y = blockDim.y * blockIdx.y + threadIdx.y;
int i = y * width + x;
if (i < (width * height)) {
a[i] = make_char4(bm[i].x, bm[i].y, bm[i].z, bm[i].w) +
make_char4(cm[i].x, cm[i].y, cm[i].z, cm[i].w);
}
}
template <typename T>
bool dataTypesRunChar1() {
T* hostA;
T* hostB;
T* hostC;
T* deviceA;
T* deviceB;
T* deviceC;
int i;
int errors;
hostA = reinterpret_cast<T*>(malloc(NUM * sizeof(T)));
hostB = reinterpret_cast<T*>(malloc(NUM * sizeof(T)));
hostC = reinterpret_cast<T*>(malloc(NUM * sizeof(T)));
// initialize the input data
for (i = 0; i < NUM; i++) {
hostB[i] = (T)i;
hostC[i] = (T)i;
}
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&deviceA), NUM * sizeof(T)));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&deviceB), NUM * sizeof(T)));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&deviceC), NUM * sizeof(T)));
HIP_CHECK(hipMemcpy(deviceB, hostB, NUM * sizeof(T), hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(deviceC, hostC, NUM * sizeof(T), hipMemcpyHostToDevice));
hipLaunchKernelGGL(HIP_KERNEL_NAME(vectoradd_char1),
dim3(WIDTH / THREADS_PER_BLOCK_X, HEIGHT /
THREADS_PER_BLOCK_Y), dim3(THREADS_PER_BLOCK_X,
THREADS_PER_BLOCK_Y), 0, 0, deviceA, deviceB, deviceC,
WIDTH, HEIGHT);
HIP_CHECK(hipMemcpy(hostA, deviceA, NUM * sizeof(T), hipMemcpyDeviceToHost));
bool ret = false;
// verify the results
errors = 0;
for (i = 0; i < NUM; i++) {
if (hostA[i] != (hostB[i] + hostC[i])) {
errors++;
}
}
if (errors != 0) {
ret = false;
} else {
ret = true;
}
HIP_CHECK(hipFree(deviceA));
HIP_CHECK(hipFree(deviceB));
HIP_CHECK(hipFree(deviceC));
free(hostA);
free(hostB);
free(hostC);
return ret;
}
template <typename T>
bool dataTypesRunChar2() {
T* hostA;
T* hostB;
T* hostC;
T* deviceA;
T* deviceB;
T* deviceC;
int i;
int errors;
hostA = reinterpret_cast<T*>(malloc(NUM * sizeof(T)));
hostB = reinterpret_cast<T*>(malloc(NUM * sizeof(T)));
hostC = reinterpret_cast<T*>(malloc(NUM * sizeof(T)));
// initialize the input data
for (i = 0; i < NUM; i++) {
hostB[i] = (T)i;
hostC[i] = (T)i;
}
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&deviceA), NUM * sizeof(T)));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&deviceB), NUM * sizeof(T)));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&deviceC), NUM * sizeof(T)));
HIP_CHECK(hipMemcpy(deviceB, hostB, NUM * sizeof(T), hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(deviceC, hostC, NUM * sizeof(T), hipMemcpyHostToDevice));
hipLaunchKernelGGL(HIP_KERNEL_NAME(vectoradd_char2),
dim3(WIDTH / THREADS_PER_BLOCK_X, HEIGHT /
THREADS_PER_BLOCK_Y), dim3(THREADS_PER_BLOCK_X,
THREADS_PER_BLOCK_Y), 0, 0, deviceA, deviceB, deviceC,
WIDTH, HEIGHT);
HIP_CHECK(hipMemcpy(hostA, deviceA, NUM * sizeof(T), hipMemcpyDeviceToHost));
bool ret = false;
// verify the results
errors = 0;
for (i = 0; i < NUM; i++) {
if (hostA[i] != (hostB[i] + hostC[i])) {
errors++;
}
}
if (errors != 0) {
ret = false;
} else {
ret = true;
}
HIP_CHECK(hipFree(deviceA));
HIP_CHECK(hipFree(deviceB));
HIP_CHECK(hipFree(deviceC));
free(hostA);
free(hostB);
free(hostC);
return ret;
}
template <typename T>
bool dataTypesRunChar3() {
T* hostA;
T* hostB;
T* hostC;
T* deviceA;
T* deviceB;
T* deviceC;
int i;
int errors;
hostA = reinterpret_cast<T*>(malloc(NUM * sizeof(T)));
hostB = reinterpret_cast<T*>(malloc(NUM * sizeof(T)));
hostC = reinterpret_cast<T*>(malloc(NUM * sizeof(T)));
// initialize the input data
for (i = 0; i < NUM; i++) {
hostB[i] = (T)i;
hostC[i] = (T)i;
}
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&deviceA), NUM * sizeof(T)));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&deviceB), NUM * sizeof(T)));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&deviceC), NUM * sizeof(T)));
HIP_CHECK(hipMemcpy(deviceB, hostB, NUM * sizeof(T), hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(deviceC, hostC, NUM * sizeof(T), hipMemcpyHostToDevice));
hipLaunchKernelGGL(HIP_KERNEL_NAME(vectoradd_char3),
dim3(WIDTH / THREADS_PER_BLOCK_X, HEIGHT /
THREADS_PER_BLOCK_Y), dim3(THREADS_PER_BLOCK_X,
THREADS_PER_BLOCK_Y), 0, 0, deviceA, deviceB, deviceC,
WIDTH, HEIGHT);
HIP_CHECK(hipMemcpy(hostA, deviceA, NUM * sizeof(T), hipMemcpyDeviceToHost));
bool ret = false;
// verify the results
errors = 0;
for (i = 0; i < NUM; i++) {
if (hostA[i] != (hostB[i] + hostC[i])) {
errors++;
}
}
if (errors != 0) {
ret = false;
} else {
ret = true;
}
HIP_CHECK(hipFree(deviceA));
HIP_CHECK(hipFree(deviceB));
HIP_CHECK(hipFree(deviceC));
free(hostA);
free(hostB);
free(hostC);
return ret;
}
template <typename T>
bool dataTypesRunChar4() {
char4* hostA;
char4* hostB;
char4* hostC;
char4* deviceA;
char4* deviceB;
char4* deviceC;
int i;
int errors;
hostA = reinterpret_cast<T*>(malloc(NUM * sizeof(T)));
hostB = reinterpret_cast<T*>(malloc(NUM * sizeof(T)));
hostC = reinterpret_cast<T*>(malloc(NUM * sizeof(T)));
// initialize the input data
for (i = 0; i < NUM; i++) {
hostB[i] = (T)i;
hostC[i] = (T)i;
}
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&deviceA), NUM * sizeof(T)));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&deviceB), NUM * sizeof(T)));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&deviceC), NUM * sizeof(T)));
HIP_CHECK(hipMemcpy(deviceB, hostB, NUM * sizeof(T), hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(deviceC, hostC, NUM * sizeof(T), hipMemcpyHostToDevice));
hipLaunchKernelGGL(HIP_KERNEL_NAME(vectoradd_char4),
dim3(WIDTH / THREADS_PER_BLOCK_X, HEIGHT /
THREADS_PER_BLOCK_Y), dim3(THREADS_PER_BLOCK_X,
THREADS_PER_BLOCK_Y), 0, 0, deviceA,
deviceB, deviceC, WIDTH, HEIGHT);
HIP_CHECK(hipMemcpy(hostA, deviceA, NUM * sizeof(T), hipMemcpyDeviceToHost));
bool ret = false;
// verify the results
errors = 0;
for (i = 0; i < NUM; i++) {
if (hostA[i] != (hostB[i] + hostC[i])) {
errors++;
}
}
if (errors != 0) {
ret = false;
} else {
ret = true;
}
HIP_CHECK(hipFree(deviceA));
HIP_CHECK(hipFree(deviceB));
HIP_CHECK(hipFree(deviceC));
free(hostA);
free(hostB);
free(hostC);
return ret;
}
TEST_CASE("Unit_Test_makechar_functionality") {
bool errors;
errors = dataTypesRunChar1<char1>() && dataTypesRunChar2<char2>() &&
dataTypesRunChar3<char3>() && dataTypesRunChar4<char4>();
REQUIRE(errors == true);
}
+86
Просмотреть файл
@@ -0,0 +1,86 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANNTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip_test_common.hh>
#include <hip/device_functions.h>
#define LEN 512
#define SIZE (LEN << 2)
__global__ static void kernel_trig(float* In, float* sin_d,
float* cos_d, float* tan_d,
float* sin_pd, float* cos_pd) {
int tid = threadIdx.x + blockIdx.x * blockDim.x;
sin_d[tid] = sinf(In[tid]);
cos_d[tid] = cosf(In[tid]);
tan_d[tid] = tanf(In[tid]);
sincosf(In[tid], &sin_pd[tid], &cos_pd[tid]);
}
TEST_CASE("Unit_kernel_trigger") {
float *In, *sin_h, *cos_h, *tan_h, *sin_ph, *cos_ph;
float *In_d, *sin_d, *cos_d, *tan_d, *sin_pd, *cos_pd;
int errors = 0;
In = new float[LEN];
sin_h = new float[LEN];
cos_h = new float[LEN];
tan_h = new float[LEN];
sin_ph = new float[LEN];
cos_ph = new float[LEN];
for (int i = 0; i < LEN; i++) {
In[i] = 1.0f;
sin_h[i] = 0.0f;
cos_h[i] = 0.0f;
tan_h[i] = 0.0f;
sin_ph[i] = 0.0f;
cos_ph[i] = 0.0f;
}
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&In_d), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&sin_d), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&cos_d), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&tan_d), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&sin_pd), SIZE));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&cos_pd), SIZE));
HIP_CHECK(hipMemcpy(In_d, In, SIZE, hipMemcpyHostToDevice));
hipLaunchKernelGGL(kernel_trig, dim3(LEN, 1, 1), dim3(1, 1, 1), 0, 0,
In_d, sin_d, cos_d, tan_d,
sin_pd, cos_pd);
HIP_CHECK(hipMemcpy(sin_h, sin_d, SIZE, hipMemcpyDeviceToHost));
HIP_CHECK(hipMemcpy(cos_h, cos_d, SIZE, hipMemcpyDeviceToHost));
HIP_CHECK(hipMemcpy(tan_h, tan_d, SIZE, hipMemcpyDeviceToHost));
HIP_CHECK(hipMemcpy(sin_ph, sin_pd, SIZE, hipMemcpyDeviceToHost));
HIP_CHECK(hipMemcpy(cos_ph, cos_pd, SIZE, hipMemcpyDeviceToHost));
// Validation
for (int i = 0; i < LEN; i++) {
if (sin_h[i] != sin_ph[i] || cos_h[i] != cos_ph[i] || tan_h[i] *
cos_h[i] != sin_h[i]) {
errors++;
}
}
REQUIRE(errors == 0);
delete[] In;
delete[] sin_h;
delete[] cos_h;
delete[] tan_h;
delete[] sin_ph;
delete[] cos_ph;
HIP_CHECK(hipFree(In_d));
HIP_CHECK(hipFree(sin_d));
HIP_CHECK(hipFree(cos_d));
HIP_CHECK(hipFree(tan_d));
HIP_CHECK(hipFree(sin_pd));
HIP_CHECK(hipFree(cos_pd));
}
+12 -12
Просмотреть файл
@@ -126,8 +126,8 @@ TEMPLATE_TEST_CASE("Unit_unsafeAtomicAdd_CoherentRTCnounsafeatomicflag", "",
void* config_d[] = {HIP_LAUNCH_PARAM_BUFFER_POINTER, &args_f,
HIP_LAUNCH_PARAM_BUFFER_SIZE,
&size, HIP_LAUNCH_PARAM_END};
hipModuleLaunchKernel(f_kernel, 1, 1, 1, 1, 1, 1, 0,
nullptr, nullptr, config_d);
HIP_CHECK(hipModuleLaunchKernel(f_kernel, 1, 1, 1, 1, 1, 1, 0,
nullptr, nullptr, config_d));
HIP_CHECK(hipDeviceSynchronize());
REQUIRE(A_h[0] == INITIAL_VAL);
REQUIRE(*result == 0);
@@ -218,8 +218,8 @@ TEMPLATE_TEST_CASE("Unit_unsafeAtomicAdd_CoherentRTCunsafeatomicflag", "",
void* config_d[] = {HIP_LAUNCH_PARAM_BUFFER_POINTER, &args_f,
HIP_LAUNCH_PARAM_BUFFER_SIZE,
&size, HIP_LAUNCH_PARAM_END};
hipModuleLaunchKernel(f_kernel, 1, 1, 1, 1, 1, 1, 0,
nullptr, nullptr, config_d);
HIP_CHECK(hipModuleLaunchKernel(f_kernel, 1, 1, 1, 1, 1, 1, 0,
nullptr, nullptr, config_d));
HIP_CHECK(hipDeviceSynchronize());
REQUIRE(A_h[0] == INITIAL_VAL);
REQUIRE(*result == 0);
@@ -306,8 +306,8 @@ TEMPLATE_TEST_CASE("Unit_unsafeAtomicAdd_CoherentRTCwithoutflag", "",
void* config_d[] = {HIP_LAUNCH_PARAM_BUFFER_POINTER, &args_f,
HIP_LAUNCH_PARAM_BUFFER_SIZE,
&size, HIP_LAUNCH_PARAM_END};
hipModuleLaunchKernel(f_kernel, 1, 1, 1, 1, 1,
1, 0, nullptr, nullptr, config_d);
HIP_CHECK(hipModuleLaunchKernel(f_kernel, 1, 1, 1, 1, 1,
1, 0, nullptr, nullptr, config_d));
HIP_CHECK(hipDeviceSynchronize());
REQUIRE(A_h[0] == INITIAL_VAL);
REQUIRE(*result == 0);
@@ -392,8 +392,8 @@ TEMPLATE_TEST_CASE("Unit_unsafeAtomicAdd_NonCoherentRTCnounsafeatomicflag", "",
void* config_d[] = {HIP_LAUNCH_PARAM_BUFFER_POINTER, &args_f,
HIP_LAUNCH_PARAM_BUFFER_SIZE,
&size, HIP_LAUNCH_PARAM_END};
hipModuleLaunchKernel(f_kernel, 1, 1, 1, 1, 1, 1, 0,
nullptr, nullptr, config_d);
HIP_CHECK(hipModuleLaunchKernel(f_kernel, 1, 1, 1, 1, 1, 1, 0,
nullptr, nullptr, config_d));
HIP_CHECK(hipDeviceSynchronize());
REQUIRE(A_h[0] == INITIAL_VAL + INCREMENT_VAL);
REQUIRE(*result == INITIAL_VAL);
@@ -480,8 +480,8 @@ TEMPLATE_TEST_CASE("Unit_unsafeAtomicAdd_NonCoherentRTCunsafeatomicflag", "",
void* config_d[] = {HIP_LAUNCH_PARAM_BUFFER_POINTER, &args_f,
HIP_LAUNCH_PARAM_BUFFER_SIZE,
&size, HIP_LAUNCH_PARAM_END};
hipModuleLaunchKernel(f_kernel, 1, 1, 1, 1, 1, 1, 0,
nullptr, nullptr, config_d);
HIP_CHECK(hipModuleLaunchKernel(f_kernel, 1, 1, 1, 1, 1, 1, 0,
nullptr, nullptr, config_d));
HIP_CHECK(hipDeviceSynchronize());
REQUIRE(A_h[0] == INITIAL_VAL + INCREMENT_VAL);
REQUIRE(*result == INITIAL_VAL);
@@ -568,8 +568,8 @@ TEMPLATE_TEST_CASE("Unit_unsafeAtomicAdd_NonCoherentRTC", "",
void* config_d[] = {HIP_LAUNCH_PARAM_BUFFER_POINTER, &args_f,
HIP_LAUNCH_PARAM_BUFFER_SIZE,
&size, HIP_LAUNCH_PARAM_END};
hipModuleLaunchKernel(f_kernel, 1, 1, 1, 1, 1, 1, 0,
nullptr, nullptr, config_d);
HIP_CHECK(hipModuleLaunchKernel(f_kernel, 1, 1, 1, 1, 1, 1, 0,
nullptr, nullptr, config_d));
HIP_CHECK(hipDeviceSynchronize());
REQUIRE(A_h[0] == INITIAL_VAL + INCREMENT_VAL);
REQUIRE(*result == INITIAL_VAL);
+303 -11
Просмотреть файл
@@ -1,5 +1,5 @@
/*
Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
Copyright (c) 2022-2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -21,38 +21,330 @@ THE SOFTWARE.
*/
#include <hip_test_common.hh>
#include <hip_test_kernels.hh>
#include <hip_test_defgroups.hh>
#include <stdlib.h>
constexpr size_t buffer_size = (1024*1024);
constexpr int test_iteration_hstvismem = 5;
constexpr int test_iteration_noncohmem = 10;
constexpr int block_size = 512;
/**
* @addtogroup hipEventCreateWithFlags hipEventCreateWithFlags
* @{
* @ingroup EventTest
* `hipEventCreateWithFlags(hipEvent_t* event, unsigned flags)` -
* Create an event with the specified flags to control event behaviour.
* `hipEventCreateWithFlags (hipEvent_t *event, unsigned flags)` -
* begins graph capture on a stream
*/
/**
* Test Description
* ------------------------
* - Successfully create an event with all defined device flags.
* - Test simple event creation with hipEventCreateWithFlags api for each flag
* Test source
* ------------------------
* - unit/event/hipEventCreateWithFlags.cc
* - catch\unit\event\hipEventCreateWithFlags.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
* - HIP_VERSION >= 5.2
*/
TEST_CASE("Unit_hipEventCreateWithFlags_Positive") {
#if HT_AMD
const unsigned int flagUnderTest = GENERATE(hipEventDefault, hipEventBlockingSync, hipEventDisableTiming, hipEventInterprocess | hipEventDisableTiming, hipEventReleaseToDevice, hipEventReleaseToSystem);
const unsigned int flagUnderTest = GENERATE(hipEventDefault,
hipEventBlockingSync, hipEventDisableTiming,
hipEventInterprocess | hipEventDisableTiming,
hipEventReleaseToDevice, hipEventReleaseToSystem);
#else
// On Non-AMD platforms hipEventReleaseToDevice / hipEventReleaseToSystem are not defined
const unsigned int flagUnderTest = GENERATE(hipEventDefault, hipEventBlockingSync, hipEventDisableTiming, hipEventInterprocess | hipEventDisableTiming);
// On Non-AMD platforms hipEventReleaseToDevice / hipEventReleaseToSystem
// are not defined.
const unsigned int flagUnderTest = GENERATE(hipEventDefault,
hipEventBlockingSync,
hipEventDisableTiming,
hipEventInterprocess | hipEventDisableTiming);
#endif
hipEvent_t event;
HIP_CHECK(hipEventCreateWithFlags(&event, flagUnderTest));
REQUIRE(event != nullptr);
HIP_CHECK(hipEventDestroy(event));
}
/**
Since flags hipEventReleaseToSystem, hipEventDisableSystemFence and hipEventReleaseToDevice
are AMD specific flags, hence the following tests enabled only for AMD.
*/
#if HT_AMD
enum class eSyncToTest {
eStreamSynchronize,
eDeviceSynchronize,
eStreamWaitEvent,
eEventSynchronize
};
enum class eMemoryToTest {
eHostVisibleMemory,
eNonCoherentHostMemory,
eCoherentHostMemory
};
static void init_input(int* a, size_t size) {
unsigned int seed = time(nullptr);
for (size_t i = 0; i < size; i++) {
a[i] = (HipTest::RAND_R(&seed) & 0xFF);
}
}
static void check_output(int* inp, int* out, size_t size) {
for (size_t i = 0; i < size; i++) {
REQUIRE(out[i] == (inp[i]*inp[i]));
}
}
// local function
static void testMemCoherency(eSyncToTest test, eMemoryToTest mem,
uint32_t flags) {
hipDeviceProp_t prop;
HIP_CHECK(hipGetDeviceProperties(&prop, 0));
// If the GPU is not large bar then exit the test
if (prop.isLargeBar != 1) {
HipTest::HIP_SKIP_TEST("Skipping test as large bar is not supported");
return;
}
constexpr auto blocksPerCU = 6;
unsigned grid_size = HipTest::setNumBlocks(blocksPerCU,
block_size, buffer_size);
hipEvent_t event;
HIP_CHECK(hipEventCreateWithFlags(&event, flags));
hipStream_t stream;
HIP_CHECK(hipStreamCreateWithFlags(&stream, 0x0));
int *ibuf_h, *buf_d;
ibuf_h = new int[buffer_size];
REQUIRE(ibuf_h != nullptr);
int total_iter = 0;
if (mem == eMemoryToTest::eHostVisibleMemory) {
HIP_CHECK(hipMalloc(&buf_d, buffer_size*sizeof(int)));
total_iter = test_iteration_hstvismem;
} else if (mem == eMemoryToTest::eNonCoherentHostMemory) {
HIP_CHECK(hipHostMalloc(&buf_d, buffer_size*sizeof(int),
hipHostMallocNonCoherent));
total_iter = test_iteration_noncohmem;
} else if (mem == eMemoryToTest::eCoherentHostMemory) {
HIP_CHECK(hipHostMalloc(&buf_d, buffer_size*sizeof(int),
hipHostMallocCoherent));
total_iter = test_iteration_noncohmem;
}
for (int iter = 0; iter < total_iter; iter++) {
// Inititalize the buffer with random data
init_input(ibuf_h, buffer_size);
HIP_CHECK(hipMemcpy(buf_d, ibuf_h, sizeof(int)*buffer_size,
hipMemcpyDefault));
HipTest::vector_square<int><<<grid_size, block_size, 0, stream>>>(
buf_d, buf_d, buffer_size);
HIP_CHECK(hipEventRecord(event, stream));
// test different synchronization APIs
if (test == eSyncToTest::eStreamSynchronize) {
HIP_CHECK(hipStreamSynchronize(stream));
} else if (test == eSyncToTest::eDeviceSynchronize) {
HIP_CHECK(hipDeviceSynchronize());
} else if (test == eSyncToTest::eEventSynchronize) {
HIP_CHECK(hipEventSynchronize(event));
} else if (test == eSyncToTest::eStreamWaitEvent) {
HIP_CHECK(hipStreamWaitEvent(stream, event, 0));
}
check_output(ibuf_h, buf_d, buffer_size);
}
delete[] ibuf_h;
HIP_CHECK(hipStreamDestroy(stream));
HIP_CHECK(hipEventDestroy(event));
if (mem == eMemoryToTest::eHostVisibleMemory) {
HIP_CHECK(hipFree(buf_d));
} else if ((mem == eMemoryToTest::eNonCoherentHostMemory) ||
(mem == eMemoryToTest::eCoherentHostMemory)) {
HIP_CHECK(hipHostFree(buf_d));
}
}
/**
* Test Description
* ------------------------
* - Check Synchronization effect on Host Visible Memory.
* Disable System fence when creating an event. Create a chunk of Host Visisble
* Memory using hipMalloc and initialize the memory with user data. Launch a
* kernel that writes to this memory location. Perform different synchronizations
* and validate that updated values are seen from host.
* Test source
* ------------------------
* - catch\unit\event\hipEventCreateWithFlags.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.6
*/
TEST_CASE("Unit_hipEventCreateWithFlags_DisableSystemFence_HstVisMem") {
SECTION("Check with hipStreamSynchronize") {
INFO("Check with hipStreamSynchronize");
testMemCoherency(eSyncToTest::eStreamSynchronize,
eMemoryToTest::eHostVisibleMemory, hipEventDisableSystemFence);
}
SECTION("Check with hipDeviceSynchronize") {
INFO("Check with hipDeviceSynchronize");
testMemCoherency(eSyncToTest::eDeviceSynchronize,
eMemoryToTest::eHostVisibleMemory, hipEventDisableSystemFence);
}
}
/**
* Test Description
* ------------------------
* - Check Synchronization effect on Host Visible Memory.
* Use Default Flag when creating an event. Create a chunk of Host Visisble
* Memory using hipMalloc and initialize the memory with user data. Launch
* a kernel that writes to this memory location. Perform different synchronizations
* and validate that updated values are seen from host.
* ------------------------
* - catch\unit\event\hipEventCreateWithFlags.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.6
*/
TEST_CASE("Unit_hipEventCreateWithFlags_DefaultFlg_HstVisMem") {
SECTION("Check with hipStreamSynchronize") {
INFO("Check with hipStreamSynchronize");
testMemCoherency(eSyncToTest::eStreamSynchronize,
eMemoryToTest::eHostVisibleMemory, hipEventDefault);
}
SECTION("Check with hipDeviceSynchronize") {
INFO("Check with hipDeviceSynchronize");
testMemCoherency(eSyncToTest::eDeviceSynchronize,
eMemoryToTest::eHostVisibleMemory, hipEventDefault);
}
SECTION("Check with hipEventSynchronize") {
INFO("Check with hipEventSynchronize");
testMemCoherency(eSyncToTest::eEventSynchronize,
eMemoryToTest::eHostVisibleMemory, hipEventDefault);
}
}
/**
* Test Description
* ------------------------
* - Check Synchronization effect on Non Coherent Host Memory.
* Disable System fence when creating an event. Create a chunk of Host Visisble
* Memory using hipMalloc and initialize the memory with user data. Launch a
* kernel that writes to this memory location. Perform different synchronizations
* and validate that updated values are seen from host.
* ------------------------
* - catch\unit\event\hipEventCreateWithFlags.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.6
*/
TEST_CASE("Unit_hipEventCreateWithFlags_DisableSystemFence_NonCohHstMem") {
SECTION("Check with hipStreamSynchronize") {
INFO("Check with hipStreamSynchronize");
testMemCoherency(eSyncToTest::eStreamSynchronize,
eMemoryToTest::eNonCoherentHostMemory, hipEventDisableSystemFence);
}
SECTION("Check with hipDeviceSynchronize") {
INFO("Check with hipDeviceSynchronize");
testMemCoherency(eSyncToTest::eDeviceSynchronize,
eMemoryToTest::eNonCoherentHostMemory, hipEventDisableSystemFence);
}
}
/**
* Test Description
* ------------------------
* - Check Synchronization effect on Non Coherent Host Memory.
* Use Default Flag when creating an event. Create a chunk of Host Visisble
* Memory using hipMalloc and initialize the memory with user data. Launch
* a kernel that writes to this memory location. Perform different
* synchronizations and validate that updated values are seen from host.
* ------------------------
* - catch\unit\event\hipEventCreateWithFlags.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.6
*/
TEST_CASE("Unit_hipEventCreateWithFlags_DefaultFlg_NonCohHstMem") {
SECTION("Check with hipStreamSynchronize") {
INFO("Check with hipStreamSynchronize");
testMemCoherency(eSyncToTest::eStreamSynchronize,
eMemoryToTest::eNonCoherentHostMemory, hipEventDefault);
}
SECTION("Check with hipDeviceSynchronize") {
INFO("Check with hipDeviceSynchronize");
testMemCoherency(eSyncToTest::eDeviceSynchronize,
eMemoryToTest::eNonCoherentHostMemory, hipEventDefault);
}
SECTION("Check with hipEventSynchronize") {
INFO("Check with hipEventSynchronize");
testMemCoherency(eSyncToTest::eEventSynchronize,
eMemoryToTest::eNonCoherentHostMemory, hipEventDefault);
}
}
/**
* Test Description
* ------------------------
* - Check Synchronization effect on Coherent Host Memory.
* Disable System fence when creating an event. Create a chunk of Host Visisble
* Memory using hipMalloc and initialize the memory with user data. Launch a
* kernel that writes to this memory location. Perform different synchronizations
* and validate that updated values are seen from host.
* ------------------------
* - catch\unit\event\hipEventCreateWithFlags.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.6
*/
TEST_CASE("Unit_hipEventCreateWithFlags_DisableSystemFence_CohHstMem") {
SECTION("Check with hipStreamSynchronize") {
INFO("Check with hipStreamSynchronize");
testMemCoherency(eSyncToTest::eStreamSynchronize,
eMemoryToTest::eCoherentHostMemory, hipEventDisableSystemFence);
}
SECTION("Check with hipDeviceSynchronize") {
INFO("Check with hipDeviceSynchronize");
testMemCoherency(eSyncToTest::eDeviceSynchronize,
eMemoryToTest::eCoherentHostMemory, hipEventDisableSystemFence);
}
SECTION("Check with hipEventSynchronize") {
INFO("Check with hipEventSynchronize");
testMemCoherency(eSyncToTest::eEventSynchronize,
eMemoryToTest::eCoherentHostMemory, hipEventDisableSystemFence);
}
}
/**
* Test Description
* ------------------------
* - Check Synchronization effect on Coherent Host Memory.
* Use Default Flag when creating an event. Create a chunk of Host Visisble
* Memory using hipMalloc and initialize the memory with user data. Launch a
* kernel that writes to this memory location. Perform different synchronizations
* and validate that updated values are seen from host.
* ------------------------
* - catch\unit\event\hipEventCreateWithFlags.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.6
*/
TEST_CASE("Unit_hipEventCreateWithFlags_DefaultFlg_CohHstMem") {
SECTION("Check with hipStreamSynchronize") {
INFO("Check with hipStreamSynchronize");
testMemCoherency(eSyncToTest::eStreamSynchronize,
eMemoryToTest::eCoherentHostMemory, hipEventDefault);
}
SECTION("Check with hipDeviceSynchronize") {
INFO("Check with hipDeviceSynchronize");
testMemCoherency(eSyncToTest::eDeviceSynchronize,
eMemoryToTest::eCoherentHostMemory, hipEventDefault);
}
SECTION("Check with hipEventSynchronize") {
INFO("Check with hipEventSynchronize");
testMemCoherency(eSyncToTest::eEventSynchronize,
eMemoryToTest::eCoherentHostMemory, hipEventDefault);
}
}
#endif
+1
Просмотреть файл
@@ -126,6 +126,7 @@ set(TEST_SRC
hipGraphExecDestroy.cc
hipGraphUpload.cc
hipGraphKernelNodeCopyAttributes.cc
hipGraphAddNodeBeginCapture.cc
hipGraphCycle.cc
hipGraphKernelNodeGetAttribute.cc
hipGraphKernelNodeSetAttribute.cc)
+951
Просмотреть файл
@@ -0,0 +1,951 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip_test_common.hh>
#include <hip_test_checkers.hh>
#include <hip_test_kernels.hh>
#pragma clang diagnostic ignored "-Wunused-parameter"
#define SIZE (1024 * 1024)
static size_t Nbytes = SIZE * sizeof(int);
__device__ int globalOut[SIZE];
/**
* @addtogroup hipStreamBeginCapture hipStreamBeginCapture
* @{
* @ingroup GraphTest
* `hipStreamBeginCapture(hipStream_t stream, hipStreamCaptureMode mode)` -
* Returns the last error from a runtime call.
*/
static void verifyArrayMemset(int *A_h, int val) {
int expected_val = val | (val << 8) | (val << 16) | (val << 24);
for (size_t i = 0; i < SIZE; i++) {
if (A_h[i] != expected_val) {
INFO("Memset Validation failed at i " << i << " A_h[i] "<< A_h[i]);
REQUIRE(false);
}
}
}
__device__ __host__ static void callbackFunc(void *A_h) {
int *A = reinterpret_cast<int *>(A_h);
for (int i = 0; i < SIZE; i++) {
A[i] = i + i%2;
}
}
__global__ static void kCallbackFunc(void *A_h) {
callbackFunc(A_h);
}
static void verifyCallbackFunc(int *A_h) {
for (size_t i = 0; i < SIZE; i++) {
if (A_h[i] != static_cast<int>(i + i%2)) {
INFO("CallBack Validation failed i " << i << " A_h[i] "<< A_h[i]);
REQUIRE(false);
}
}
}
__global__ static void addGpuKernel(int *i_d) {
*i_d = *i_d + 1;
}
static void CpuCallback(void *args) {
// do nothing function
}
/**
* Test Description
* ------------------------
*  - Verify hipStreamBeginCapture, hipStreamEndCapture status with
* hipGraphAddHostNode api call.
* Test source
* ------------------------
*  - unit/graph/hipGraphAddNodeBeginCapture.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
TEST_CASE("Unit_hipStreamBeginCapture_with_hipGraphAddHostNode") {
hipGraph_t graph;
hipGraphExec_t graphExec;
hipGraphNode_t cpuGraphNode;
int *i_d;
HIP_CHECK(hipMalloc(&i_d, sizeof(int)));
REQUIRE(i_d != nullptr);
hipStream_t stream;
HIP_CHECK(hipStreamCreateWithFlags(&stream, hipStreamNonBlocking));
HIP_CHECK(hipStreamBeginCapture(stream, hipStreamCaptureModeThreadLocal));
HIP_CHECK(hipGraphCreate(&graph, 0));
hipHostNodeParams p = {0, 0};
p.fn = CpuCallback;
p.userData = nullptr;
HIP_CHECK(hipGraphAddHostNode(&cpuGraphNode, graph, nullptr, 0, &p));
addGpuKernel<<<1, 1, 0, stream>>>(i_d);
HIP_CHECK(hipStreamEndCapture(stream, &graph));
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, NULL, NULL, 0));
HIP_CHECK(hipGraphLaunch(graphExec, stream));
HIP_CHECK(hipStreamSynchronize(stream));
HIP_CHECK(hipFree(i_d));
HIP_CHECK(hipGraphExecDestroy(graphExec));
HIP_CHECK(hipGraphDestroy(graph));
HIP_CHECK(hipStreamDestroy(stream));
}
/**
* Test Description
* ------------------------
*  - Capture graph sequence using hipStreamBeginCapture and try to add a new
* node to the capture stream using hipStreamUpdateCaptureDependencies api
* which will copy back the result from the existing graph and verify
* 1) Add a hipGraphAddMemcpyNode1D node before hipStreamEndCapture
* 2) Add a hipGraphAddMemsetNode node before hipStreamEndCapture
* 3) Add a hipGraphAddMemcpyNode node before hipStreamEndCapture
* 4) Add a hipGraphAddKernelNode node before hipStreamEndCapture
* 5) Add a hipGraphAddMemcpyNodeToSymbol and hipGraphAddMemcpyNodeFromSymbol
* node before hipStreamEndCapture
* 6) Add a hipGraphAddHostNode node before hipStreamEndCapture
* 7) Add a hipGraphAddChildGraphNode node before hipStreamEndCapture
* 8) Add a hipGraphAddEmptyNode node before hipStreamEndCapture
* 9) Add a hipGraphAddEventRecordNode node before hipStreamEndCapture
* 10) Add a hipGraphAddEventWaitNode node before hipStreamEndCapture
* Test source
* ------------------------
*  - unit/graph/hipGraphAddNodeBeginCapture.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
TEST_CASE("Unit_hipStreamEndCapture_later_and_add_a_node_inbetween") {
hipGraphExec_t graphExec;
hipGraphNode_t memcpyD2H_C;
hipStream_t stream;
int *A_d, *B_d, *C_d, *A_h, *B_h, *C_h;
HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, SIZE, false);
HIP_CHECK(hipStreamCreate(&stream));
HIP_CHECK(hipStreamBeginCapture(stream, hipStreamCaptureModeGlobal));
HIP_CHECK(hipMemcpyAsync(A_d, A_h, Nbytes, hipMemcpyHostToDevice, stream));
HIP_CHECK(hipMemcpyAsync(B_d, B_h, Nbytes, hipMemcpyHostToDevice, stream));
HipTest::vectorADD<int><<<1, 1, 0, stream>>>(A_d, B_d, C_d, SIZE);
hipStreamCaptureStatus captureStatus{hipStreamCaptureStatusNone};
hipGraph_t capGraph{nullptr};
const hipGraphNode_t* nodelist{};
size_t numDependencies;
HIP_CHECK(hipStreamGetCaptureInfo_v2(stream, &captureStatus, nullptr,
&capGraph, &nodelist, &numDependencies));
REQUIRE(captureStatus == hipStreamCaptureStatusActive);
REQUIRE(capGraph != nullptr);
SECTION("Add a hipGraphAddMemcpyNode1D node before hipStreamEndCapture") {
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_C, capGraph, nodelist,
numDependencies, C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
HIP_CHECK(hipStreamUpdateCaptureDependencies(stream, &memcpyD2H_C, 1,
hipStreamSetCaptureDependencies));
HIP_CHECK(hipStreamEndCapture(stream, &capGraph));
// Instantiate and launch the graph
HIP_CHECK(hipGraphInstantiate(&graphExec, capGraph, nullptr, nullptr, 0));
HIP_CHECK(hipGraphLaunch(graphExec, stream));
HIP_CHECK(hipStreamSynchronize(stream));
// Verify execution result
HipTest::checkVectorADD(A_h, B_h, C_h, SIZE);
}
SECTION("Add a hipGraphAddMemsetNode node before hipStreamEndCapture") {
hipGraphNode_t memsetNode;
int memSetVal = 7;
hipMemsetParams memsetParams{};
memset(&memsetParams, 0, sizeof(memsetParams));
memsetParams.dst = reinterpret_cast<void*>(C_d);
memsetParams.value = memSetVal;
memsetParams.pitch = 0;
memsetParams.elementSize = sizeof(char);
memsetParams.width = Nbytes;
memsetParams.height = 1;
HIP_CHECK(hipGraphAddMemsetNode(&memsetNode, capGraph, nodelist,
numDependencies, &memsetParams));
HIP_CHECK(hipStreamUpdateCaptureDependencies(stream, &memsetNode, 1,
hipStreamSetCaptureDependencies));
HIP_CHECK(hipMemcpyAsync(C_h, C_d, Nbytes, hipMemcpyDeviceToHost, stream));
HIP_CHECK(hipStreamEndCapture(stream, &capGraph));
// Instantiate and launch the graph
HIP_CHECK(hipGraphInstantiate(&graphExec, capGraph, nullptr, nullptr, 0));
HIP_CHECK(hipGraphLaunch(graphExec, stream));
HIP_CHECK(hipStreamSynchronize(stream));
// Verify execution result
verifyArrayMemset(C_h, memSetVal);
}
SECTION("Add a hipGraphAddMemcpyNode node before hipStreamEndCapture") {
hipMemcpy3DParms myparams;
hipGraphNode_t memcpyNode;
memset(&myparams, 0x0, sizeof(hipMemcpy3DParms));
myparams.srcPos = make_hipPos(0, 0, 0);
myparams.dstPos = make_hipPos(0, 0, 0);
myparams.srcPtr = make_hipPitchedPtr(C_d, Nbytes, 1, 1);
myparams.dstPtr = make_hipPitchedPtr(C_h, Nbytes, 1, 1);
myparams.extent = make_hipExtent(Nbytes, 1, 1);
myparams.kind = hipMemcpyDeviceToHost;
HIP_CHECK(hipGraphAddMemcpyNode(&memcpyNode, capGraph, nodelist,
numDependencies, &myparams));
HIP_CHECK(hipStreamUpdateCaptureDependencies(stream, &memcpyNode, 1,
hipStreamSetCaptureDependencies));
HIP_CHECK(hipStreamEndCapture(stream, &capGraph));
// Instantiate and launch the graph
HIP_CHECK(hipGraphInstantiate(&graphExec, capGraph, nullptr, nullptr, 0));
HIP_CHECK(hipGraphLaunch(graphExec, stream));
HIP_CHECK(hipStreamSynchronize(stream));
// Verify execution result
HipTest::checkVectorADD(A_h, B_h, C_h, SIZE);
}
SECTION("Add a hipGraphAddKernelNode node before hipStreamEndCapture") {
hipGraphNode_t kNode;
hipKernelNodeParams kNodeParams{};
memset(&kNodeParams, 0x00, sizeof(kNodeParams));
void* kernelArgs[] = {&C_d};
kNodeParams.func = reinterpret_cast<void *>(kCallbackFunc);
kNodeParams.gridDim = dim3(1);
kNodeParams.blockDim = dim3(256);
kNodeParams.sharedMemBytes = 0;
kNodeParams.kernelParams = reinterpret_cast<void**>(kernelArgs);
kNodeParams.extra = nullptr;
HIP_CHECK(hipGraphAddKernelNode(&kNode, capGraph, nodelist,
numDependencies, &kNodeParams));
HIP_CHECK(hipStreamUpdateCaptureDependencies(stream, &kNode, 1,
hipStreamSetCaptureDependencies));
HIP_CHECK(hipMemcpyAsync(C_h, C_d, Nbytes, hipMemcpyDeviceToHost, stream));
HIP_CHECK(hipStreamEndCapture(stream, &capGraph));
// Instantiate and launch the graph
HIP_CHECK(hipGraphInstantiate(&graphExec, capGraph, nullptr, nullptr, 0));
HIP_CHECK(hipGraphLaunch(graphExec, stream));
HIP_CHECK(hipStreamSynchronize(stream));
// Verify execution result
verifyCallbackFunc(C_h);
}
SECTION("Add hipGraphAddMemcpyNodeToSymbol node before hipStreamEndCapture") {
hipGraphNode_t memcpyToSymNode, memcpyFromSymNode;
HIP_CHECK(hipGraphAddMemcpyNodeToSymbol(&memcpyToSymNode, capGraph,
nodelist, numDependencies, HIP_SYMBOL(globalOut),
C_d, Nbytes, 0, hipMemcpyDeviceToDevice));
HIP_CHECK(hipGraphAddMemcpyNodeFromSymbol(&memcpyFromSymNode, capGraph,
nullptr, 0, C_h, HIP_SYMBOL(globalOut),
Nbytes, 0, hipMemcpyDeviceToHost));
HIP_CHECK(hipGraphAddDependencies(capGraph, &memcpyToSymNode,
&memcpyFromSymNode, 1));
HIP_CHECK(hipStreamUpdateCaptureDependencies(stream, &memcpyToSymNode, 1,
hipStreamSetCaptureDependencies));
HIP_CHECK(hipStreamUpdateCaptureDependencies(stream, &memcpyFromSymNode, 1,
hipStreamSetCaptureDependencies));
HIP_CHECK(hipStreamEndCapture(stream, &capGraph));
// Instantiate and launch the graph
HIP_CHECK(hipGraphInstantiate(&graphExec, capGraph, nullptr, nullptr, 0));
HIP_CHECK(hipGraphLaunch(graphExec, stream));
HIP_CHECK(hipStreamSynchronize(stream));
// Verify execution result
HipTest::checkVectorADD(A_h, B_h, C_h, SIZE);
}
SECTION("Add a hipGraphAddHostNode node before hipStreamEndCapture") {
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_C, capGraph, nodelist,
numDependencies, C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
hipGraphNode_t hostNode;
hipHostNodeParams hostParams = {0, 0};
hostParams.fn = callbackFunc;
hostParams.userData = C_h;
HIP_CHECK(hipGraphAddHostNode(&hostNode, capGraph,
nullptr, 0, &hostParams));
HIP_CHECK(hipGraphAddDependencies(capGraph, &memcpyD2H_C, &hostNode, 1));
HIP_CHECK(hipStreamUpdateCaptureDependencies(stream, &memcpyD2H_C, 1,
hipStreamSetCaptureDependencies));
HIP_CHECK(hipStreamUpdateCaptureDependencies(stream, &hostNode, 1,
hipStreamSetCaptureDependencies));
HIP_CHECK(hipStreamEndCapture(stream, &capGraph));
// Instantiate and launch the graph
HIP_CHECK(hipGraphInstantiate(&graphExec, capGraph, nullptr, nullptr, 0));
HIP_CHECK(hipGraphLaunch(graphExec, stream));
HIP_CHECK(hipStreamSynchronize(stream));
// Verify execution result
verifyCallbackFunc(C_h);
}
SECTION("Add a hipGraphAddChildGraphNode node before hipStreamEndCapture") {
hipGraph_t childGraph;
hipGraphNode_t memsetNode, childGraphNode;
int memSetVal = 7;
hipMemsetParams memsetParams{};
memset(&memsetParams, 0, sizeof(memsetParams));
memsetParams.dst = reinterpret_cast<void*>(C_d);
memsetParams.value = memSetVal;
memsetParams.pitch = 0;
memsetParams.elementSize = sizeof(char);
memsetParams.width = Nbytes;
memsetParams.height = 1;
HIP_CHECK(hipGraphCreate(&childGraph, 0));
HIP_CHECK(hipGraphAddMemsetNode(&memsetNode, childGraph, nullptr, 0,
&memsetParams));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_C, childGraph, nullptr, 0,
C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
HIP_CHECK(hipGraphAddDependencies(childGraph, &memsetNode,
&memcpyD2H_C, 1));
HIP_CHECK(hipGraphAddChildGraphNode(&childGraphNode, capGraph, nodelist,
numDependencies, childGraph));
HIP_CHECK(hipStreamUpdateCaptureDependencies(stream, &childGraphNode, 1,
hipStreamSetCaptureDependencies));
HIP_CHECK(hipStreamEndCapture(stream, &capGraph));
// Instantiate and launch the graph
HIP_CHECK(hipGraphInstantiate(&graphExec, capGraph, nullptr, nullptr, 0));
HIP_CHECK(hipGraphLaunch(graphExec, stream));
HIP_CHECK(hipStreamSynchronize(stream));
// Verify execution result
verifyArrayMemset(C_h, memSetVal);
HIP_CHECK(hipGraphDestroy(childGraph));
}
SECTION("Add a hipGraphAddEmptyNode node before hipStreamEndCapture") {
hipGraphNode_t emptyNode;
HIP_CHECK(hipGraphAddEmptyNode(&emptyNode, capGraph,
nodelist, numDependencies));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_C, capGraph, nullptr, 0,
C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
HIP_CHECK(hipGraphAddDependencies(capGraph, &emptyNode, &memcpyD2H_C, 1));
HIP_CHECK(hipStreamUpdateCaptureDependencies(stream, &emptyNode, 1,
hipStreamSetCaptureDependencies));
HIP_CHECK(hipStreamUpdateCaptureDependencies(stream, &memcpyD2H_C, 1,
hipStreamSetCaptureDependencies));
HIP_CHECK(hipStreamEndCapture(stream, &capGraph));
// Instantiate and launch the graph
HIP_CHECK(hipGraphInstantiate(&graphExec, capGraph, nullptr, nullptr, 0));
HIP_CHECK(hipGraphLaunch(graphExec, stream));
HIP_CHECK(hipStreamSynchronize(stream));
// Verify execution result
HipTest::checkVectorADD(A_h, B_h, C_h, SIZE);
}
SECTION("Add hipGraphAddEventRecordNode node before hipStreamEndCapture") {
hipGraphNode_t event_start, event_end;
hipEvent_t eventstart, eventend;
HIP_CHECK(hipEventCreate(&eventstart));
HIP_CHECK(hipEventCreate(&eventend));
HIP_CHECK(hipGraphAddEventRecordNode(&event_start, capGraph,
nodelist, numDependencies, eventstart));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_C, capGraph, nullptr, 0,
C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
HIP_CHECK(hipGraphAddEventRecordNode(&event_end, capGraph,
nullptr, 0, eventend));
HIP_CHECK(hipGraphAddDependencies(capGraph, &event_start, &memcpyD2H_C, 1));
HIP_CHECK(hipGraphAddDependencies(capGraph, &memcpyD2H_C, &event_end, 1));
HIP_CHECK(hipStreamUpdateCaptureDependencies(stream, &event_start, 1,
hipStreamSetCaptureDependencies));
HIP_CHECK(hipStreamUpdateCaptureDependencies(stream, &memcpyD2H_C, 1,
hipStreamSetCaptureDependencies));
HIP_CHECK(hipStreamUpdateCaptureDependencies(stream, &event_end, 1,
hipStreamSetCaptureDependencies));
HIP_CHECK(hipStreamEndCapture(stream, &capGraph));
// Instantiate and launch the graph
HIP_CHECK(hipGraphInstantiate(&graphExec, capGraph, nullptr, nullptr, 0));
HIP_CHECK(hipGraphLaunch(graphExec, stream));
HIP_CHECK(hipStreamSynchronize(stream));
HIP_CHECK(hipEventSynchronize(eventend));
// Verify execution result
HipTest::checkVectorADD(A_h, B_h, C_h, SIZE);
float t = 0.0f;
HIP_CHECK(hipEventElapsedTime(&t, eventstart, eventend));
REQUIRE(t > 0.0f);
HIP_CHECK(hipEventDestroy(eventstart));
HIP_CHECK(hipEventDestroy(eventend));
}
SECTION("Add hipGraphAddEventWaitNode node before hipStreamEndCapture") {
hipGraphNode_t eventRecNode, eventWaitNode;
hipEvent_t event;
HIP_CHECK(hipEventCreate(&event));
HIP_CHECK(hipGraphAddEventRecordNode(&eventRecNode, capGraph,
nodelist, numDependencies, event));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_C, capGraph, nullptr, 0,
C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
HIP_CHECK(hipGraphAddEventWaitNode(&eventWaitNode, capGraph,
nullptr, 0, event));
HIP_CHECK(hipGraphAddDependencies(capGraph, &eventRecNode,
&memcpyD2H_C, 1));
HIP_CHECK(hipGraphAddDependencies(capGraph, &memcpyD2H_C,
&eventWaitNode, 1));
HIP_CHECK(hipStreamUpdateCaptureDependencies(stream, &eventRecNode, 1,
hipStreamSetCaptureDependencies));
HIP_CHECK(hipStreamUpdateCaptureDependencies(stream, &memcpyD2H_C, 1,
hipStreamSetCaptureDependencies));
HIP_CHECK(hipStreamUpdateCaptureDependencies(stream, &eventWaitNode, 1,
hipStreamSetCaptureDependencies));
HIP_CHECK(hipStreamEndCapture(stream, &capGraph));
// Instantiate and launch the graph
HIP_CHECK(hipGraphInstantiate(&graphExec, capGraph, nullptr, nullptr, 0));
HIP_CHECK(hipGraphLaunch(graphExec, stream));
HIP_CHECK(hipStreamSynchronize(stream));
HIP_CHECK(hipEventSynchronize(event));
// Verify execution result
HipTest::checkVectorADD(A_h, B_h, C_h, SIZE);
HIP_CHECK(hipEventDestroy(event));
}
HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, false);
HIP_CHECK(hipGraphExecDestroy(graphExec));
HIP_CHECK(hipGraphDestroy(capGraph));
HIP_CHECK(hipStreamDestroy(stream));
}
/**
* Test Description
* ------------------------
*  - Capture graph sequence using hipStreamBeginCapture and hipStreamEndCapture
* Try to add a new node and link this new node to the existing graph
* which will copy back the result from the existing graph and verify
* 1) Add a hipGraphAddMemcpyNode1D node after hipStreamEndCapture
* 2) Add a hipGraphAddMemsetNode node after hipStreamEndCapture
* 3) Add a hipGraphAddMemcpyNode node after hipStreamEndCapture
* 4) Add a hipGraphAddKernelNode node after hipStreamEndCapture
* 5) Add a hipGraphAddMemcpyNodeToSymbol and hipGraphAddMemcpyNodeFromSymbol
* node after hipStreamEndCapture
* 6) Add a hipGraphAddHostNode node after hipStreamEndCapture
* 7) Add a hipGraphAddChildGraphNode node after hipStreamEndCapture
* 8) Add a hipGraphAddEmptyNode node after hipStreamEndCapture
* 9) Add a hipGraphAddEventRecordNode node after hipStreamEndCapture
* 10) Add a hipGraphAddEventWaitNode node after hipStreamEndCapture
* Test source
* ------------------------
*  - unit/graph/hipGraphAddNodeBeginCapture.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
TEST_CASE("Unit_hipStreamEndCapture_first_and_add_a_node_later") {
hipGraph_t graph;
hipGraphExec_t graphExec;
hipGraphNode_t memcpyD2H_C;
hipStream_t stream;
int *A_d, *B_d, *C_d, *A_h, *B_h, *C_h;
HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, SIZE, false);
HIP_CHECK(hipStreamCreate(&stream));
HIP_CHECK(hipStreamBeginCapture(stream, hipStreamCaptureModeGlobal));
HIP_CHECK(hipMemcpyAsync(A_d, A_h, Nbytes, hipMemcpyHostToDevice, stream));
HIP_CHECK(hipMemcpyAsync(B_d, B_h, Nbytes, hipMemcpyHostToDevice, stream));
HipTest::vectorSUB<int><<<1, 1, 0, stream>>>(A_d, B_d, C_d, SIZE);
HIP_CHECK(hipStreamEndCapture(stream, &graph));
size_t numN{};
int foundAt = -1;
HIP_CHECK(hipGraphGetNodes(graph, nullptr, &numN));
hipGraphNode_t* nodes =
reinterpret_cast<hipGraphNode_t *>(malloc(numN * sizeof(hipGraphNode_t)));
REQUIRE(nodes != nullptr);
HIP_CHECK(hipGraphGetNodes(graph, nodes, &numN));
hipGraphNodeType nodeType;
for (int i = 0; i < numN; i++) {
HIP_CHECK(hipGraphNodeGetType(nodes[i], &nodeType));
if (nodeType == hipGraphNodeTypeKernel) {
foundAt = i;
break;
}
}
SECTION("Add a hipGraphAddMemcpyNode1D node after hipStreamEndCapture") {
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_C, graph, nullptr, 0,
C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
HIP_CHECK(hipGraphAddDependencies(graph, &nodes[foundAt], &memcpyD2H_C, 1));
// Instantiate and launch the graph
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0));
HIP_CHECK(hipGraphLaunch(graphExec, stream));
HIP_CHECK(hipStreamSynchronize(stream));
// Verify execution result
HipTest::checkVectorSUB(A_h, B_h, C_h, SIZE);
}
SECTION("Add a hipGraphAddMemsetNode node after hipStreamEndCapture") {
hipGraphNode_t memsetNode;
int memSetVal = 7;
hipMemsetParams memsetParams{};
memset(&memsetParams, 0, sizeof(memsetParams));
memsetParams.dst = reinterpret_cast<void*>(C_d);
memsetParams.value = memSetVal;
memsetParams.pitch = 0;
memsetParams.elementSize = sizeof(char);
memsetParams.width = Nbytes;
memsetParams.height = 1;
HIP_CHECK(hipGraphAddMemsetNode(&memsetNode, graph, nullptr, 0,
&memsetParams));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_C, graph, nullptr, 0,
C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
HIP_CHECK(hipGraphAddDependencies(graph, &nodes[foundAt], &memsetNode, 1));
HIP_CHECK(hipGraphAddDependencies(graph, &memsetNode, &memcpyD2H_C, 1));
// Instantiate and launch the graph
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0));
HIP_CHECK(hipGraphLaunch(graphExec, stream));
HIP_CHECK(hipStreamSynchronize(stream));
// Verify execution result
verifyArrayMemset(C_h, memSetVal);
}
SECTION("Add a hipGraphAddMemcpyNode node after hipStreamEndCapture") {
hipMemcpy3DParms myparams;
hipGraphNode_t memcpyNode;
memset(&myparams, 0x0, sizeof(hipMemcpy3DParms));
myparams.srcPos = make_hipPos(0, 0, 0);
myparams.dstPos = make_hipPos(0, 0, 0);
myparams.srcPtr = make_hipPitchedPtr(C_d, Nbytes, 1, 1);
myparams.dstPtr = make_hipPitchedPtr(C_h, Nbytes, 1, 1);
myparams.extent = make_hipExtent(Nbytes, 1, 1);
myparams.kind = hipMemcpyDeviceToHost;
HIP_CHECK(hipGraphAddMemcpyNode(&memcpyNode, graph, nullptr, 0, &myparams));
HIP_CHECK(hipGraphAddDependencies(graph, &nodes[foundAt], &memcpyNode, 1));
// Instantiate and launch the graph
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0));
HIP_CHECK(hipGraphLaunch(graphExec, stream));
HIP_CHECK(hipStreamSynchronize(stream));
// Verify execution result
HipTest::checkVectorSUB(A_h, B_h, C_h, SIZE);
}
SECTION("Add a hipGraphAddKernelNode node after hipStreamEndCapture") {
hipGraphNode_t kNode;
hipKernelNodeParams kNodeParams{};
memset(&kNodeParams, 0x00, sizeof(kNodeParams));
void* kernelArgs[] = {&C_d};
kNodeParams.func = reinterpret_cast<void *>(kCallbackFunc);
kNodeParams.gridDim = dim3(1);
kNodeParams.blockDim = dim3(256);
kNodeParams.sharedMemBytes = 0;
kNodeParams.kernelParams = reinterpret_cast<void**>(kernelArgs);
kNodeParams.extra = nullptr;
HIP_CHECK(hipGraphAddKernelNode(&kNode, graph, nullptr, 0, &kNodeParams));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_C, graph, nullptr, 0,
C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
HIP_CHECK(hipGraphAddDependencies(graph, &nodes[foundAt], &kNode, 1));
HIP_CHECK(hipGraphAddDependencies(graph, &kNode, &memcpyD2H_C, 1));
// Instantiate and launch the graph
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0));
HIP_CHECK(hipGraphLaunch(graphExec, stream));
HIP_CHECK(hipStreamSynchronize(stream));
// Verify execution result
verifyCallbackFunc(C_h);
}
SECTION("Add hipGraphAddMemcpyNodeToSymbol node after hipStreamEndCapture") {
hipGraphNode_t memcpyToSymNode, memcpyFromSymNode;
HIP_CHECK(hipGraphAddMemcpyNodeToSymbol(&memcpyToSymNode, graph, nullptr,
0, HIP_SYMBOL(globalOut), C_d, Nbytes, 0,
hipMemcpyDeviceToDevice));
HIP_CHECK(hipGraphAddMemcpyNodeFromSymbol(&memcpyFromSymNode, graph,
nullptr, 0, C_h, HIP_SYMBOL(globalOut),
Nbytes, 0, hipMemcpyDeviceToHost));
HIP_CHECK(hipGraphAddDependencies(graph, &nodes[foundAt],
&memcpyToSymNode, 1));
HIP_CHECK(hipGraphAddDependencies(graph, &memcpyToSymNode,
&memcpyFromSymNode, 1));
// Instantiate and launch the graph
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0));
HIP_CHECK(hipGraphLaunch(graphExec, stream));
HIP_CHECK(hipStreamSynchronize(stream));
// Verify execution result
HipTest::checkVectorSUB(A_h, B_h, C_h, SIZE);
}
SECTION("Add hipGraphAddHostNode node after hipStreamEndCapture") {
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_C, graph, nullptr, 0,
C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
hipGraphNode_t hostNode;
hipHostNodeParams hostParams = {0, 0};
hostParams.fn = callbackFunc;
hostParams.userData = C_h;
HIP_CHECK(hipGraphAddHostNode(&hostNode, graph, nullptr, 0, &hostParams));
HIP_CHECK(hipGraphAddDependencies(graph, &nodes[foundAt], &memcpyD2H_C, 1));
HIP_CHECK(hipGraphAddDependencies(graph, &memcpyD2H_C, &hostNode, 1));
// Instantiate and launch the graph
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0));
HIP_CHECK(hipGraphLaunch(graphExec, stream));
HIP_CHECK(hipStreamSynchronize(stream));
// Verify execution result
verifyCallbackFunc(C_h);
}
SECTION("Add hipGraphAddChildGraphNode node after hipStreamEndCapture") {
hipGraph_t childGraph;
hipGraphNode_t memsetNode, childGraphNode;
int memSetVal = 7;
hipMemsetParams memsetParams{};
memset(&memsetParams, 0, sizeof(memsetParams));
memsetParams.dst = reinterpret_cast<void*>(C_d);
memsetParams.value = memSetVal;
memsetParams.pitch = 0;
memsetParams.elementSize = sizeof(char);
memsetParams.width = Nbytes;
memsetParams.height = 1;
HIP_CHECK(hipGraphCreate(&childGraph, 0));
HIP_CHECK(hipGraphAddMemsetNode(&memsetNode, childGraph, nullptr, 0,
&memsetParams));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_C, childGraph, nullptr, 0,
C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
HIP_CHECK(hipGraphAddDependencies(childGraph, &memsetNode,
&memcpyD2H_C, 1));
HIP_CHECK(hipGraphAddChildGraphNode(&childGraphNode, graph, nullptr, 0,
childGraph));
HIP_CHECK(hipGraphAddDependencies(graph, &nodes[foundAt],
&childGraphNode, 1));
// Instantiate and launch the graph
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0));
HIP_CHECK(hipGraphLaunch(graphExec, stream));
HIP_CHECK(hipStreamSynchronize(stream));
// Verify execution result
verifyArrayMemset(C_h, memSetVal);
HIP_CHECK(hipGraphDestroy(childGraph));
}
SECTION("Add hipGraphAddEmptyNode node after hipStreamEndCapture") {
hipGraphNode_t emptyNode;
HIP_CHECK(hipGraphAddEmptyNode(&emptyNode, graph, nullptr, 0));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_C, graph, nullptr, 0,
C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
HIP_CHECK(hipGraphAddDependencies(graph, &nodes[foundAt], &emptyNode, 1));
HIP_CHECK(hipGraphAddDependencies(graph, &emptyNode, &memcpyD2H_C, 1));
// Instantiate and launch the graph
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0));
HIP_CHECK(hipGraphLaunch(graphExec, stream));
HIP_CHECK(hipStreamSynchronize(stream));
// Verify execution result
HipTest::checkVectorSUB(A_h, B_h, C_h, SIZE);
}
SECTION("Add hipGraphAddEventRecordNode node after hipStreamEndCapture") {
hipGraphNode_t event_start, event_end;
hipEvent_t eventstart, eventend;
HIP_CHECK(hipEventCreate(&eventstart));
HIP_CHECK(hipEventCreate(&eventend));
HIP_CHECK(hipGraphAddEventRecordNode(&event_start, graph,
nullptr, 0, eventstart));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_C, graph, nullptr, 0,
C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
HIP_CHECK(hipGraphAddEventRecordNode(&event_end, graph,
nullptr, 0, eventend));
HIP_CHECK(hipGraphAddDependencies(graph, &nodes[foundAt], &event_start, 1));
HIP_CHECK(hipGraphAddDependencies(graph, &event_start, &memcpyD2H_C, 1));
HIP_CHECK(hipGraphAddDependencies(graph, &memcpyD2H_C, &event_end, 1));
// Instantiate and launch the graph
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0));
HIP_CHECK(hipGraphLaunch(graphExec, stream));
HIP_CHECK(hipStreamSynchronize(stream));
HIP_CHECK(hipEventSynchronize(eventend));
// Verify execution result
HipTest::checkVectorSUB(A_h, B_h, C_h, SIZE);
float t = 0.0f;
HIP_CHECK(hipEventElapsedTime(&t, eventstart, eventend));
REQUIRE(t > 0.0f);
HIP_CHECK(hipEventDestroy(eventstart));
HIP_CHECK(hipEventDestroy(eventend));
}
SECTION("Add hipGraphAddEventWaitNode node after hipStreamEndCapture") {
hipGraphNode_t eventRecNode, eventWaitNode;
hipEvent_t event;
HIP_CHECK(hipEventCreate(&event));
HIP_CHECK(hipGraphAddEventRecordNode(&eventRecNode, graph,
nullptr, 0, event));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_C, graph, nullptr, 0,
C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
HIP_CHECK(hipGraphAddEventWaitNode(&eventWaitNode, graph,
nullptr, 0, event));
HIP_CHECK(hipGraphAddDependencies(graph, &nodes[foundAt],
&eventRecNode, 1));
HIP_CHECK(hipGraphAddDependencies(graph, &eventRecNode, &memcpyD2H_C, 1));
HIP_CHECK(hipGraphAddDependencies(graph, &memcpyD2H_C, &eventWaitNode, 1));
// Instantiate and launch the graph
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0));
HIP_CHECK(hipGraphLaunch(graphExec, stream));
HIP_CHECK(hipStreamSynchronize(stream));
HIP_CHECK(hipEventSynchronize(event));
// Verify execution result
HipTest::checkVectorSUB(A_h, B_h, C_h, SIZE);
HIP_CHECK(hipEventDestroy(event));
}
free(nodes);
HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, false);
HIP_CHECK(hipGraphExecDestroy(graphExec));
HIP_CHECK(hipGraphDestroy(graph));
HIP_CHECK(hipStreamDestroy(stream));
}
/**
* Test Description
* ------------------------
*  - Capture graph sequence using hipStreamBeginCapture and hipStreamEndCapture
* Add some new node to the same graph and execute it and verify
* Test source
* ------------------------
*  - unit/graph/hipGraphAddNodeBeginCapture.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
TEST_CASE("Unit_hipStreamEndCapture_first_and_add_other_graph_node_later") {
hipGraph_t graph;
hipGraphExec_t graphExec;
hipGraphNode_t memcpyH2D_A, memcpyH2D_B, memcpyD2H_AC, memcpyH2D_C;
hipStream_t stream;
int *A_d, *B_d, *C_d, *A_h, *B_h, *C_h;
HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, SIZE, false);
int *A_d1, *B_d1, *C_d1, *A_h1, *B_h1, *C_h1;
HipTest::initArrays(&A_d1, &B_d1, &C_d1, &A_h1, &B_h1, &C_h1, SIZE, false);
HIP_CHECK(hipStreamCreate(&stream));
HIP_CHECK(hipGraphCreate(&graph, 0));
HIP_CHECK(hipStreamBeginCapture(stream, hipStreamCaptureModeGlobal));
HIP_CHECK(hipMemcpyAsync(A_d1, A_h1, Nbytes, hipMemcpyHostToDevice, stream));
HIP_CHECK(hipMemcpyAsync(B_d1, B_h1, Nbytes, hipMemcpyHostToDevice, stream));
HipTest::vectorADD<int><<<1, 1, 0, stream>>>(A_d1, B_d1, C_d1, SIZE);
HIP_CHECK(hipMemcpyAsync(C_h1, C_d1, Nbytes, hipMemcpyDeviceToHost, stream));
HIP_CHECK(hipStreamEndCapture(stream, &graph));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_A, graph, nullptr, 0, A_d, A_h,
Nbytes, hipMemcpyHostToDevice));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_B, graph, nullptr, 0, B_d, B_h,
Nbytes, hipMemcpyHostToDevice));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D_C, graph, nullptr, 0, C_d, C_h,
Nbytes, hipMemcpyHostToDevice));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_AC, graph, nullptr, 0, A_h, C_d,
Nbytes, hipMemcpyDeviceToHost));
hipGraphNode_t hostNode;
hipHostNodeParams hostParams = {0, 0};
hostParams.fn = callbackFunc;
hostParams.userData = A_h;
HIP_CHECK(hipGraphAddHostNode(&hostNode, graph, nullptr, 0, &hostParams));
HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_A, &memcpyH2D_B, 1));
HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_B, &memcpyD2H_AC, 1));
HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D_C, &memcpyD2H_AC, 1));
HIP_CHECK(hipGraphAddDependencies(graph, &memcpyD2H_AC, &hostNode, 1));
// Instantiate and launch the graph
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0));
HIP_CHECK(hipGraphLaunch(graphExec, stream));
HIP_CHECK(hipStreamSynchronize(stream));
// Verify execution result fir above two graph operations
verifyCallbackFunc(A_h);
HipTest::checkVectorADD(A_h1, B_h1, C_h1, SIZE);
HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, false);
HipTest::freeArrays(A_d1, B_d1, C_d1, A_h1, B_h1, C_h1, false);
HIP_CHECK(hipGraphExecDestroy(graphExec));
HIP_CHECK(hipGraphDestroy(graph));
HIP_CHECK(hipStreamDestroy(stream));
}
/**
* Test Description
* ------------------------
*  - Capture graph sequence using hipStreamBeginCapture and
* add some new node before hipStreamEndCapture to the same graph
* and hipGraphAddEmptyNode to use as last node to grah to complete.
* Test source
* ------------------------
*  - unit/graph/hipGraphAddNodeBeginCapture.cc
* Test requirements
* ------------------------
*  - HIP_VERSION >= 5.6
*/
TEST_CASE("Unit_hipStreamEndCapture_later_and_addEmptyNode") {
hipGraphExec_t graphExec;
hipGraphNode_t memcpyD2H_C;
hipStream_t stream;
int *A_d, *B_d, *C_d, *A_h, *B_h, *C_h;
HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, SIZE, false);
HIP_CHECK(hipStreamCreate(&stream));
HIP_CHECK(hipStreamBeginCapture(stream, hipStreamCaptureModeGlobal));
HIP_CHECK(hipMemcpyAsync(A_d, A_h, Nbytes, hipMemcpyHostToDevice, stream));
HIP_CHECK(hipMemcpyAsync(B_d, B_h, Nbytes, hipMemcpyHostToDevice, stream));
HipTest::vectorSUB<int><<<1, 1, 0, stream>>>(A_d, B_d, C_d, SIZE);
hipStreamCaptureStatus captureStatus{hipStreamCaptureStatusNone};
hipGraph_t capGraph{nullptr};
const hipGraphNode_t* nodelist{};
size_t numDependencies;
HIP_CHECK(hipStreamGetCaptureInfo_v2(stream, &captureStatus, nullptr,
&capGraph, &nodelist, &numDependencies));
REQUIRE(captureStatus == hipStreamCaptureStatusActive);
REQUIRE(capGraph != nullptr);
hipGraphNode_t memsetNode;
int memSetVal = 7;
hipMemsetParams memsetParams{};
memset(&memsetParams, 0, sizeof(memsetParams));
memsetParams.dst = reinterpret_cast<void*>(C_d);
memsetParams.value = memSetVal;
memsetParams.pitch = 0;
memsetParams.elementSize = sizeof(char);
memsetParams.width = Nbytes;
memsetParams.height = 1;
HIP_CHECK(hipGraphAddMemsetNode(&memsetNode, capGraph, nodelist,
numDependencies, &memsetParams));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H_C, capGraph, nullptr, 0,
C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
hipGraphNode_t emptyNode;
HIP_CHECK(hipGraphAddEmptyNode(&emptyNode, capGraph, nullptr, 0));
HIP_CHECK(hipGraphAddDependencies(capGraph, &memsetNode, &memcpyD2H_C, 1));
HIP_CHECK(hipGraphAddDependencies(capGraph, &memcpyD2H_C, &emptyNode, 1));
HIP_CHECK(hipStreamUpdateCaptureDependencies(stream, &memsetNode, 1,
hipStreamSetCaptureDependencies));
HIP_CHECK(hipStreamUpdateCaptureDependencies(stream, &memcpyD2H_C, 1,
hipStreamSetCaptureDependencies));
HIP_CHECK(hipStreamUpdateCaptureDependencies(stream, &emptyNode, 1,
hipStreamSetCaptureDependencies));
HIP_CHECK(hipStreamEndCapture(stream, &capGraph));
// Instantiate and launch the graph
HIP_CHECK(hipGraphInstantiate(&graphExec, capGraph, nullptr, nullptr, 0));
HIP_CHECK(hipGraphLaunch(graphExec, stream));
HIP_CHECK(hipStreamSynchronize(stream));
// Verify execution result
verifyArrayMemset(C_h, memSetVal);
HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, false);
HIP_CHECK(hipGraphExecDestroy(graphExec));
HIP_CHECK(hipGraphDestroy(capGraph));
HIP_CHECK(hipStreamDestroy(stream));
}
+1 -3
Просмотреть файл
@@ -132,7 +132,6 @@ TEST_CASE("Unit_hipGraph_BasicCyclic4") {
HipTest::initArrays<int>(&X_d, &Y_d, nullptr, &X_h, &Y_h, nullptr, N, false);
constexpr size_t memSetVal = 9;
hipGraphNode_t kMemCpyH2D_X, memcpyD2D, memcpyD2H_RC, emptyNode1;
HIP_CHECK(hipStreamCreate(&stream));
@@ -192,7 +191,6 @@ TEST_CASE("Unit_hipGraph_BasicCyclic5") {
HipTest::initArrays<int>(&X_d, &Y_d, nullptr, &X_h, &Y_h, nullptr, N, false);
constexpr size_t memSetVal = 9;
hipGraphNode_t kMemCpyH2D_X, memcpyD2D, memcpyD2H_RC, emptyNode1, emptyNode2, emptyNode3;
HIP_CHECK(hipStreamCreate(&stream));
@@ -241,4 +239,4 @@ TEST_CASE("Unit_hipGraph_BasicCyclic5") {
HIP_CHECK(hipGraphExecDestroy(graphExec));
HIP_CHECK(hipGraphDestroy(graph));
HIP_CHECK(hipStreamDestroy(stream));
}
}
+1
Просмотреть файл
@@ -22,6 +22,7 @@ THE SOFTWARE.
#include <hip_test_defgroups.hh>
#include "stream_capture_common.hh" // NOLINT
#pragma clang diagnostic ignored "-Wunused-variable"
/**
* @addtogroup hipStreamBeginCapture hipStreamBeginCapture
* @{
+3 -1
Просмотреть файл
@@ -24,6 +24,8 @@ THE SOFTWARE.
#include <hip_test_common.hh>
#pragma clang diagnostic ignored "-Wunused-function"
struct BoxStruct {
int count;
BoxStruct() { INFO("Constructor called for Struct!\n"); }
@@ -58,4 +60,4 @@ void destroyFloatObj(void* ptr) {
delete ptr2;
}
} // anonymous namespace
} // anonymous namespace
+8 -10
Просмотреть файл
@@ -23,30 +23,28 @@ set(TEST_SRC
hipMemFaultStackAllocation.cc
hipLaunchBounds.cc
hipShflTests.cc
hipDynamicShared.cc
hipDynamicShared2.cc
hipEmptyKernel.cc
hipGridLaunch.cc
hipLanguageExtensions.cc
hipLaunchParm.cc
hipLaunchParmFunctor.cc
hipTestConstant.cc
hipTestGlobalVariable.cc
hipTestMemKernel.cc
launch_bounds.cc
inline_asm_vadd.cc
)
if(UNIX)
set(TEST_SRC ${TEST_SRC}
hipPrintfKernel.cc)
endif()
string(FIND "${OFFLOAD_ARCH_STR}" "gfx1030" RESULT)
if ("${RESULT}" EQUAL "-1")
set(AMD_TEST_SRC
inline_asm_vmac.cc)
endif()
if(HIP_PLATFORM MATCHES "amd")
set(TEST_SRC ${TEST_SRC} ${AMD_TEST_SRC})
endif()
# only for AMD
if(HIP_PLATFORM MATCHES "amd")
set(AMD_SRC
hipShflUpDownTest.cc
hipExtLaunchKernelGGL.cc
)
set(TEST_SRC ${TEST_SRC} ${AMD_SRC})
endif()
+164
Просмотреть файл
@@ -0,0 +1,164 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip_test_kernels.hh>
#include <hip_test_checkers.hh>
#include <hip_test_common.hh>
#include <hip_test_defgroups.hh>
#pragma clang diagnostic ignored "-Wunused-parameter"
unsigned threadsPerBlock = 256;
template <unsigned batch, typename T>
__device__ void sum(T* sdata, unsigned groupElements, unsigned tid) {
T tmp;
if (groupElements < batch)
return;
// sdata[tid] += sdata[tid - batch/2] does not work when block size is
// greater than wave size because one wave may complete before another
// wave.
if (tid >= batch/2 && tid < groupElements)
tmp = sdata[tid - batch/2];
__syncthreads();
if (tid >= batch/2 && tid < groupElements)
sdata[tid] += tmp;
__syncthreads();
}
template <typename T>
__global__ void testExternSharedKernel(const T* A_d, const T* B_d, T* C_d,
size_t numElements, size_t groupElements) {
// declare dynamic shared memory
extern __shared__ double sdata0[];
T* sdata = reinterpret_cast<T *>(sdata0);
size_t gid = (blockIdx.x * blockDim.x + threadIdx.x);
size_t tid = threadIdx.x;
// initialize dynamic shared memory
if (tid < groupElements) {
sdata[tid] = static_cast<T>(tid);
}
__syncthreads();
// prefix sum inside dynamic shared memory
sum<512>(sdata, groupElements, tid);
sum<256>(sdata, groupElements, tid);
sum<128>(sdata, groupElements, tid);
sum<64>(sdata, groupElements, tid);
sum<32>(sdata, groupElements, tid);
sum<16>(sdata, groupElements, tid);
sum<8>(sdata, groupElements, tid);
sum<4>(sdata, groupElements, tid);
sum<2>(sdata, groupElements, tid);
C_d[gid] = A_d[gid] + B_d[gid] + sdata[tid % groupElements];
}
template <typename T>
void testExternShared(size_t N, unsigned groupElements) {
size_t Nbytes = N * sizeof(T);
T *A_d, *B_d, *C_d;
T *A_h, *B_h, *C_h;
HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N, false);
unsigned blocks = N/threadsPerBlock;
assert(N == blocks * threadsPerBlock);
HIP_CHECK(hipMemcpy(A_d, A_h, Nbytes, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(B_d, B_h, Nbytes, hipMemcpyHostToDevice));
// calculate the amount of dynamic shared memory required
size_t groupMemBytes = groupElements * sizeof(double);
// launch kernel with dynamic shared memory
hipLaunchKernelGGL(HIP_KERNEL_NAME(testExternSharedKernel<T>), dim3(blocks),
dim3(threadsPerBlock), groupMemBytes, 0, A_d, B_d, C_d,
N, groupElements);
HIP_CHECK(hipDeviceSynchronize());
HIP_CHECK(hipMemcpy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
// verify
for (size_t i = 0; i < N; ++i) {
size_t tid = (i % min(threadsPerBlock, groupElements));
T sumFromSharedMemory = static_cast<T>(tid * (tid + 1) / 2);
T expected = A_h[i] + B_h[i] + sumFromSharedMemory;
REQUIRE(C_h[i] == expected);
}
HipTest::freeArrays(A_d, B_d, C_d, A_h, B_h, C_h, false);
}
/**
* @addtogroup hipLaunchKernelGGL hipLaunchKernelGGL
* @{
* @ingroup KernelTest
* `void hipLaunchKernelGGL(F kernel, const dim3& numBlocks, const dim3& dimBlocks,
std::uint32_t sharedMemBytes, hipStream_t stream, Args... args)` -
* Method to invocate kernel functions
*/
/**
* Test Description
* ------------------------
* - launch kernel with dynamic shared memory for float and double
* datatypes and verify the results.
* Test source
* ------------------------
* - catch/unit/kernel/hipDynamicShared.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.5
*/
TEST_CASE("Unit_hipDynamicShared") {
SECTION("test case with float for least size") {
testExternShared<float>(1024, 4);
testExternShared<float>(1024, 8);
testExternShared<float>(1024, 16);
testExternShared<float>(1024, 32);
testExternShared<float>(1024, 64);
}
SECTION("test case with float for max size") {
testExternShared<float>(65536, 4);
testExternShared<float>(65536, 8);
testExternShared<float>(65536, 16);
testExternShared<float>(65536, 32);
testExternShared<float>(65536, 64);
}
SECTION("test case with double for least size") {
testExternShared<double>(1024, 4);
testExternShared<double>(1024, 8);
testExternShared<double>(1024, 16);
testExternShared<double>(1024, 32);
testExternShared<double>(1024, 64);
}
SECTION("test case with double for max size") {
testExternShared<double>(65536, 4);
testExternShared<double>(65536, 8);
testExternShared<double>(65536, 16);
testExternShared<double>(65536, 32);
testExternShared<double>(65536, 64);
}
}
+89
Просмотреть файл
@@ -0,0 +1,89 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip_test_kernels.hh>
#include <hip_test_checkers.hh>
#include <hip_test_common.hh>
#include <hip_test_defgroups.hh>
#define LEN (16 * 1024)
#define SIZE (LEN * sizeof(float))
__global__ void vectorAdd(float* Ad, float* Bd) {
extern __shared__ float sBd[];
int tx = threadIdx.x;
for (int i = 0; i < LEN / 64; i++) {
sBd[tx + i * 64] = Ad[tx + i * 64] + 1.0f;
Bd[tx + i * 64] = sBd[tx + i * 64];
}
}
/**
* @addtogroup hipLaunchKernelGGL hipLaunchKernelGGL
* @{
* @ingroup KernelTest
* `void hipLaunchKernelGGL(F kernel, const dim3& numBlocks, const dim3& dimBlocks,
std::uint32_t sharedMemBytes, hipStream_t stream, Args... args)` -
* Method to invocate kernel functions
*/
/**
* Test Description
* ------------------------
* - Assign max dynamic shared memory to kernel function and
* verify the results.
* Test source
* ------------------------
* - catch/unit/kernel/hipDynamicShared2.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.5
*/
TEST_CASE("Unit_hipDynamicShared2") {
float *A, *B, *Ad, *Bd;
A = new float[LEN];
B = new float[LEN];
for (int i = 0; i < LEN; i++) {
A[i] = 1.0f;
B[i] = 1.0f;
}
HIP_CHECK(hipMalloc(&Ad, SIZE));
HIP_CHECK(hipMalloc(&Bd, SIZE));
HIP_CHECK(hipMemcpy(Ad, A, SIZE, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(Bd, B, SIZE, hipMemcpyHostToDevice));
hipError_t ret = hipFuncSetAttribute(
reinterpret_cast<const void*>(&vectorAdd),
hipFuncAttributeMaxDynamicSharedMemorySize, SIZE);
REQUIRE(ret == hipSuccess);
hipLaunchKernelGGL(vectorAdd, dim3(1, 1, 1), dim3(64, 1, 1), SIZE, 0, Ad, Bd);
HIP_CHECK(hipGetLastError());
HIP_CHECK(hipMemcpy(B, Bd, SIZE, hipMemcpyDeviceToHost));
for (int i = 0; i < LEN; i++) {
assert(B[i] > 1.0f && B[i] < 3.0f);
}
HIP_CHECK(hipFree(Ad));
HIP_CHECK(hipFree(Bd));
delete[] A;
delete[] B;
}
+54
Просмотреть файл
@@ -0,0 +1,54 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip_test_kernels.hh>
#include <hip_test_checkers.hh>
#include <hip_test_common.hh>
#include <hip_test_defgroups.hh>
#pragma clang diagnostic ignored "-Wunused-parameter"
__global__ void Empty(int param) {}
/**
* @addtogroup hipLaunchKernelGGL hipLaunchKernelGGL
* @{
* @ingroup KernelTest
* `void hipLaunchKernelGGL(F kernel, const dim3& numBlocks, const dim3& dimBlocks,
std::uint32_t sharedMemBytes, hipStream_t stream, Args... args)` -
* Method to invocate kernel functions
*/
/**
* Test Description
* ------------------------
* - pass empty Kernel function.
* Test source
* ------------------------
* - catch/unit/kernel/hipEmptyKernel.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.5
*/
TEST_CASE("Unit_hipEmptyKernel") {
hipLaunchKernelGGL(HIP_KERNEL_NAME(Empty), dim3(1), dim3(1), 0, 0, 0);
HIP_CHECK(hipDeviceSynchronize());
}
+133
Просмотреть файл
@@ -0,0 +1,133 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
// Test the Grid_Launch syntax.
#include <hip_test_kernels.hh>
#include <hip_test_checkers.hh>
#include <hip_test_common.hh>
#include <hip_test_defgroups.hh>
#include "hip/hip_ext.h"
static unsigned threadsPerBlock = 256;
static unsigned blocksPerCU = 6;
struct _t {
double _a, _b, _c, _d, _e, _f, _g, _h, _i, _j;
};
typedef struct _t _T;
__global__ void sKernel(_T s, double *a) {
*a = s._a + s._b + s._c + s._d + s._e + s._f + s._g + s._h + s._i + s._j;
}
__global__ void mKernel(char f, int16_t a, int b, double c,
int16_t d, int e, double* res) {
*res = a + b + c + d + e + f;
}
void testMixData() {
double m = 0;
double *d_m;
HIP_CHECK(hipMalloc(&d_m, sizeof(double)));
int a = 1, e = 10;
int16_t b = 2, d = 4;
double c = 3.0;
char ff = 10;
hipExtLaunchKernelGGL(mKernel, 1, 1, 0, 0, nullptr, nullptr, 0, ff,
b, a, c, d, e, d_m);
HIP_CHECK(hipMemcpy(&m, d_m, sizeof(double), hipMemcpyDeviceToHost));
REQUIRE(m == 30.0);
HIP_CHECK(hipFree(d_m));
}
void testStruct() {
double m = 0;
double *d_m;
HIP_CHECK(hipMalloc(&d_m, sizeof(double)));
_T s{1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
hipExtLaunchKernelGGL(sKernel, 1, 1, 0, 0, nullptr, nullptr, 0, s, d_m);
HIP_CHECK(hipMemcpy(&m, d_m, sizeof(double), hipMemcpyDeviceToHost));
REQUIRE(m == 55.0);
HIP_CHECK(hipFree(d_m));
}
void test(size_t N) {
size_t Nbytes = N * sizeof(int);
int *A_d, *B_d, *C_d;
int *A_h, *B_h, *C_h;
HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N);
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, N);
HIP_CHECK(hipMemcpy(A_d, A_h, Nbytes, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(B_d, B_h, Nbytes, hipMemcpyHostToDevice));
hipExtLaunchKernelGGL(HipTest::vectorADD, dim3(blocks),
dim3(threadsPerBlock), 0, 0, nullptr, nullptr, 0,
static_cast<const int*>(A_d),
static_cast<const int*>(B_d), C_d, N);
HIP_CHECK(hipMemcpy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
HIP_CHECK(hipDeviceSynchronize());
HipTest::checkVectorADD(A_h, B_h, C_h, N);
}
/**
* @addtogroup hipExtLaunchKernelGGL hipExtLaunchKernelGGL
* @{
* @ingroup KernelTest
* `void hipExtLaunchKernelGGL(F kernel, const dim3& numBlocks, const dim3& dimBlocks,
std::uint32_t sharedMemBytes, hipStream_t stream,
hipEvent_t startEvent, hipEvent_t stopEvent, std::uint32_t flags,
Args... args)` -
* Launches kernel with dimention parameters and shared memory on stream with templated kernel and arguments
*/
/**
* Test Description
* ------------------------
* - Test case to verify sample array with hipExtLaunchKernelGGL()
* and verify the results.
* - Test case to verify struct data with hipExtLaunchKernelGGL()
* and verify the results.
* - Test case to verify mix datatypes with hipExtLaunchKernelGGL()
* and verify the results.
* Test source
* ------------------------
* - catch/unit/kernel/hipExtLaunchKernelGGL.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.5
*/
TEST_CASE("Unit_hipExtLaunchKernelGGL") {
SECTION("test run") {
size_t N = 4 * 1024 * 1024;
test(N);
}
SECTION("testStruct run") {
testStruct();
}
SECTION("testMixData run") {
testMixData();
}
}
+117
Просмотреть файл
@@ -0,0 +1,117 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
// Test the Grid_Launch syntax.
#include <hip_test_kernels.hh>
#include <hip_test_checkers.hh>
#include <hip_test_common.hh>
#include <hip_test_defgroups.hh>
static unsigned threadsPerBlock = 256;
static unsigned blocksPerCU = 6;
// __device__ maps to __attribute__((hc))
__device__ int foo(int i) { return i + 1; }
template <typename T>
__global__ void vectorADD2(T* A_d, T* B_d, T* C_d, size_t N) {
size_t offset = (blockIdx.x * blockDim.x + threadIdx.x);
size_t stride = blockDim.x * gridDim.x;
for (size_t i = offset; i < N; i += stride) {
double foo = __hiloint2double(A_d[i], B_d[i]);
C_d[i] = __double2loint(foo) + __double2hiint(foo);
}
}
int test_gl2(size_t N) {
size_t Nbytes = N * sizeof(int);
int *A_d, *B_d, *C_d;
int *A_h, *B_h, *C_h;
HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N);
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, N);
// Full vadd in one large chunk, to get things started:
HIP_CHECK(hipMemcpy(A_d, A_h, Nbytes, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(B_d, B_h, Nbytes, hipMemcpyHostToDevice));
hipLaunchKernelGGL(vectorADD2, dim3(blocks), dim3(threadsPerBlock),
0, 0, A_d, B_d, C_d, N);
HIP_CHECK(hipMemcpy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
HIP_CHECK(hipDeviceSynchronize());
// verify
HipTest::checkVectorADD(A_h, B_h, C_h, N);
return 0;
}
#if __HIP__
int test_triple_chevron(size_t N) {
size_t Nbytes = N * sizeof(int);
int *A_d, *B_d, *C_d;
int *A_h, *B_h, *C_h;
HipTest::initArrays(&A_d, &B_d, &C_d, &A_h, &B_h, &C_h, N);
unsigned blocks = HipTest::setNumBlocks(blocksPerCU, threadsPerBlock, N);
// Full vadd in one large chunk, to get things started:
HIP_CHECK(hipMemcpy(A_d, A_h, Nbytes, hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(B_d, B_h, Nbytes, hipMemcpyHostToDevice));
vectorADD2<<<dim3(blocks), dim3(threadsPerBlock)>>>(A_d, B_d, C_d, N);
HIP_CHECK(hipMemcpy(C_h, C_d, Nbytes, hipMemcpyDeviceToHost));
HIP_CHECK(hipDeviceSynchronize());
// verify
HipTest::checkVectorADD(A_h, B_h, C_h, N);
return 0;
}
#endif
/**
* @addtogroup hipLaunchKernelGGL hipLaunchKernelGGL
* @{
* @ingroup KernelTest
* `void hipLaunchKernelGGL(F kernel, const dim3& numBlocks, const dim3& dimBlocks,
std::uint32_t sharedMemBytes, hipStream_t stream, Args... args)` -
* Method to invocate kernel functions
*/
/**
* Test Description
* ------------------------
* - Test case to verify the Grid_Launch syntax.
* Test source
* ------------------------
* - catch/unit/kernel/hipGridLaunch.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.5
*/
TEST_CASE("Unit_hipGridLaunch") {
size_t N = 4 * 1024 * 1024;
SECTION("Test test_gl2") {
test_gl2(N);
}
#if __HIP__
SECTION("Test triple_chevron") {
test_triple_chevron(N);
}
#endif
}
+106
Просмотреть файл
@@ -0,0 +1,106 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip_test_kernels.hh>
#include <hip_test_common.hh>
#include <hip_test_checkers.hh>
#include <hip_test_defgroups.hh>
#include <hip/math_functions.h>
#pragma clang diagnostic ignored "-Wunused-variable"
#pragma clang diagnostic ignored "-Wuninitialized"
// Simple tests for variable type qualifiers:
__device__ int deviceVar;
// TODO-HCC __constant__ not working yet.
__constant__ int constantVar1;
__constant__ __device__ int constantVar2;
// Test HOST space:
__host__ void foo() { printf("foo!\n"); }
__device__ __noinline__ int sum1_noinline(int a) { return a + 1; }
__device__ __forceinline__ int sum1_forceinline(int a) { return a + 1; }
__device__ __host__ float PlusOne(float x) { return x + 1.0; }
__global__ void MyKernel(const float* a, const float* b, float* c,
unsigned N) {
unsigned gid = threadIdx.x;
if (gid < N) {
c[gid] = a[gid] + PlusOne(b[gid]);
}
}
void callMyKernel() {
float *a, *b, *c;
const unsigned blockSize = 256;
unsigned N = blockSize;
hipLaunchKernelGGL(MyKernel, dim3(N / blockSize), dim3(blockSize),
0, 0, a, b, c, N);
}
template <typename T>
__global__ void vectorADD(T __restrict__* A_d, T* B_d, T* C_d, size_t N) {
#ifdef NOT_YET
int a = __shfl_up(x, 1);
#endif
float x = 1.0;
#ifdef NOT_YET
float fastZ = __sin(x);
#endif
__syncthreads();
size_t offset = (blockIdx.x * blockDim.x + threadIdx.x);
size_t stride = blockDim.x * gridDim.x;
for (size_t i = offset; i < N; i += stride) {
C_d[i] = A_d[i] + B_d[i];
}
}
/**
* @addtogroup hipLaunchKernelGGL hipLaunchKernelGGL
* @{
* @ingroup KernelTest
* `void hipLaunchKernelGGL(F kernel, const dim3& numBlocks, const dim3& dimBlocks,
std::uint32_t sharedMemBytes, hipStream_t stream, Args... args)` -
* Method to invocate kernel functions
*/
/**
* Test Description
* ------------------------
* - Collection of code to make sure that various features
* in the hip kernel language compile.
* Test source
* ------------------------
* - catch/unit/kernel/hipLanguageExtensions.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.5
*/
TEST_CASE("Unit_hipLanguageExtensions") {
REQUIRE(true);
}
Разница между файлами не показана из-за своего большого размера Загрузить разницу
+459
Просмотреть файл
@@ -0,0 +1,459 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip_test_kernels.hh>
#include <hip_test_checkers.hh>
#include <hip_test_common.hh>
#include <hip_test_defgroups.hh>
class HipFunctorTests {
public:
// Test that a class functor can be passed to hiplaunchparam
// and can be used in kernel
void TestForSimpleClassFunctor(void);
// Test that a templated class functor can be passed to hiplaunchparam
// and can be used in kernel
void TestForClassTemplateFunctor(void);
// Test that a class functor object ptr can be passed to hiplaunchparam
// and can be used in kernel
void TestForClassObjPtrFunctor(void);
// Test that a class object containing functor can be passed
// to hiplaunchparam and can be used in kernel
void TestForFunctorContainInClassObj(void);
// Test that a stuct functor can be passed to hiplaunchparam
// and can be used in kernel
void TestForSimpleStructFunctor(void);
// Test that a stuct functor object ptr can be passed to hiplaunchparam
// and can be used in kernel
void TestForStructObjPtrFunctor(void);
// Test that a templated struct functor can be passed to hiplaunchparam
// and can be used in kernel
void TestForStructTemplateFunctor(void);
// Test that a struct object containing functor can be
// passed to hiplaunchparam and can be used in kernel
void TestForFunctorContainInStructObj(void);
};
static const int BLOCK_DIM_SIZE = 1024;
static const int THREADS_PER_BLOCK = 1;
// class functor tests
// Simple doubler Functor
class DoublerFunctor{
public:
__device__ int operator()(int x) { return x * 2;}
};
// simple doubler functor passed to kernel
__global__ void DoublerFunctorKernel(
DoublerFunctor doubler_,
bool* deviceResult) {
int x = blockIdx.x * blockDim.x + threadIdx.x;
int result = doubler_(5);
deviceResult[x] = (result == 10);
}
void HipFunctorTests::TestForSimpleClassFunctor(void) {
DoublerFunctor doubler;
bool *deviceResults, *hostResults;
HIP_CHECK(hipMalloc(&deviceResults, BLOCK_DIM_SIZE*sizeof(bool)));
HIP_CHECK(hipHostMalloc(&hostResults, BLOCK_DIM_SIZE*sizeof(bool)));
for (int k = 0; k < BLOCK_DIM_SIZE; ++k) {
// initialize to false, will be set to
// true if the functor is called in device code
hostResults[k] = false;
}
HIP_CHECK(hipMemcpy(deviceResults, hostResults, BLOCK_DIM_SIZE*sizeof(bool),
hipMemcpyHostToDevice));
hipLaunchKernelGGL(DoublerFunctorKernel, dim3(BLOCK_DIM_SIZE),
dim3(THREADS_PER_BLOCK), 0, 0, doubler, deviceResults);
// Validation part of TestForSimpleClassFunctor
HIP_CHECK(hipMemcpy(hostResults, deviceResults, BLOCK_DIM_SIZE*sizeof(bool),
hipMemcpyDeviceToHost));
for (int k = 0; k < BLOCK_DIM_SIZE; ++k)
REQUIRE(hostResults[k] == true);
HIP_CHECK(hipHostFree(hostResults));
HIP_CHECK(hipFree(deviceResults));
}
// pointer functor passed to kernel
__global__ void PtrDoublerFunctorKernel(
DoublerFunctor *doubler_,
bool* deviceResult) {
int x = blockIdx.x * blockDim.x + threadIdx.x;
int result = (*doubler_)(5);
deviceResult[x] = (result == 10);
}
void HipFunctorTests::TestForClassObjPtrFunctor(void) {
DoublerFunctor* ptrdoubler = new DoublerFunctor[sizeof(int)];
bool *deviceResults, *hostResults;
HIP_CHECK(hipMalloc(&deviceResults, BLOCK_DIM_SIZE*sizeof(bool)));
HIP_CHECK(hipHostMalloc(&hostResults, BLOCK_DIM_SIZE*sizeof(bool)));
for (int k = 0; k < BLOCK_DIM_SIZE; ++k) {
// initialize to false, will be set to
// true if the functor is called in device code
hostResults[k] = false;
}
HIP_CHECK(hipMemcpy(deviceResults, hostResults, BLOCK_DIM_SIZE*sizeof(bool),
hipMemcpyHostToDevice));
hipLaunchKernelGGL(PtrDoublerFunctorKernel, dim3(BLOCK_DIM_SIZE),
dim3(THREADS_PER_BLOCK), 0, 0, ptrdoubler, deviceResults);
// Validation part of TestForClassObjPtrFunctor
HIP_CHECK(hipMemcpy(hostResults, deviceResults, BLOCK_DIM_SIZE*sizeof(bool),
hipMemcpyDeviceToHost));
for (int k = 0; k < BLOCK_DIM_SIZE; ++k)
REQUIRE(hostResults[k] == true);
HIP_CHECK(hipHostFree(hostResults));
HIP_CHECK(hipFree(deviceResults));
delete[] ptrdoubler;
}
class compare {
public:
template<typename T1, typename T2>
__device__ bool operator()(const T1& v1, const T2& v2) {
return v1 > v2;
}
};
// template functor passed to kernel
__global__ void TemplateFunctorKernel(
compare compare_,
bool* deviceResult) {
int x = blockIdx.x * blockDim.x + threadIdx.x;
deviceResult[x] = compare_(2.2, 2.1);
deviceResult[x] = compare_(2, 1);
deviceResult[x] = compare_('b', 'a');
}
void HipFunctorTests::TestForClassTemplateFunctor(void) {
compare comparefunctor;
bool *deviceResults, *hostResults;
HIP_CHECK(hipMalloc(&deviceResults, BLOCK_DIM_SIZE*sizeof(bool)));
HIP_CHECK(hipHostMalloc(&hostResults, BLOCK_DIM_SIZE*sizeof(bool)));
for (int k = 0; k < BLOCK_DIM_SIZE; ++k) {
// initialize to false, will be set to
// true if the functor is called in device code
hostResults[k] = false;
}
HIP_CHECK(hipMemcpy(deviceResults, hostResults, BLOCK_DIM_SIZE*sizeof(bool),
hipMemcpyHostToDevice));
hipLaunchKernelGGL(TemplateFunctorKernel, dim3(BLOCK_DIM_SIZE),
dim3(THREADS_PER_BLOCK), 0, 0, comparefunctor, deviceResults);
// Validation part of TestForClassTemplateFunctor
HIP_CHECK(hipMemcpy(hostResults, deviceResults, BLOCK_DIM_SIZE*sizeof(bool),
hipMemcpyDeviceToHost));
for (int k = 0; k < BLOCK_DIM_SIZE; ++k)
REQUIRE(hostResults[k] == true);
HIP_CHECK(hipHostFree(hostResults));
HIP_CHECK(hipFree(deviceResults));
}
// Doubler calculator
class DoublerCalculator {
public:
int a, result;
// fucntor contained in class object
DoublerFunctor doubler;
};
// doubler functor conatined in class obj passed to kernel
__global__ void DoublerCalculatorFunctorKernel(
DoublerCalculator doubler_,
bool* deviceResult) {
int x = blockIdx.x * blockDim.x + threadIdx.x;
int result = doubler_.doubler(doubler_.a);
deviceResult[x] = (doubler_.result == result);
}
void HipFunctorTests::TestForFunctorContainInClassObj(void) {
DoublerCalculator Doubler;
bool *deviceResults, *hostResults;
HIP_CHECK(hipMalloc(&deviceResults, BLOCK_DIM_SIZE*sizeof(bool)));
HIP_CHECK(hipHostMalloc(&hostResults, BLOCK_DIM_SIZE*sizeof(bool)));
for (int k = 0; k < BLOCK_DIM_SIZE; ++k) {
// initialize to false, will be set to
// true if the functor is called in device code
hostResults[k] = false;
}
Doubler.a = 5;
Doubler.result = 10;
// pass comparefunctor to hipLaunchParm
HIP_CHECK(hipMemcpy(deviceResults, hostResults, BLOCK_DIM_SIZE*sizeof(bool),
hipMemcpyHostToDevice));
hipLaunchKernelGGL(DoublerCalculatorFunctorKernel, dim3(BLOCK_DIM_SIZE),
dim3(THREADS_PER_BLOCK), 0, 0, Doubler, deviceResults);
// Validation part of TestForStructTemplateFunctor
HIP_CHECK(hipMemcpy(hostResults, deviceResults, BLOCK_DIM_SIZE*sizeof(bool),
hipMemcpyDeviceToHost));
for (int k = 0; k < BLOCK_DIM_SIZE; ++k)
REQUIRE(hostResults[k] == true);
HIP_CHECK(hipHostFree(hostResults));
HIP_CHECK(hipFree(deviceResults));
}
// Struct functor tests
// Simple doubler Functor
struct sDoublerFunctor {
public:
__device__ int operator()(int x) { return x * 2;}
};
// simple sturct doubler functor passed to kernel
__global__ void structDoublerFunctorKernel(
sDoublerFunctor doubler_,
bool* deviceResult) {
int x = blockIdx.x * blockDim.x + threadIdx.x;
int result = doubler_(5);
deviceResult[x] = (result == 10);
}
void HipFunctorTests::TestForSimpleStructFunctor(void) {
sDoublerFunctor doubler;
bool *deviceResults, *hostResults;
HIP_CHECK(hipMalloc(&deviceResults, BLOCK_DIM_SIZE*sizeof(bool)));
HIP_CHECK(hipHostMalloc(&hostResults, BLOCK_DIM_SIZE*sizeof(bool)));
for (int k = 0; k < BLOCK_DIM_SIZE; ++k) {
// initialize to false, will be set to
// true if the functor is called in device code
hostResults[k] = false;
}
HIP_CHECK(hipMemcpy(deviceResults, hostResults, BLOCK_DIM_SIZE*sizeof(bool),
hipMemcpyHostToDevice));
hipLaunchKernelGGL(structDoublerFunctorKernel, dim3(BLOCK_DIM_SIZE),
dim3(THREADS_PER_BLOCK), 0, 0, doubler, deviceResults);
// Validation part of TestForSimpleStructFunctor
HIP_CHECK(hipMemcpy(hostResults, deviceResults, BLOCK_DIM_SIZE*sizeof(bool),
hipMemcpyDeviceToHost));
for (int k = 0; k < BLOCK_DIM_SIZE; ++k)
REQUIRE(hostResults[k] == true);
HIP_CHECK(hipHostFree(hostResults));
HIP_CHECK(hipFree(deviceResults));
}
// ptr functor passed to kernel
__global__ void structPtrDoublerFunctorKernel(
sDoublerFunctor *doubler_,
bool* deviceResult) {
int x = blockIdx.x * blockDim.x + threadIdx.x;
int result = (*doubler_)(5);
deviceResult[x] = (result == 10);
}
void HipFunctorTests::TestForStructObjPtrFunctor(void) {
sDoublerFunctor* ptrdoubler = new sDoublerFunctor[sizeof(int)];
bool *deviceResults, *hostResults;
HIP_CHECK(hipMalloc(&deviceResults, BLOCK_DIM_SIZE*sizeof(bool)));
HIP_CHECK(hipHostMalloc(&hostResults, BLOCK_DIM_SIZE*sizeof(bool)));
for (int k = 0; k < BLOCK_DIM_SIZE; ++k) {
// initialize to false, will be set to
// true if the functor is called in device code
hostResults[k] = false;
}
HIP_CHECK(hipMemcpy(deviceResults, hostResults, BLOCK_DIM_SIZE*sizeof(bool),
hipMemcpyHostToDevice));
hipLaunchKernelGGL(structPtrDoublerFunctorKernel, dim3(BLOCK_DIM_SIZE),
dim3(THREADS_PER_BLOCK), 0, 0, ptrdoubler, deviceResults);
// Validation part of TestForStructObjPtrFunctor
HIP_CHECK(hipMemcpy(hostResults, deviceResults, BLOCK_DIM_SIZE*sizeof(bool),
hipMemcpyDeviceToHost));
for (int k = 0; k < BLOCK_DIM_SIZE; ++k)
REQUIRE(hostResults[k] == true);
HIP_CHECK(hipHostFree(hostResults));
HIP_CHECK(hipFree(deviceResults));
delete[] ptrdoubler;
}
struct sCompare {
public:
template< typename T1, typename T2 >
__device__ bool operator()(const T1& v1, const T2& v2) {
return v1 > v2;
}
};
// template functor passed to kernel
__global__ void structTemplateFunctorKernel(
sCompare compare_,
bool* deviceResult) {
int x = blockIdx.x * blockDim.x + threadIdx.x;
deviceResult[x] = compare_(2.2, 2.1);
deviceResult[x] = compare_(2, 1);
deviceResult[x] = compare_('b', 'a');
}
void HipFunctorTests::TestForStructTemplateFunctor(void) {
sCompare comparefunctor;
bool *deviceResults, *hostResults;
HIP_CHECK(hipMalloc(&deviceResults, BLOCK_DIM_SIZE*sizeof(bool)));
HIP_CHECK(hipHostMalloc(&hostResults, BLOCK_DIM_SIZE*sizeof(bool)));
for (int k = 0; k < BLOCK_DIM_SIZE; ++k) {
// initialize to false, will be set to
// true if the functor is called in device code
hostResults[k] = false;
}
HIP_CHECK(hipMemcpy(deviceResults, hostResults, BLOCK_DIM_SIZE*sizeof(bool),
hipMemcpyHostToDevice));
// pass comparefunctor to hipLaunchKernelGGL
hipLaunchKernelGGL(structTemplateFunctorKernel, dim3(BLOCK_DIM_SIZE),
dim3(THREADS_PER_BLOCK), 0, 0, comparefunctor, deviceResults);
// Validation part of TestForStructTemplateFunctor
HIP_CHECK(hipMemcpy(hostResults, deviceResults, BLOCK_DIM_SIZE*sizeof(bool),
hipMemcpyDeviceToHost));
for (int k = 0; k < BLOCK_DIM_SIZE; ++k)
REQUIRE(hostResults[k] == true);
HIP_CHECK(hipHostFree(hostResults));
HIP_CHECK(hipFree(deviceResults));
}
// Doubler calculator struct
struct sDoublerCalculator {
public:
int a, result;
// fucntor contained in class object
DoublerFunctor doubler;
};
// doubler functor contained in struct passed to kernel
__global__ void DoublerCalculatorFunctorKernel(
sDoublerCalculator doubler_,
bool* deviceResult) {
int x = blockIdx.x * blockDim.x + threadIdx.x;
int result = doubler_.doubler(doubler_.a);
deviceResult[x] = (doubler_.result == result);
}
void HipFunctorTests::TestForFunctorContainInStructObj(void) {
sDoublerCalculator Doubler;
bool *deviceResults, *hostResults;
HIP_CHECK(hipMalloc(&deviceResults, BLOCK_DIM_SIZE*sizeof(bool)));
HIP_CHECK(hipHostMalloc(&hostResults, BLOCK_DIM_SIZE*sizeof(bool)));
for (int k = 0; k < BLOCK_DIM_SIZE; ++k) {
// initialize to false, will be set to
// true if the functor is called in device code
hostResults[k] = false;
}
Doubler.a = 5;
Doubler.result = 10;
HIP_CHECK(hipMemcpy(deviceResults, hostResults, BLOCK_DIM_SIZE*sizeof(bool),
hipMemcpyHostToDevice));
// pass comparefunctor to hipLaunchKernelGGL
hipLaunchKernelGGL(DoublerCalculatorFunctorKernel, dim3(BLOCK_DIM_SIZE),
dim3(THREADS_PER_BLOCK), 0, 0, Doubler, deviceResults);
// Validation part of TestForStructTemplateFunctor
HIP_CHECK(hipMemcpy(hostResults, deviceResults, BLOCK_DIM_SIZE*sizeof(bool),
hipMemcpyDeviceToHost));
for (int k = 0; k < BLOCK_DIM_SIZE; ++k)
REQUIRE(hostResults[k] == true);
HIP_CHECK(hipHostFree(hostResults));
HIP_CHECK(hipFree(deviceResults));
}
/**
* @addtogroup hipLaunchKernelGGL hipLaunchKernelGGL
* @{
* @ingroup KernelTest
* `void hipLaunchKernelGGL(F kernel, const dim3& numBlocks, const dim3& dimBlocks,
std::uint32_t sharedMemBytes, hipStream_t stream, Args... args)` -
* Method to invocate kernel functions
*/
/**
* Test Description
* ------------------------
* - Test that a class functor can be passed to hiplaunchparam
* and can be used in kernel.
* - Test that a templated class functor can be passed to hiplaunchparam
* and can be used in kernel.
* - Test that a class functor object ptr can be passed to hiplaunchparam
* and can be used in kernel.
* - Test that a class object containing functor can be passed to hiplaunchparam
* and can be used in kernel
* - Test that a stuct functor can be passed to hiplaunchparam
* and can be used in kernel
* - Test that a stuct functor object ptr can be passed to hiplaunchparam
* and can be used in kernel
* - Test that a templated struct functor can be passed to hiplaunchparam
* and can be used in kernel
* - Test that a struct object containing functor can be passed to hiplaunchparam
* and can be used in kernel
* Test source
* ------------------------
* - catch/unit/kernel/hipLaunchParmFunctor.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.5
*/
TEST_CASE("Unit_hipLaunchParmFunctor") {
HipFunctorTests FunctorTests;
SECTION("test for simple class functor") {
FunctorTests.TestForSimpleClassFunctor();
}
SECTION("test for class objptr functor") {
FunctorTests.TestForClassObjPtrFunctor();
}
SECTION("test for class templete functor") {
FunctorTests.TestForClassTemplateFunctor();
}
SECTION("test for simple struct functor") {
FunctorTests.TestForSimpleStructFunctor();
}
SECTION("test for struct objptr functor") {
FunctorTests.TestForStructObjPtrFunctor();
}
SECTION("test for struct templete functor") {
FunctorTests.TestForStructTemplateFunctor();
}
SECTION("test for functor contain in classobj") {
FunctorTests.TestForFunctorContainInClassObj();
}
SECTION("test for functor contain in structobj") {
FunctorTests.TestForFunctorContainInStructObj();
}
}
-1
Просмотреть файл
@@ -150,7 +150,6 @@ static void runTest() {
// verify the results
REQUIRE(errors == compare(TransposeMatrix, cpuTransposeMatrix));
double eps = 1.0E-6;
// free the resources on device side
HIP_CHECK(hipFree(gpuMatrix));
HIP_CHECK(hipFree(gpuTransposeMatrix));
-136
Просмотреть файл
@@ -1,136 +0,0 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANNTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip_test_common.hh>
#include <hip_test_defgroups.hh>
#define NUM 1024
#define THREADS_PER_BLOCK_X 4
// Device (Kernel) function, it must be void
__global__ void vadd_asm(float* out, float* in) {
int i = blockDim.x * blockIdx.x + threadIdx.x;
#ifdef __HIP_PLATFORM_NVIDIA__
asm volatile("add.f32 %0,%1,%2;" : "=f"(out[i]) : "f"(in[i]), "f"(out[i]));
#endif
#ifdef __HIP_PLATFORM_AMD__
asm volatile("v_add_f32_e32 %0, %1, %2" : "=v"(out[i]) : "v"(in[i]),
"v"(out[i]));
#endif
}
// CPU implementation of Vector Result
void addCPUReference(float* output, float* input) {
for (unsigned int j = 0; j < NUM; j++) {
output[j] = input[j] + output[j];
}
}
/**
* @addtogroup hipLaunchKernelGGL
* @{
* @ingroup KernelTest
* `void hipLaunchKernelGGL(F kernel, const dim3& numBlocks, const dim3& dimBlocks,
std::uint32_t sharedMemBytes, hipStream_t stream, Args... args)` -
* Method to invocate kernel functions
*/
/**
* Test Description
* ------------------------
* - Test case to check inline asm vadd instruction via kernel call.
* Test source
* ------------------------
* - catch/unit/kernel/inline_asm_vadd.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.6
*/
TEST_CASE("Unit_kernel_inline_asm_vadd_Functional") {
float* VectorA;
float* ResultVector;
float* VectorB;
float* gpuVector;
float* gpuResultVector;
int i;
int errors;
VectorA = reinterpret_cast<float*>(malloc(NUM * sizeof(float)));
ResultVector = reinterpret_cast<float*>(malloc(NUM * sizeof(float)));
VectorB = reinterpret_cast<float*>(malloc(NUM * sizeof(float)));
// initialize the input data
for (i = 0; i < NUM; i++) {
VectorA[i] = static_cast<float>(i * 10.0f);
VectorB[i] = static_cast<float>(i * 30.0f);
}
// allocate the memory on the device side
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&gpuVector),
NUM * sizeof(float)));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&gpuResultVector),
NUM * sizeof(float)));
// Memory transfer from host to device
HIP_CHECK(hipMemcpy(gpuVector, VectorA, NUM * sizeof(float),
hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(gpuResultVector, VectorB, NUM * sizeof(float),
hipMemcpyHostToDevice));
// Lauching kernel from host
hipLaunchKernelGGL(vadd_asm, dim3(NUM / THREADS_PER_BLOCK_X),
dim3(THREADS_PER_BLOCK_X), 0, 0,
gpuResultVector, gpuVector);
// Memory transfer from device to host
HIP_CHECK(hipMemcpy(ResultVector, gpuResultVector, NUM * sizeof(float),
hipMemcpyDeviceToHost));
// CPU Result computation
addCPUReference(VectorB, VectorA);
// verify the results
errors = 0;
double eps = 1.0E-3;
for (i = 0; i < NUM; i++) {
if (std::abs(ResultVector[i] - VectorB[i]) > eps) {
errors++;
}
}
if (errors != 0) {
REQUIRE(false);
} else {
REQUIRE(true);
}
// free the resources on device side
HIP_CHECK(hipFree(gpuVector));
HIP_CHECK(hipFree(gpuResultVector));
HIP_CHECK(hipDeviceReset());
// free the resources on host side
free(VectorA);
free(ResultVector);
free(VectorB);
}
-128
Просмотреть файл
@@ -1,128 +0,0 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANNTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER INN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR INN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <hip_test_common.hh>
#include <hip_test_defgroups.hh>
#define NUM 1024
#define THREADS_PER_BLOCK_X 4
// Device (Kernel) function, it must be void
__global__ void vmac_asm(float* out, float* in, float a) {
int i = blockDim.x * blockIdx.x + threadIdx.x;
asm volatile("v_mac_f32_e32 %0, %2, %3" : "=v"(out[i]) :
"0"(out[i]), "v"(a), "v"(in[i]));
}
// CPU implementation of saxpy
void addCPUReference(float* output, float* input, float a) {
for (unsigned int j = 0; j < NUM; j++) {
output[j] = a * input[j] + output[j];
}
}
/**
* @addtogroup hipLaunchKernelGGL
* @{
* @ingroup KernelTest
* `void hipLaunchKernelGGL(F kernel, const dim3& numBlocks, const dim3& dimBlocks,
std::uint32_t sharedMemBytes, hipStream_t stream, Args... args)` -
* Method to invocate kernel functions
*/
/**
* Test Description
* ------------------------
* - Test case to check inline asm vmac instruction via kernel call.
* Test source
* ------------------------
* - catch/unit/kernel/inline_asm_vmac.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.6
*/
TEST_CASE("Unit_kernel_inline_asm_vmac_Functional") {
float* VectorA;
float* ResultVector;
float* VectorB;
float* gpuVector;
float* gpuResultVector;
const float a = 10.0f;
int i;
int errors;
VectorA = reinterpret_cast<float*>(malloc(NUM * sizeof(float)));
ResultVector = reinterpret_cast<float*>(malloc(NUM * sizeof(float)));
VectorB = reinterpret_cast<float*>(malloc(NUM * sizeof(float)));
// initialize the input data
for (i = 0; i < NUM; i++) {
VectorA[i] = static_cast<float>(i * 10.0f);
VectorB[i] = static_cast<float>(i * 30.0f);
}
// allocate the memory on the device side
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&gpuVector),
NUM * sizeof(float)));
HIP_CHECK(hipMalloc(reinterpret_cast<void**>(&gpuResultVector),
NUM * sizeof(float)));
// Memory transfer from host to device
HIP_CHECK(hipMemcpy(gpuVector, VectorA, NUM * sizeof(float),
hipMemcpyHostToDevice));
HIP_CHECK(hipMemcpy(gpuResultVector, VectorB, NUM * sizeof(float),
hipMemcpyHostToDevice));
// Lauching kernel from host
hipLaunchKernelGGL(vmac_asm, dim3(NUM / THREADS_PER_BLOCK_X),
dim3(THREADS_PER_BLOCK_X), 0, 0,
gpuResultVector, gpuVector, a);
// Memory transfer from device to host
HIP_CHECK(hipMemcpy(ResultVector, gpuResultVector, NUM * sizeof(float),
hipMemcpyDeviceToHost));
// CPU Result computation
addCPUReference(VectorB, VectorA, a);
// verify the results
errors = 0;
double eps = 1.0E-3;
for (i = 0; i < NUM; i++) {
if (std::abs(ResultVector[i] - VectorB[i]) > eps) {
errors++;
}
}
if (errors != 0) {
REQUIRE(false);
} else {
REQUIRE(true);
}
// free the resources on device side
HIP_CHECK(hipFree(gpuVector));
HIP_CHECK(hipFree(gpuResultVector));
HIP_CHECK(hipDeviceReset());
// free the resources on host side
free(VectorA);
free(ResultVector);
free(VectorB);
}
+6 -1
Просмотреть файл
@@ -1,4 +1,4 @@
# Copyright (c) 2022 Advanced Micro Devices, Inc. All Rights Reserved.
# Copyright (c) 2023 Advanced Micro Devices, Inc. All Rights Reserved.
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
@@ -88,6 +88,11 @@ hip_add_exe_to_target(NAME MemoryTest1
TEST_SRC ${TEST_SRC}
TEST_TARGET_NAME build_tests COMMON_SHARED_SRC ${COMMON_SHARED_SRC})
if(HIP_PLATFORM MATCHES "amd")
set_source_files_properties(hipHostRegister.cc PROPERTIES COMPILE_FLAGS -std=c++17)
add_executable(hipHostRegisterPerf EXCLUDE_FROM_ALL hipHostRegister_exe.cc)
endif()
set(TEST_SRC
hipMemcpyFromSymbol.cc
hipPtrGetAttribute.cc
+3 -6
Просмотреть файл
@@ -1,5 +1,5 @@
/*
Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -22,6 +22,8 @@ THE SOFTWARE.
#pragma once
#pragma clang diagnostic ignored "-Wunused-parameter"
#include <hip_test_common.hh>
constexpr size_t BlockSize = 16;
@@ -43,12 +45,7 @@ __global__ void readFromTexture(T* output, hipTextureObject_t texObj, size_t wid
} else {
const float v = y / (float)height;
if (textureGather) {
// tex2Dgather not supported on __gfx90a__
#if !defined(__gfx90a__)
output[y * width + x] = tex2Dgather<T>(texObj, u, v, ChannelToRead);
#else
#warning("tex2Dgather not supported on gfx90a");
#endif
} else {
output[y * width + x] = tex2D<T>(texObj, u, v);
}
+1 -1
Просмотреть файл
@@ -54,7 +54,7 @@ static void ArrayCreate_DiffSizes(int gpu) {
std::vector<std::pair<size_t, size_t>> runs {std::make_pair(NUM_W, NUM_H), std::make_pair(BIGNUM_W, BIGNUM_H)};
for (const auto& size : runs) {
std::array<HIP_ARRAY, ARRAY_LOOP> array;
size_t pavail, avail;
size_t pavail;
HIP_CHECK_THREAD(hipMemGetInfo(&pavail, nullptr));
HIP_ARRAY_DESCRIPTOR desc;
desc.NumChannels = 1;
+1 -1
Просмотреть файл
@@ -26,7 +26,7 @@ TEST_CASE("Unit_hipFreeAsync_negative") {
HIP_CHECK(hipSetDevice(0));
void* p = nullptr;
hipStream_t stream{nullptr};
hipStreamCreate(&stream);
HIP_CHECK(hipStreamCreate(&stream));
SECTION("dev_ptr is nullptr") { REQUIRE(hipFreeAsync(nullptr, stream) != hipSuccess); }
+68 -8
Просмотреть файл
@@ -1,5 +1,5 @@
/*
Copyright (c) 2021 Advanced Micro Devices, Inc. All rights reserved.
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -29,19 +29,30 @@ This testfile verifies the following scenarios of hipHostMalloc API
5. Allocating memory using hipHostMalloc with default flag
*/
#include<hip_test_checkers.hh>
#include<kernels.hh>
#include<hip_test_common.hh>
#include <hip_test_checkers.hh>
#include <kernels.hh>
#include <hip_test_common.hh>
#include <hip_test_context.hh>
#include <hip_test_helper.hh>
#define SYNC_EVENT 0
#define SYNC_STREAM 1
#define SYNC_DEVICE 2
#define ADDITIONAL_MEMORY_PERCENT 10
#define BLOCK_SIZE 512
#define VALUE 32
std::vector<std::string> syncMsg = {"event", "stream", "device"};
static constexpr int numElements{1024 * 16};
static constexpr size_t sizeBytes{numElements * sizeof(int)};
#if HT_AMD
static __global__ void kerTestMemAccess(char *buf) {
int myId = threadIdx.x + blockDim.x * blockIdx.x;
buf[myId] = VALUE;
}
#endif
void CheckHostPointer(int numElements, int* ptr, unsigned eventFlags,
int syncMethod, std::string msg) {
std::cerr << "test: CheckHostPointer "
@@ -134,8 +145,8 @@ TEST_CASE("Unit_hipHostMalloc_Basic") {
dim3 dimGrid(LEN / 512, 1, 1);
dim3 dimBlock(512, 1, 1);
HipTest::launchKernel<float>(HipTest::vectorADD<float>, dimGrid, dimBlock,
0, 0, static_cast<const float*>(A_d),
static_cast<const float*>(B_d), C_d, static_cast<size_t>(LEN));
0, 0, static_cast<const float*>(A_d),
static_cast<const float*>(B_d), C_d, static_cast<size_t>(LEN));
HIP_CHECK(hipMemcpy(C_h, C_d, LEN*sizeof(float),
hipMemcpyDeviceToHost));
HIP_CHECK(hipDeviceSynchronize());
@@ -229,16 +240,65 @@ TEST_CASE("Unit_hipHostMalloc_Default") {
CheckHostPointer(numElements, A, 0, SYNC_DEVICE, ptrType);
CheckHostPointer(numElements, A, 0, SYNC_STREAM, ptrType);
CheckHostPointer(numElements, A, 0, SYNC_EVENT, ptrType);
}
TEST_CASE("Unit_hipHostGetDevicePointer_NullCheck") {
int* d_a;
HIP_CHECK(hipHostMalloc(reinterpret_cast<void**>(&d_a), sizeof(int)));
auto res = hipHostGetDevicePointer(nullptr,d_a,0);
auto res = hipHostGetDevicePointer(nullptr, d_a, 0);
REQUIRE(res == hipErrorInvalidValue);
HIP_CHECK(hipHostFree(d_a));
}
/*
This testcase verifies the hipHostMalloc API by
1. Allocating more memory than total GPU memory. Should return hipSuccess.
2. Allocating more memory than the total GPU memory and accessing the memory
in a device function.
*/
TEST_CASE("Unit_hipHostMalloc_AllocateMoreThanAvailGPUMemory") {
char* A = nullptr;
size_t maxGpuMem = 0, availableMem = 0;
// Get available GPU memory and total GPU memory
HIP_CHECK(hipMemGetInfo(&availableMem, &maxGpuMem));
size_t allocsize = maxGpuMem +
((maxGpuMem*ADDITIONAL_MEMORY_PERCENT)/100);
// Get free host In bytes
size_t hostMemFree = HipTest::getMemoryAmount() * 1024 * 1024;
// Ensure that allocsize < hostMemFree
if (allocsize < hostMemFree) {
HIP_CHECK(hipHostMalloc(reinterpret_cast<void**>(&A), allocsize));
HIP_CHECK(hipHostFree(A));
} else {
WARN("Skipping test as CPU memory is less than GPU memory");
}
}
#if HT_AMD
TEST_CASE("Unit_hipHostMalloc_AllocateUseMoreThanAvailGPUMemory") {
char* A = nullptr;
size_t maxGpuMem = 0, availableMem = 0;
// Get available GPU memory and total GPU memory
HIP_CHECK(hipMemGetInfo(&availableMem, &maxGpuMem));
size_t allocsize = maxGpuMem +
((maxGpuMem*ADDITIONAL_MEMORY_PERCENT)/100);
// Get free host In bytes
size_t hostMemFree = HipTest::getMemoryAmount() * 1024 * 1024;
// Ensure that allocsize < hostMemFree
if (allocsize < hostMemFree) {
HIP_CHECK(hipHostMalloc(reinterpret_cast<void**>(&A), allocsize));
constexpr int sample_size = 1024;
// memset a sample size to 0
HIP_CHECK(hipMemset(A, 0, sample_size));
unsigned int grid_size = allocsize/BLOCK_SIZE;
// Check if the allocated memory can be accessed in kernels
kerTestMemAccess<<<grid_size, BLOCK_SIZE>>>(A);
HIP_CHECK(hipDeviceSynchronize());
HIP_CHECK(hipHostFree(A));
} else {
WARN("Skipping test as CPU memory is less than GPU memory");
}
}
#endif
+797 -34
Просмотреть файл
@@ -1,5 +1,5 @@
/*
Copyright (c) 2022 Advanced Micro Devices, Inc. All rights reserved.
Copyright (c) 2022-2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
@@ -20,20 +20,40 @@ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
/*
This testfile verifies the following scenarios of hipHostRegister API
1. Referencing the hipHostRegister variable from kernel and performing
memset on that variable.This is verified for different datatypes.
2. hipHostRegister and perform hipMemcpy on it.
*/
/**
* @addtogroup hipHostRegister hipHostRegister
* @{
* @ingroup MemoryTest
* `hipError_t hipHostRegister (void *hostPtr, size_t sizeBytes, unsigned int flags)` -
* register host memory so it can be accessed from the current device.
*/
#include "hip/hip_runtime_api.h"
#include <hip_test_common.hh>
#include <hip_test_helper.hh>
#include <hip_test_process.hh>
#include <hip_test_defgroups.hh>
#include <utils.hh>
#define OFFSET 128
#define INITIAL_VAL 1
#define EXPECTED_VAL 2
#define ITERATION 100
#define ADDITIONAL_MEMORY_PERCENT 10
static constexpr auto LEN{1024 * 1024};
static constexpr auto LARGE_CHUNK_LEN{100 * LEN};
static constexpr auto SMALL_CHUNK_LEN{10 * LEN};
#if HT_AMD
#define TEST_SKIP(arch, msg) \
if (std::string::npos == arch.find("xnack+")) {\
HipTest::HIP_SKIP_TEST(msg);\
return;\
}
#else
#define TEST_SKIP(arch, msg)
#endif
template <typename T> __global__ void Inc(T* Ad) {
int tx = threadIdx.x + blockIdx.x * blockDim.x;
@@ -41,7 +61,8 @@ template <typename T> __global__ void Inc(T* Ad) {
}
template <typename T>
void doMemCopy(size_t numElements, int offset, T* A, T* Bh, T* Bd, bool internalRegister) {
void doMemCopy(size_t numElements, int offset, T* A, T* Bh, T* Bd,
bool internalRegister) {
constexpr auto memsetval = 13.0f;
A = A + offset;
numElements -= offset;
@@ -71,18 +92,27 @@ void doMemCopy(size_t numElements, int offset, T* A, T* Bh, T* Bd, bool internal
}
}
/*
This testcase verifies the hipHostRegister API by
1. Allocating the memory using malloc
2. hipHostRegister that variable
3. Getting the corresponding device pointer of the registered varible
4. Launching kernel and access the device pointer variable
5. performing hipMemset on the device pointer variable
*/
TEMPLATE_TEST_CASE("Unit_hipHostRegister_ReferenceFromKernelandhipMemset", "", int, float, double) {
/**
* Test Description
* ------------------------
* - This testcase verifies the hipHostRegister API by
* 1. Allocating the memory using malloc
* 2. hipHostRegister that variable
* 3. Getting the corresponding device pointer of the registered varible
* 4. Launching kernel and access the device pointer variable
* 5. performing hipMemset on the device pointer variable
* Test source
* ------------------------
* - catch\unit\memory\hipHostRegister.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
TEMPLATE_TEST_CASE("Unit_hipHostRegister_ReferenceFromKernelandhipMemset", "", \
int, float, double) {
size_t sizeBytes{LEN * sizeof(TestType)};
TestType *A, **Ad;
int num_devices;
int num_devices = 0;
HIP_CHECK(hipGetDeviceCount(&num_devices));
Ad = new TestType*[num_devices];
A = reinterpret_cast<TestType*>(malloc(sizeBytes));
@@ -118,17 +148,722 @@ TEMPLATE_TEST_CASE("Unit_hipHostRegister_ReferenceFromKernelandhipMemset", "", i
delete[] Ad;
}
/*
This testcase verifies hipHostRegister API by
performing memcpy on the hipHostRegistered variable.
*/
/**
* Test Description
* ------------------------
* - This testcase verifies that the host pointer registered by hipHostRegister API
* is accessible from current device when xnack is on.
* Test source
* ------------------------
* - catch\unit\memory\hipHostRegister.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.6
*/
TEMPLATE_TEST_CASE("Unit_hipHostRegister_DirectReferenceFromKernel", "", \
int, float, double) {
auto flags = GENERATE(hipHostRegisterDefault, hipHostRegisterPortable,
hipHostRegisterMapped);
// Execute the test only if xnack is supported
hipDeviceProp_t prop;
HIP_CHECK(hipGetDeviceProperties(&prop, 0));
std::string arch = prop.gcnArchName;
TEST_SKIP(arch, "Xnack+ is not supported. Skipping the test ...")
size_t sizeBytes{LEN * sizeof(TestType)};
TestType *A;
A = reinterpret_cast<TestType*>(malloc(sizeBytes));
REQUIRE(A != nullptr);
// Initialize buffer with data
TestType val = static_cast<TestType>(1);
for (int i = 0; i < LEN; i++) {
A[i] = val;
}
HIP_CHECK(hipHostRegister(A, sizeBytes, flags));
// Reference the registered device pointer A from inside the kernel:
hipLaunchKernelGGL(Inc, dim3(LEN / 32), dim3(32), 0, 0, A);
HIP_CHECK(hipGetLastError());
HIP_CHECK(hipDeviceSynchronize());
for (int i = 0; i < LEN; i++) {
REQUIRE(A[i] == (val + static_cast<TestType>(1)));
}
HIP_CHECK(hipHostUnregister(A));
free(A);
}
/**
* Test Description
* ------------------------
* - This testcase verifies that the host pointer registered by hipHostRegister API
is usable from multiple device when xnack is on.
* Test source
* ------------------------
* - catch\unit\memory\hipHostRegister.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.6
*/
TEMPLATE_TEST_CASE("Unit_hipHostRegister_DirectReferenceMultGpu", "", \
int, float, double) {
// 1 refers to doing hipHostRegister once for all devices
// 0 refers to doing hipHostRegister for each device
auto register_once = GENERATE(0, 1);
hipDeviceProp_t prop;
int numDevices = HipTest::getDeviceCount();
size_t sizeBytes{LEN * sizeof(TestType)};
TestType *A;
A = reinterpret_cast<TestType*>(malloc(sizeBytes));
REQUIRE(A != nullptr);
// Register host memory only once for all device
if (register_once == 1) {
HIP_CHECK(hipHostRegister(A, sizeBytes, 0));
}
// Reference the registered device pointer A from inside all devices:
for (int dev = 0; dev < numDevices; dev++) {
// Initialize buffer with data
TestType val = static_cast<TestType>(1);
for (int i = 0; i < LEN; i++) {
A[i] = val;
}
HIP_CHECK(hipSetDevice(dev));
HIP_CHECK(hipGetDeviceProperties(&prop, dev));
std::string arch = prop.gcnArchName;
TEST_SKIP(arch, "Xnack+ is not supported. Skipping the test ...")
// Register host memory for each device
if (register_once == 0) {
HIP_CHECK(hipHostRegister(A, sizeBytes, 0));
}
hipLaunchKernelGGL(Inc, dim3(LEN / 32), dim3(32), 0, 0, A);
HIP_CHECK(hipGetLastError());
HIP_CHECK(hipDeviceSynchronize());
for (int i = 0; i < LEN; i++) {
REQUIRE(A[i] == (val + static_cast<TestType>(1)));
}
if (register_once == 0) {
HIP_CHECK(hipHostUnregister(A));
}
}
if (register_once == 1) {
HIP_CHECK(hipHostUnregister(A));
}
free(A);
}
/**
* Test Description
* ------------------------
* - This testcase verifies functionality when same host pointer is repeatedly
* registered and unregistered.
* Test source
* ------------------------
* - catch\unit\memory\hipHostRegister.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.6
*/
TEST_CASE("Unit_hipHostRegister_SameChunkRepeat") {
// Execute the test only if xnack is supported
hipDeviceProp_t prop;
HIP_CHECK(hipGetDeviceProperties(&prop, 0));
std::string arch = prop.gcnArchName;
TEST_SKIP(arch, "Xnack+ is not supported. Skipping the test ...")
size_t sizeBytes{LEN * sizeof(uint8_t)};
uint8_t *A;
A = reinterpret_cast<uint8_t*>(malloc(sizeBytes));
REQUIRE(A != nullptr);
for (int iter = 0; iter < ITERATION; iter++) {
// Initialize buffer with data
memset(A, INITIAL_VAL, sizeBytes);
HIP_CHECK(hipHostRegister(A, sizeBytes, 0));
// Reference the registered device pointer A from inside the kernel:
hipLaunchKernelGGL(Inc, dim3(LEN / 32), dim3(32), 0, 0, A);
HIP_CHECK(hipGetLastError());
HIP_CHECK(hipDeviceSynchronize());
for (int i = 0; i < LEN; i++) {
REQUIRE(A[i] == EXPECTED_VAL);
}
HIP_CHECK(hipHostUnregister(A));
}
free(A);
}
/**
* Test Description
* ------------------------
* - Allocate a large chunk of host memory. Divide the memory into smaller chunks.
* Register each smaller chunk in one attempt. Access all the chunks in Kernel. Verify
* results.
* Test source
* ------------------------
* - catch\unit\memory\hipHostRegister.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.6
*/
TEST_CASE("Unit_hipHostRegister_Chunks_SingleAttempt") {
// Execute the test only if xnack is supported
hipDeviceProp_t prop;
HIP_CHECK(hipGetDeviceProperties(&prop, 0));
std::string arch = prop.gcnArchName;
TEST_SKIP(arch, "Xnack+ is not supported. Skipping the test ...")
size_t sizeBytes{LARGE_CHUNK_LEN * sizeof(uint8_t)};
size_t sizeBytesChunk{SMALL_CHUNK_LEN * sizeof(uint8_t)};
uint8_t *A;
A = reinterpret_cast<uint8_t*>(malloc(sizeBytes));
REQUIRE(A != nullptr);
// Initialize buffer with data
memset(A, INITIAL_VAL, sizeBytes);
uint8_t *arrPtr[LARGE_CHUNK_LEN / SMALL_CHUNK_LEN];
for (int cnt = 0; cnt < (LARGE_CHUNK_LEN / SMALL_CHUNK_LEN); cnt++) {
arrPtr[cnt] = A + (cnt*sizeBytesChunk);
HIP_CHECK(hipHostRegister(arrPtr[cnt], sizeBytesChunk, 0));
}
// Reference each registered chunk inside the kernel:
for (int cnt = 0; cnt < (LARGE_CHUNK_LEN / SMALL_CHUNK_LEN); cnt++) {
uint8_t *ptrA = arrPtr[cnt];
hipLaunchKernelGGL(Inc, dim3(SMALL_CHUNK_LEN / 32), dim3(32), 0, 0, ptrA);
HIP_CHECK(hipGetLastError());
HIP_CHECK(hipDeviceSynchronize());
for (int i = 0; i < SMALL_CHUNK_LEN; i++) {
REQUIRE(ptrA[i] == EXPECTED_VAL);
}
}
for (int cnt = 0; cnt < (LARGE_CHUNK_LEN / SMALL_CHUNK_LEN); cnt++) {
HIP_CHECK(hipHostUnregister(arrPtr[cnt]));
}
free(A);
}
/**
* Test Description
* ------------------------
* - Allocate a large chunk of host memory. Divide the memory into smaller chunks.
* Register each smaller chunk, access the chunk in Kernel and unregister the chunk.
* Verify results. Perform this series of operation in a round robin manner for
* all chunks.
* Test source
* ------------------------
* - catch\unit\memory\hipHostRegister.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.6
*/
TEST_CASE("Unit_hipHostRegister_Chunks_RoundRobin") {
// Execute the test only if xnack is supported
hipDeviceProp_t prop;
HIP_CHECK(hipGetDeviceProperties(&prop, 0));
std::string arch = prop.gcnArchName;
TEST_SKIP(arch, "Xnack+ is not supported. Skipping the test ...")
size_t sizeBytes{LARGE_CHUNK_LEN * sizeof(uint8_t)};
size_t sizeBytesChunk{SMALL_CHUNK_LEN * sizeof(uint8_t)};
uint8_t *A;
A = reinterpret_cast<uint8_t*>(malloc(sizeBytes));
REQUIRE(A != nullptr);
// Initialize buffer with data
memset(A, INITIAL_VAL, sizeBytes);
for (int cnt = 0; cnt < (LARGE_CHUNK_LEN / SMALL_CHUNK_LEN); cnt++) {
uint8_t *ptrA = A + (cnt*sizeBytesChunk);
HIP_CHECK(hipHostRegister(ptrA, sizeBytesChunk, 0));
hipLaunchKernelGGL(Inc, dim3(SMALL_CHUNK_LEN / 32), dim3(32), 0, 0, ptrA);
HIP_CHECK(hipGetLastError());
HIP_CHECK(hipDeviceSynchronize());
for (int i = 0; i < SMALL_CHUNK_LEN; i++) {
REQUIRE(ptrA[i] == EXPECTED_VAL);
}
HIP_CHECK(hipHostUnregister(ptrA));
}
free(A);
}
/**
* Test Description
* ------------------------
* - This testcase verifies that the host pointer registered by hipHostRegister API
* can be memset using hipMemset.
* Test source
* ------------------------
* - catch\unit\memory\hipHostRegister.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.6
*/
TEST_CASE("Unit_hipHostRegister_Perform_hipMemset") {
// Execute the test only if xnack is supported
hipDeviceProp_t prop;
HIP_CHECK(hipGetDeviceProperties(&prop, 0));
std::string arch = prop.gcnArchName;
TEST_SKIP(arch, "Xnack+ is not supported. Skipping the test ...")
size_t sizeBytes{LEN * sizeof(uint8_t)};
uint8_t *A;
A = reinterpret_cast<uint8_t*>(malloc(sizeBytes));
REQUIRE(A != nullptr);
// Register the host pointer
HIP_CHECK(hipHostRegister(A, sizeBytes, 0));
// Memset the registered pointer
HIP_CHECK(hipMemset(A, INITIAL_VAL, sizeBytes));
// Reference the registered device pointer A from inside the kernel:
hipLaunchKernelGGL(Inc, dim3(LEN / 32), dim3(32), 0, 0, A);
HIP_CHECK(hipGetLastError());
HIP_CHECK(hipDeviceSynchronize());
for (int i = 0; i < LEN; i++) {
REQUIRE(A[i] == EXPECTED_VAL);
}
HIP_CHECK(hipHostUnregister(A));
free(A);
}
/**
* Test Description
* ------------------------
* - This testcase verifies that the host pointer registered by hipHostRegister API
* can be used with hipMemcpy.
* Test source
* ------------------------
* - catch\unit\memory\hipHostRegister.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.6
*/
TEST_CASE("Unit_hipHostRegister_Perform_hipMemcpy") {
// Execute the test only if xnack is supported
hipDeviceProp_t prop;
HIP_CHECK(hipGetDeviceProperties(&prop, 0));
std::string arch = prop.gcnArchName;
TEST_SKIP(arch, "Xnack+ is not supported. Skipping the test ...")
size_t sizeBytes{LEN * sizeof(uint8_t)};
uint8_t *A, *B;
A = reinterpret_cast<uint8_t*>(malloc(sizeBytes));
REQUIRE(A != nullptr);
B = reinterpret_cast<uint8_t*>(malloc(sizeBytes));
REQUIRE(B != nullptr);
memset(B, INITIAL_VAL, sizeBytes);
// Register the host pointer
HIP_CHECK(hipHostRegister(A, sizeBytes, 0));
// Memcpy from B to A
HIP_CHECK(hipMemcpy(A, B, sizeBytes, hipMemcpyDefault));
// Reference the registered device pointer A from inside the kernel:
hipLaunchKernelGGL(Inc, dim3(LEN / 32), dim3(32), 0, 0, A);
HIP_CHECK(hipGetLastError());
HIP_CHECK(hipDeviceSynchronize());
// Verify if we can Memcpy from A to B
HIP_CHECK(hipMemcpy(B, A, sizeBytes, hipMemcpyDefault));
for (int i = 0; i < LEN; i++) {
REQUIRE(B[i] == EXPECTED_VAL);
}
HIP_CHECK(hipHostUnregister(A));
free(A);
free(B);
}
/**
* Test Description
* ------------------------
* - Oversubscription: This testcase allocates host memory of size > total
* GPU memory. Register the memory and try accessing it from kernel. Verify
* the behaviour.
* Test source
* ------------------------
* - catch\unit\memory\hipHostRegister.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.6
*/
TEST_CASE("Unit_hipHostRegister_Oversubscription") {
// Execute the test only if xnack is supported
hipDeviceProp_t prop;
HIP_CHECK(hipGetDeviceProperties(&prop, 0));
std::string arch = prop.gcnArchName;
TEST_SKIP(arch, "Xnack+ is not supported. Skipping the test ...")
size_t maxGpuMem = 0, availableMem = 0;
// Get available GPU memory and total GPU memory
HIP_CHECK(hipMemGetInfo(&availableMem, &maxGpuMem));
size_t allocsize = maxGpuMem +
((maxGpuMem*ADDITIONAL_MEMORY_PERCENT)/100);
// Get free host In bytes
size_t hostMemFree = HipTest::getMemoryAmount() * 1024 * 1024;
// Ensure that allocsize < hostMemFree
if (allocsize >= hostMemFree) {
HipTest::HIP_SKIP_TEST("Available Host Memory is not sufficient ...");
return;
}
uint8_t* A = reinterpret_cast<uint8_t*>(malloc(allocsize));
REQUIRE(A != nullptr);
size_t used_size = LEN;
// Inititalize only the first used_size bytes chunk
memset(A, INITIAL_VAL, used_size);
// Inititalize only the last used_size bytes chunk
memset((A + allocsize - used_size), INITIAL_VAL, used_size);
// Register the entire host memory chunk
HIP_CHECK(hipHostRegister(A, allocsize, 0));
// Reference only the first used_size bytes
hipLaunchKernelGGL(Inc, dim3(used_size / 32), dim3(32), 0, 0, A);
HIP_CHECK(hipGetLastError());
HIP_CHECK(hipDeviceSynchronize());
for (int i = 0; i < used_size; i++) {
REQUIRE(A[i] == EXPECTED_VAL);
}
// Reference only the last used_size bytes chunk
uint8_t* B = (A + allocsize - used_size);
hipLaunchKernelGGL(Inc, dim3(used_size / 32), dim3(32), 0, 0, B);
HIP_CHECK(hipGetLastError());
HIP_CHECK(hipDeviceSynchronize());
for (int i = 0; i < used_size; i++) {
REQUIRE(B[i] == EXPECTED_VAL);
}
HIP_CHECK(hipHostUnregister(A));
free(A);
}
/**
* Test Description
* ------------------------
* - This testcase verifies that the host pointer registered by hipHostRegister API
* can be used with Async APIs (hipMemsetAsync, hipMemcpyAsync and kernel) on a user
* defined stream.
* Test source
* ------------------------
* - catch\unit\memory\hipHostRegister.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.6
*/
TEST_CASE("Unit_hipHostRegister_AsyncApis") {
// Execute the test only if xnack is supported
hipDeviceProp_t prop;
HIP_CHECK(hipGetDeviceProperties(&prop, 0));
std::string arch = prop.gcnArchName;
bool useRegPtrInDev = false;
#if HT_AMD
if (std::string::npos == arch.find("xnack+")) {
useRegPtrInDev = false;
} else {
useRegPtrInDev = true;
}
#else
useRegPtrInDev = GENERATE(true, false);
#endif
size_t sizeBytes{LEN * sizeof(uint32_t)};
uint32_t *A, *B, *dPtr;
A = reinterpret_cast<uint32_t*>(malloc(sizeBytes));
REQUIRE(A != nullptr);
B = reinterpret_cast<uint32_t*>(malloc(sizeBytes));
REQUIRE(B != nullptr);
for (int i = 0; i < LEN; i++) {
B[i] = i;
}
// Register the host pointer
HIP_CHECK(hipHostRegister(A, sizeBytes, 0));
if (useRegPtrInDev) {
dPtr = A;
} else {
HIP_CHECK(hipHostGetDevicePointer(reinterpret_cast<void**>(&dPtr), A, 0));
}
hipStream_t strm{nullptr};
HIP_CHECK(hipStreamCreate(&strm));
// Memcpy from B to A
HIP_CHECK(hipMemcpyAsync(dPtr, B, sizeBytes, hipMemcpyHostToDevice, strm));
// Reference the registered device pointer A from inside the kernel:
hipLaunchKernelGGL(Inc, dim3(LEN / 32), dim3(32), 0, strm, dPtr);
HIP_CHECK(hipMemcpyAsync(B, dPtr, sizeBytes, hipMemcpyDeviceToHost, strm));
HIP_CHECK(hipStreamSynchronize(strm));
for (int i = 0; i < LEN; i++) {
REQUIRE(B[i] == (i + 1));
}
HIP_CHECK(hipStreamDestroy(strm));
HIP_CHECK(hipHostUnregister(A));
free(A);
free(B);
}
/**
* Test Description
* ------------------------
* - This testcase verifies the behaviour of host registered memory when
* used with hipGraph.
* Test source
* ------------------------
* - catch\unit\memory\hipHostRegister.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.6
*/
TEST_CASE("Unit_hipHostRegister_Graphs") {
// Execute the test only if xnack is supported
hipDeviceProp_t prop;
HIP_CHECK(hipGetDeviceProperties(&prop, 0));
std::string arch = prop.gcnArchName;
bool useRegPtrInDev = false;
#if HT_AMD
if (std::string::npos == arch.find("xnack+")) {
useRegPtrInDev = false;
} else {
useRegPtrInDev = true;
}
#else
useRegPtrInDev = GENERATE(true, false);
#endif
size_t sizeBytes{LEN * sizeof(uint32_t)};
uint32_t *A, *B, *dPtr;
A = reinterpret_cast<uint32_t*>(malloc(sizeBytes));
REQUIRE(A != nullptr);
B = reinterpret_cast<uint32_t*>(malloc(sizeBytes));
REQUIRE(B != nullptr);
for (int i = 0; i < LEN; i++) {
B[i] = i;
}
// Register the host pointer
HIP_CHECK(hipHostRegister(A, sizeBytes, 0));
if (useRegPtrInDev) {
dPtr = A;
} else {
HIP_CHECK(hipHostGetDevicePointer(reinterpret_cast<void**>(&dPtr), A, 0));
}
// Use dPtr in graphs
hipStream_t streamForGraph;
HIP_CHECK(hipStreamCreate(&streamForGraph));
hipGraph_t graph;
HIP_CHECK(hipGraphCreate(&graph, 0));
hipGraphNode_t memcpyH2D, memcpyD2H;
hipGraphNode_t kernel_vecInc;
void* kernelArgs1[] = {&dPtr};
hipKernelNodeParams kernelNodeParams{};
kernelNodeParams.func = reinterpret_cast<void *>(Inc<uint32_t>);
kernelNodeParams.gridDim = dim3(LEN / 32);
kernelNodeParams.blockDim = dim3(32);
kernelNodeParams.sharedMemBytes = 0;
kernelNodeParams.kernelParams = reinterpret_cast<void**>(kernelArgs1);
kernelNodeParams.extra = nullptr;
HIP_CHECK(hipGraphAddKernelNode(&kernel_vecInc, graph, nullptr, 0,
&kernelNodeParams));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyH2D, graph, nullptr, 0, dPtr, B,
sizeBytes, hipMemcpyHostToDevice));
HIP_CHECK(hipGraphAddMemcpyNode1D(&memcpyD2H, graph, nullptr, 0, B, dPtr,
sizeBytes, hipMemcpyDeviceToHost));
// Create dependencies
HIP_CHECK(hipGraphAddDependencies(graph, &memcpyH2D, &kernel_vecInc, 1));
HIP_CHECK(hipGraphAddDependencies(graph, &kernel_vecInc, &memcpyD2H, 1));
// Instantiate and execute Graph
hipGraphExec_t graphExec;
HIP_CHECK(hipGraphInstantiate(&graphExec, graph, nullptr, nullptr, 0));
HIP_CHECK(hipGraphLaunch(graphExec, streamForGraph));
HIP_CHECK(hipStreamSynchronize(streamForGraph));
// Verify Result
for (int i = 0; i < LEN; i++) {
REQUIRE(B[i] == (i + 1));
}
HIP_CHECK(hipGraphExecDestroy(graphExec));
HIP_CHECK(hipGraphDestroy(graph));
HIP_CHECK(hipStreamDestroy(streamForGraph));
HIP_CHECK(hipHostUnregister(A));
free(A);
free(B);
}
#if HT_AMD
/**
* Test Description
* ------------------------
* - This testcase measures performance when same memory chunk is repeatedly
* registered and unregistered.
* Test source
* ------------------------
* - catch\unit\memory\hipHostRegister.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.6
*/
TEST_CASE("Unit_hipHostRegister_RegUnreg_Perf_SameChunk") {
// Execute the test only if xnack is supported
hipDeviceProp_t prop;
hipDevice_t device;
HIP_CHECK(hipDeviceGet(&device, 0));
HIP_CHECK(hipGetDeviceProperties(&prop, device));
std::string arch = prop.gcnArchName;
if (std::string::npos == arch.find("xnack+")) {
HipTest::HIP_SKIP_TEST("Xnack+ is not supported. Skipping the test ...");
return;
}
hip::SpawnProc proc("hipHostRegisterPerf", true);
REQUIRE(proc.run("svm_enable 1") == 0);
float perf_svm_enable = std::stof(proc.getOutput());
INFO("perf_svm_enable: " << perf_svm_enable);
REQUIRE(proc.run("svm_disable 1") == 0);
float perf_svm_disable = std::stof(proc.getOutput());
INFO("perf_svm_disable: " << perf_svm_disable);
REQUIRE(perf_svm_enable <= perf_svm_disable);
}
/**
* Test Description
* ------------------------
* - This testcase measures performance when different memory chunks
* are repeatedly registered and unregistered.
* Test source
* ------------------------
* - catch\unit\memory\hipHostRegister.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.6
*/
TEST_CASE("Unit_hipHostRegister_RegUnreg_Perf_DiffChunk") {
// Execute the test only if xnack is supported
hipDeviceProp_t prop;
hipDevice_t device;
HIP_CHECK(hipDeviceGet(&device, 0));
HIP_CHECK(hipGetDeviceProperties(&prop, device));
std::string arch = prop.gcnArchName;
if (std::string::npos == arch.find("xnack+")) {
HipTest::HIP_SKIP_TEST("Xnack+ is not supported. Skipping the test ...");
return;
}
hip::SpawnProc proc("hipHostRegisterPerf", true);
REQUIRE(proc.run("svm_enable 0") == 0);
float perf_svm_enable = std::stof(proc.getOutput());
INFO("perf_svm_enable: " << perf_svm_enable);
REQUIRE(proc.run("svm_disable 0") == 0);
float perf_svm_disable = std::stof(proc.getOutput());
INFO("perf_svm_disable: " << perf_svm_disable);
REQUIRE(perf_svm_enable <= perf_svm_disable);
}
/**
* Test Description
* ------------------------
* - This testcase measures performance when same memory chunk is repeatedly
* registered and unregistered on multiple GPUs.
* Test source
* ------------------------
* - catch\unit\memory\hipHostRegister.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.6
*/
TEST_CASE("Unit_hipHostRegister_RegUnreg_Perf_SameChunk_MGPU") {
// Execute the test only if xnack is supported
hipDeviceProp_t prop;
hipDevice_t device;
HIP_CHECK(hipDeviceGet(&device, 0));
HIP_CHECK(hipGetDeviceProperties(&prop, device));
std::string arch = prop.gcnArchName;
if (std::string::npos == arch.find("xnack+")) {
HipTest::HIP_SKIP_TEST("Xnack+ is not supported. Skipping the test ...");
return;
}
int dev_count = HipTest::getDeviceCount();
if (dev_count < 2) {
HipTest::HIP_SKIP_TEST("Only 1 GPU available. Skipping this test ...");
return;
}
hip::SpawnProc proc("hipHostRegisterPerf", true);
REQUIRE(proc.run("svm_enable 2") == 0);
float perf_svm_enable = std::stof(proc.getOutput());
INFO("perf_svm_enable: " << perf_svm_enable);
REQUIRE(proc.run("svm_disable 2") == 0);
float perf_svm_disable = std::stof(proc.getOutput());
INFO("perf_svm_disable: " << perf_svm_disable);
REQUIRE(perf_svm_enable <= perf_svm_disable);
}
/**
* Test Description
* ------------------------
* - This testcase verifies whether hipMemAdvise can be used with
* host memory registered with hipHostRegister.
* registered and unregistered.
* Test source
* ------------------------
* - catch\unit\memory\hipHostRegister.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.6
*/
TEST_CASE("Unit_hipHostRegister_MemAdvise_SetGet") {
// Execute the test only if xnack is supported
hipDeviceProp_t prop;
HIP_CHECK(hipGetDeviceProperties(&prop, 0));
std::string arch = prop.gcnArchName;
if ((std::string::npos == arch.find("xnack+")) ||
(prop.concurrentManagedAccess == 0)) {
const char *msg = "Xnack/ConcurrentAccess not supported. Skipping test";
HipTest::HIP_SKIP_TEST(msg);
return;
}
int numDevices = HipTest::getDeviceCount();
size_t sizeBytes{LEN * sizeof(uint8_t)};
uint8_t *A;
A = reinterpret_cast<uint8_t*>(malloc(sizeBytes));
REQUIRE(A != nullptr);
memset(A, INITIAL_VAL, sizeBytes);
HIP_CHECK(hipHostRegister(A, sizeBytes, 0));
int out = 0;
SECTION("Attribute = hipMemAdviseSetReadMostly") {
HIP_CHECK(hipMemAdvise(A, sizeBytes, hipMemAdviseSetReadMostly, 0));
HIP_CHECK(hipMemRangeGetAttribute(&out, 4, hipMemRangeAttributeReadMostly,
A, sizeBytes));
REQUIRE(out == 1);
HIP_CHECK(hipMemAdvise(A, sizeBytes, hipMemAdviseUnsetReadMostly, 0));
HIP_CHECK(hipMemRangeGetAttribute(&out, 4, hipMemRangeAttributeReadMostly,
A, sizeBytes));
REQUIRE(out == 0);
}
SECTION("Attribute = hipMemAdviseSetPreferredLocation") {
HIP_CHECK(hipMemAdvise(A, sizeBytes,
hipMemAdviseSetPreferredLocation, hipCpuDeviceId));
HIP_CHECK(hipMemRangeGetAttribute(&out, sizeof(int),
hipMemRangeAttributePreferredLocation, A, sizeBytes));
REQUIRE(out == hipCpuDeviceId);
for (int dev = 0; dev < numDevices; dev++) {
HIP_CHECK(hipMemAdvise(A, sizeBytes,
hipMemAdviseSetPreferredLocation, dev));
HIP_CHECK(hipMemRangeGetAttribute(&out, sizeof(int),
hipMemRangeAttributePreferredLocation, A, sizeBytes));
REQUIRE(out == dev);
}
HIP_CHECK(hipMemAdvise(A, sizeBytes,
hipMemAdviseUnsetPreferredLocation, 0));
HIP_CHECK(hipMemRangeGetAttribute(&out, sizeof(int),
hipMemRangeAttributePreferredLocation, A, sizeBytes));
REQUIRE(out == hipInvalidDeviceId);
}
SECTION("Attribute = hipMemAdviseSetAccessedBy") {
size_t size = numDevices*sizeof(int);
int *chkOut = reinterpret_cast<int*>(malloc(size));
HIP_CHECK(hipMemAdvise(A, sizeBytes,
hipMemAdviseSetAccessedBy, hipCpuDeviceId));
for (int dev = 0; dev < numDevices; dev++) {
HIP_CHECK(hipMemAdvise(A, sizeBytes,
hipMemAdviseSetAccessedBy, dev));
}
HIP_CHECK(hipMemRangeGetAttribute(chkOut, size,
hipMemRangeAttributeAccessedBy, A, sizeBytes));
for (int dev = 0; dev < numDevices; dev++) {
REQUIRE(chkOut[dev] == dev);
}
free(chkOut);
}
HIP_CHECK(hipHostUnregister(A));
free(A);
}
#endif
/**
* Test Description
* ------------------------
* - This testcase verifies hipHostRegister API by performing memcpy
* on the hipHostRegistered variable.
* Test source
* ------------------------
* - catch\unit\memory\hipHostRegister.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
TEMPLATE_TEST_CASE("Unit_hipHostRegister_Memcpy", "", int, float, double) {
// 1 refers to hipHostRegister
// 0 refers to malloc
auto mem_type = GENERATE(0, 1);
HIP_CHECK(hipSetDevice(0));
size_t sizeBytes = LEN * sizeof(TestType);
TestType* A = reinterpret_cast<TestType*>(malloc(sizeBytes));
@@ -161,6 +896,17 @@ template <typename T> __global__ void fill_kernel(T* dataPtr, T value) {
dataPtr[tid] = value;
}
/**
* Test Description
* ------------------------
* - This testcase verifies all the supported flags of hipHostRegister.
* Test source
* ------------------------
* - catch\unit\memory\hipHostRegister.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
TEMPLATE_TEST_CASE("Unit_hipHostRegister_Flags", "", int, float, double) {
size_t sizeBytes = 1 * sizeof(TestType);
TestType* hostPtr = reinterpret_cast<TestType*>(malloc(sizeBytes));
@@ -171,25 +917,40 @@ TEMPLATE_TEST_CASE("Unit_hipHostRegister_Flags", "", int, float, double) {
bool valid;
};
/* EXSWCPHIPT-29 - 0x08 is hipHostRegisterReadOnly which currently doesn't have a definition in the headers */
/* hipHostRegisterIoMemory is a valid flag but requires access to I/O mapped memory to be tested */
FlagType flags = GENERATE(
FlagType{hipHostRegisterDefault, true}, FlagType{hipHostRegisterPortable, true},
FlagType{0x08, true}, FlagType{hipHostRegisterPortable | hipHostRegisterMapped, true},
FlagType{hipHostRegisterPortable | hipHostRegisterMapped | 0x08, true}, FlagType{0xF0, false},
FlagType{0xFFF2, false}, FlagType{0xFFFFFFFF, false});
/* EXSWCPHIPT-29 - 0x08 is hipHostRegisterReadOnly which currently doesn't
have a definition in the headers */
/* hipHostRegisterIoMemory is a valid flag but requires access to I/O mapped
memory to be tested */
FlagType flags = GENERATE(FlagType{hipHostRegisterDefault, true},
FlagType{hipHostRegisterPortable, true},
FlagType{0x08, true},
FlagType{hipHostRegisterPortable | hipHostRegisterMapped, true},
FlagType{hipHostRegisterPortable | hipHostRegisterMapped | 0x08, true},
FlagType{0xF0, false},
FlagType{0xFFF2, false}, FlagType{0xFFFFFFFF, false});
INFO("Testing hipHostRegister flag: " << flags.value);
if (flags.valid) {
HIP_CHECK(hipHostRegister(hostPtr, sizeBytes, flags.value));
HIP_CHECK(hipHostUnregister(hostPtr));
} else {
HIP_CHECK_ERROR(hipHostRegister(hostPtr, sizeBytes, flags.value), hipErrorInvalidValue);
HIP_CHECK_ERROR(hipHostRegister(hostPtr, sizeBytes, flags.value),
hipErrorInvalidValue);
}
free(hostPtr);
}
/**
* Test Description
* ------------------------
* - These negative tests checks invalid parameter values.
* Test source
* ------------------------
* - catch\unit\memory\hipHostRegister.cc
* Test requirements
* ------------------------
* - HIP_VERSION >= 5.2
*/
TEMPLATE_TEST_CASE("Unit_hipHostRegister_Negative", "", int, float, double) {
TestType* hostPtr = nullptr;
@@ -205,12 +966,14 @@ TEMPLATE_TEST_CASE("Unit_hipHostRegister_Negative", "", int, float, double) {
size_t devMemAvail{0}, devMemFree{0};
HIP_CHECK(hipMemGetInfo(&devMemFree, &devMemAvail));
auto hostMemFree = HipTest::getMemoryAmount() /* In MB */ * 1024 * 1024; // In bytes
auto hostMemFree =
HipTest::getMemoryAmount() /* In MB */ * 1024 * 1024; // In bytes
REQUIRE(devMemFree > 0);
REQUIRE(devMemAvail > 0);
REQUIRE(hostMemFree > 0);
size_t memFree = (std::max)(devMemFree, hostMemFree); // which is the limiter cpu or gpu
// which is the limiter cpu or gpu
size_t memFree = (std::max)(devMemFree, hostMemFree);
SECTION("hipHostRegister Negative Test - invalid memory size") {
HIP_CHECK_ERROR(hipHostRegister(hostPtr, memFree, 0), hipErrorInvalidValue);
+155
Просмотреть файл
@@ -0,0 +1,155 @@
/*
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
*/
#include <stdlib.h>
#include <iostream>
#include <chrono> // NOLINT
#include "hip/hip_runtime_api.h"
#define ITERATION 1000
#define SIZE (64*1024*1024)
#define ARRAY_SIZE 20
static bool UNSETENV(std::string var) {
int result = -1;
#ifdef __unix__
result = unsetenv(var.c_str());
#else
result = _putenv((var + '=').c_str());
#endif
return (result == 0) ? true: false;
}
static bool SETENV(std::string var, std::string value, int overwrite) {
int result = -1;
#ifdef __unix__
result = setenv(var.c_str(), value.c_str(), overwrite);
#else
result = _putenv((var + '=' + value).c_str());
#endif
return (result == 0) ? true: false;
}
/**
Expects 2 command line arg, first command is flag svm_enable = 1/0
and second command is test number: 0 = Register/Unregister different
chunks of host memory, 1 = Register/Unregister the same chunk of host
memory repeatedly, 2 = Register/Unregister the same chunk of host
memory repeatedly on multiple GPUs.
*/
int main(int argc, char** argv) {
if (argc != 3) {
std::cerr << "Invalid number of args passed.\n"
<< "argc : " << argc << std::endl;
return -1;
}
std::string env_flag = argv[1];
int test = std::stoi(argv[2]);
// disable SVM feature using HSA_USE_SVM=0 env from shell
UNSETENV("HSA_USE_SVM");
if (env_flag == "svm_enable") {
SETENV("HSA_USE_SVM", "1", 1);
} else {
SETENV("HSA_USE_SVM", "0", 1);
}
if (test == 0) {
uint8_t *A[ARRAY_SIZE];
for (int i = 0; i < ARRAY_SIZE; i++) {
A[i] = reinterpret_cast<uint8_t*>(malloc(SIZE));
if (A[i] == nullptr) {
return -1;
}
}
auto t1 = std::chrono::high_resolution_clock::now();
for (int count = 0; count < ITERATION; count++) {
// Register the host pointer
if (hipSuccess != hipHostRegister(A[count%ARRAY_SIZE], SIZE, 0)) {
return -1;
}
// Unregister the host pointer
if (hipSuccess != hipHostUnregister(A[count%ARRAY_SIZE])) {
return -1;
}
}
auto t2 = std::chrono::high_resolution_clock::now();
for (int i = 0; i < ARRAY_SIZE; i++) {
free(A[i]);
}
std::chrono::duration<float, std::milli> fp_ms = t2 - t1;
std::cout << fp_ms.count() << std::endl;
} else if (test == 1) {
uint8_t *A;
A = reinterpret_cast<uint8_t*>(malloc(SIZE));
if (A == nullptr) {
return -1;
}
auto t1 = std::chrono::high_resolution_clock::now();
for (int count = 0; count < ITERATION; count++) {
// Register the host pointer
if (hipSuccess != hipHostRegister(A, SIZE, 0)) {
return -1;
}
// Unregister the host pointer
if (hipSuccess != hipHostUnregister(A)) {
return -1;
}
}
auto t2 = std::chrono::high_resolution_clock::now();
free(A);
std::chrono::duration<float, std::milli> fp_ms = t2 - t1;
std::cout << fp_ms.count() << std::endl;
} else if (test == 2) {
uint8_t *A;
A = reinterpret_cast<uint8_t*>(malloc(SIZE));
if (A == nullptr) {
return -1;
}
int dev_count = 0;
if (hipSuccess != hipGetDeviceCount(&dev_count)) {
return -1;
}
auto t1 = std::chrono::high_resolution_clock::now();
for (int dev = 0; dev < dev_count; dev++) {
if (hipSuccess != hipSetDevice(dev)) {
return -1;
}
for (int count = 0; count < ITERATION; count++) {
// Register the host pointer
if (hipSuccess != hipHostRegister(A, SIZE, 0)) {
return -1;
}
// Unregister the host pointer
if (hipSuccess != hipHostUnregister(A)) {
return -1;
}
}
}
auto t2 = std::chrono::high_resolution_clock::now();
free(A);
std::chrono::duration<float, std::milli> fp_ms = t2 - t1;
std::cout << fp_ms.count() << std::endl;
} else {
// Undefined test
}
UNSETENV("HSA_USE_SVM");
return 0;
}
+1 -1
Просмотреть файл
@@ -43,7 +43,7 @@ static void MemoryAlloc3DDiffSizes(int gpu) {
size_t height{sizes}, depth{sizes};
hipPitchedPtr devPitchedPtr[CHUNK_LOOP];
hipExtent extent = make_hipExtent(width, height, depth);
size_t tot, avail, ptot, pavail;
size_t ptot, pavail;
HIPCHECK(hipMemGetInfo(&pavail, &ptot));
for (int i = 0; i < CHUNK_LOOP; i++) {
HIPCHECK(hipMalloc3D(&devPitchedPtr[i], extent));
+15 -5
Просмотреть файл
@@ -399,12 +399,22 @@ TEMPLATE_TEST_CASE("Unit_hipMallocArray_happy", "", uint, int, int4, ushort, sho
testArrayAsSurface<TestType>(arrayPtr, width, height);
}
SECTION("hipArrayTextureGather") {
height = 1024;
INFO("flag is hipArrayTextureGather");
INFO("height: " << height);
hipDeviceProp_t prop;
int device;
HIP_CHECK(hipGetDevice(&device));
HIP_CHECK(hipGetDeviceProperties(&prop, device));
// tex2Dgather not supported on gfx90a
if (std::string(prop.gcnArchName).find("gfx90a") == std::string::npos) {
height = 1024;
INFO("flag is hipArrayTextureGather");
INFO("height: " << height);
HIP_CHECK(hipMallocArray(&arrayPtr, &desc, width, height, hipArrayTextureGather));
testArrayAsTextureWithGather<TestType>(arrayPtr, width, height);
HIP_CHECK(hipMallocArray(&arrayPtr, &desc, width, height, hipArrayTextureGather));
testArrayAsTextureWithGather<TestType>(arrayPtr, width, height);
} else {
SUCCEED("tex2Dgather is not supported for gfx90a, Hence"
"skipping the testcase for this device " << device);
}
}
#endif

Некоторые файлы не были показаны из-за слишком большого количества измененных файлов Показать больше