CodeQL / Analyze (actions) (push) Canceled after 0s
CodeQL / Analyze (python) (push) Canceled after 0s
pre-commit / pre-commit (push) Canceled after 0s
Multi-Arch CI / setup (push) Canceled after 0s
Publish build_manylinux_x86_64 images / publish_build_manylinux_x86_64 (push) Canceled after 0s
Setup (Multi-Arch) / setup (push) Canceled after 0s
Multi-Arch CI / Linux::${{ fromJSON(needs.setup.outputs.linux_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubi10 image / publish_no_rocm_image_ubi10 (push) Canceled after 0s
Multi-Arch CI / Windows::${{ fromJSON(needs.setup.outputs.windows_build_config || '{}').build_variant_label || 'skip' }} (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Multi-Arch CI / Manifest Diff (push) Canceled after 0s
TheRock Manifest Diff Report / Generate Manifest Diff Report (push) Canceled after 0s
Multi-Arch CI / CI Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_ocl_rt images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04_rocgdb images / publish_no_rocm_image_ubuntu24_04_rocgdb (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_ocl_rt (push) Canceled after 0s
Publish TheRock Docker image / build-and-push-image (push) Canceled after 0s
Unit Tests / Unit Tests :: ubuntu-24.04 (push) Canceled after 0s
Unit Tests / Unit Tests :: windows-2022 (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_media (push) Canceled after 0s
Unit Tests / Unit Tests Summary (push) Canceled after 0s
Publish no_rocm_image_ubuntu24_04 images / publish_no_rocm_image_ubuntu24_04_openmpi (push) Canceled after 0s
260 lines
9.7 KiB
C++
260 lines
9.7 KiB
C++
/*
|
|
* Copyright (c) Advanced Micro Devices, Inc., or its affiliates.
|
|
*
|
|
* SPDX-License-Identifier: MIT
|
|
*/
|
|
|
|
#include "execution_control_common.hh"
|
|
|
|
#include <hip_test_common.hh>
|
|
#include <hip/hip_runtime_api.h>
|
|
|
|
/**
|
|
* @addtogroup hipFuncSetAttribute hipFuncSetAttribute
|
|
* @{
|
|
* @ingroup ExecutionTest
|
|
* `hipFuncSetAttribute(const void* func, hipFuncAttribute attr, int value)` -
|
|
* Set attribute for a specific function.
|
|
*/
|
|
|
|
/**
|
|
* Test Description
|
|
* ------------------------
|
|
* - Sets maximum dynamic shared memory size to the non-default value.
|
|
* - Expected output: return `hipSuccess`
|
|
* Test source
|
|
* ------------------------
|
|
* - unit/executionControl/hipFuncSetAttribute.cc
|
|
* Test requirements
|
|
* ------------------------
|
|
* - HIP_VERSION >= 5.2
|
|
*/
|
|
HIP_TEST_CASE(Unit_hipFuncSetAttribute_Positive_MaxDynamicSharedMemorySize) {
|
|
HIP_CHECK(hipFuncSetAttribute(reinterpret_cast<void*>(kernel),
|
|
hipFuncAttributeMaxDynamicSharedMemorySize, 1024));
|
|
|
|
hipFuncAttributes attributes;
|
|
HIP_CHECK(hipFuncGetAttributes(&attributes, reinterpret_cast<void*>(kernel)));
|
|
|
|
REQUIRE(attributes.maxDynamicSharedSizeBytes == 1024);
|
|
}
|
|
|
|
/**
|
|
* Test Description
|
|
* ------------------------
|
|
* - Sets preferred shared memory carveout to the non-default value.
|
|
* - Expected output: return `hipSuccess`
|
|
* Test source
|
|
* ------------------------
|
|
* - unit/executionControl/hipFuncSetAttribute.cc
|
|
* Test requirements
|
|
* ------------------------
|
|
* - HIP_VERSION >= 5.2
|
|
*/
|
|
HIP_TEST_CASE(Unit_hipFuncSetAttribute_Positive_PreferredSharedMemoryCarveout) {
|
|
HIP_CHECK(hipFuncSetAttribute(reinterpret_cast<void*>(kernel),
|
|
hipFuncAttributePreferredSharedMemoryCarveout, 50));
|
|
|
|
hipFuncAttributes attributes;
|
|
HIP_CHECK(hipFuncGetAttributes(&attributes, reinterpret_cast<void*>(kernel)));
|
|
|
|
REQUIRE(attributes.preferredShmemCarveout == 50);
|
|
}
|
|
|
|
/**
|
|
* Test Description
|
|
* ------------------------
|
|
* - Validates handling of valid arguments:
|
|
* -# When `hipFuncAttributeMaxDynamicSharedMemorySize == 0`
|
|
* - Expected output: return `hipSuccess`
|
|
* -# When `hipFuncAttributeMaxDynamicSharedMemorySize == maxSharedMemoryPerBlock -
|
|
* sharedSizeBytes`
|
|
* - Expected output: return `hipSuccess`
|
|
* -# When `hipFuncAttributePreferredSharedMemoryCarveout` is 0%
|
|
* - Expected output: return `hipSuccess`
|
|
* -# When `hipFuncAttributePreferredSharedMemoryCarveout` is 100%
|
|
* - Expected output: return `hipSuccess`
|
|
* -# When `hipFuncAttributePreferredSharedMemoryCarveout` is default (-1)
|
|
* - Expected output: return `hipSuccess`
|
|
* Test source
|
|
* ------------------------
|
|
* - unit/executionControl/hipFuncSetAttribute.cc
|
|
* Test requirements
|
|
* ------------------------
|
|
* - HIP_VERSION >= 5.2
|
|
*/
|
|
HIP_TEST_CASE(Unit_hipFuncSetAttribute_Positive_Parameters) {
|
|
SECTION("hipFuncAttributeMaxDynamicSharedMemorySize == 0") {
|
|
HIP_CHECK(hipFuncSetAttribute(reinterpret_cast<void*>(kernel),
|
|
hipFuncAttributeMaxDynamicSharedMemorySize, 0));
|
|
}
|
|
|
|
SECTION(
|
|
"hipFuncAttributeMaxDynamicSharedMemorySize == maxSharedMemoryPerBlock - sharedSizeBytes") {
|
|
// The sum of this value and the function attribute sharedSizeBytes cannot exceed the device
|
|
// attribute cudaDevAttrMaxSharedMemoryPerBlockOptin
|
|
int max_shared;
|
|
HIP_CHECK(hipDeviceGetAttribute(&max_shared, hipDeviceAttributeMaxSharedMemoryPerBlock, 0));
|
|
|
|
hipFuncAttributes attributes;
|
|
HIP_CHECK(hipFuncGetAttributes(&attributes, reinterpret_cast<void*>(kernel)));
|
|
|
|
HIP_CHECK(hipFuncSetAttribute(reinterpret_cast<void*>(kernel),
|
|
hipFuncAttributeMaxDynamicSharedMemorySize,
|
|
max_shared - attributes.sharedSizeBytes));
|
|
}
|
|
|
|
SECTION("hipFuncAttributePreferredSharedMemoryCarveout == 0") {
|
|
HIP_CHECK(hipFuncSetAttribute(reinterpret_cast<void*>(kernel),
|
|
hipFuncAttributePreferredSharedMemoryCarveout, 0));
|
|
}
|
|
|
|
SECTION("hipFuncAttributePreferredSharedMemoryCarveout == 100") {
|
|
HIP_CHECK(hipFuncSetAttribute(reinterpret_cast<void*>(kernel),
|
|
hipFuncAttributePreferredSharedMemoryCarveout, 100));
|
|
}
|
|
|
|
SECTION("hipFuncAttributePreferredSharedMemoryCarveout == -1 (default)") {
|
|
HIP_CHECK(hipFuncSetAttribute(reinterpret_cast<void*>(kernel),
|
|
hipFuncAttributePreferredSharedMemoryCarveout, -1));
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Test Description
|
|
* ------------------------
|
|
* - Validates handling of invalid arguments:
|
|
* -# When pointer to the kernel function is `nullptr`
|
|
* - Expected output: return `hipErrorInvalidDeviceFunction`
|
|
* -# When the attribute is invalid
|
|
* - Expected output: return `hipErrorInvalidValue`
|
|
* -# When `hipFuncAttributeMaxDynamicSharedMemorySize < 0`
|
|
* - Expected output: return `hipErrorInvalidValue`
|
|
* -# When `hipFuncAttributeMaxDynamicSharedMemorySize > maxSharedMemoryPerBlock -
|
|
* sharedSizeBytes`
|
|
* - Expected output: return `hipErrorInvalidValue`
|
|
* -# When `hipFuncAttributePreferredSharedMemoryCarveout` is negative
|
|
* - Expected output: return `hipErrorInvalidValue`
|
|
* -# When `hipFuncAttributePreferredSharedMemoryCarveout` is above 100%
|
|
* - Expected output: return `hipErrorInvalidValue`
|
|
* Test source
|
|
* ------------------------
|
|
* - unit/executionControl/hipFuncSetAttribute.cc
|
|
* Test requirements
|
|
* ------------------------
|
|
* - HIP_VERSION >= 5.2
|
|
*/
|
|
HIP_TEST_CASE(Unit_hipFuncSetAttribute_Negative_Parameters) {
|
|
SECTION("func == nullptr") {
|
|
HIP_CHECK_ERROR(hipFuncSetAttribute(nullptr, hipFuncAttributePreferredSharedMemoryCarveout, 50),
|
|
hipErrorInvalidDeviceFunction);
|
|
}
|
|
|
|
SECTION("invalid attribute") {
|
|
HIP_CHECK_ERROR(
|
|
hipFuncSetAttribute(reinterpret_cast<void*>(kernel), static_cast<hipFuncAttribute>(-1), 50),
|
|
hipErrorInvalidValue);
|
|
}
|
|
|
|
SECTION("hipFuncAttributeMaxDynamicSharedMemorySize < 0") {
|
|
HIP_CHECK_ERROR(hipFuncSetAttribute(reinterpret_cast<void*>(kernel),
|
|
hipFuncAttributeMaxDynamicSharedMemorySize, -1),
|
|
hipErrorInvalidValue);
|
|
}
|
|
|
|
SECTION(
|
|
"hipFuncAttributeMaxDynamicSharedMemorySize > maxSharedMemoryPerBlock - sharedSizeBytes") {
|
|
// The sum of this value and the function attribute sharedSizeBytes cannot exceed the device
|
|
// attribute cudaDevAttrMaxSharedMemoryPerBlockOptin
|
|
int max_shared;
|
|
HIP_CHECK(hipDeviceGetAttribute(&max_shared, hipDeviceAttributeSharedMemPerBlockOptin, 0));
|
|
|
|
hipFuncAttributes attributes;
|
|
HIP_CHECK(hipFuncGetAttributes(&attributes, reinterpret_cast<void*>(kernel)));
|
|
|
|
HIP_CHECK_ERROR(hipFuncSetAttribute(reinterpret_cast<void*>(kernel),
|
|
hipFuncAttributeMaxDynamicSharedMemorySize,
|
|
max_shared - attributes.sharedSizeBytes + 1),
|
|
hipErrorInvalidValue);
|
|
}
|
|
|
|
SECTION("hipFuncAttributePreferredSharedMemoryCarveout < -1") {
|
|
HIP_CHECK_ERROR(hipFuncSetAttribute(reinterpret_cast<void*>(kernel),
|
|
hipFuncAttributePreferredSharedMemoryCarveout, -2),
|
|
hipErrorInvalidValue);
|
|
}
|
|
|
|
SECTION("hipFuncAttributePreferredSharedMemoryCarveout > 100") {
|
|
HIP_CHECK_ERROR(hipFuncSetAttribute(reinterpret_cast<void*>(kernel),
|
|
hipFuncAttributePreferredSharedMemoryCarveout, 101),
|
|
hipErrorInvalidValue);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Test Description
|
|
* ------------------------
|
|
* - Sets `hipFuncAttributeMaxDynamicSharedMemorySize` to the non-supported value
|
|
* - Expected output: return `hipErrorNotSupported`
|
|
* Test source
|
|
* ------------------------
|
|
* - unit/executionControl/hipFuncSetAttribute.cc
|
|
* Test requirements
|
|
* ------------------------
|
|
* - Platform specific (AMD)
|
|
* - HIP_VERSION >= 5.2
|
|
*/
|
|
HIP_TEST_CASE(Unit_hipFuncSetAttribute_Positive_MaxDynamicSharedMemorySize_Not_Supported) {
|
|
#if HT_NVIDIA
|
|
HIP_SKIP_TEST(HipTest::SkipReason::kApiUnsupportedOnNvidia);
|
|
#endif
|
|
|
|
hipFuncAttributes old_attributes;
|
|
HIP_CHECK(hipFuncGetAttributes(&old_attributes, reinterpret_cast<void*>(kernel)));
|
|
|
|
HIP_CHECK_ERROR(hipFuncSetAttribute(reinterpret_cast<void*>(kernel),
|
|
hipFuncAttributeMaxDynamicSharedMemorySize, 1024),
|
|
hipErrorNotSupported);
|
|
|
|
hipFuncAttributes new_attributes;
|
|
HIP_CHECK(hipFuncGetAttributes(&new_attributes, reinterpret_cast<void*>(kernel)));
|
|
|
|
REQUIRE(old_attributes.maxDynamicSharedSizeBytes == new_attributes.maxDynamicSharedSizeBytes);
|
|
}
|
|
|
|
/**
|
|
* Test Description
|
|
* ------------------------
|
|
* - Sets `hipFuncAttributePreferredSharedMemoryCarveout` to the non-supported value
|
|
* - Expected output: return `hipErrorNotSupported`
|
|
* Test source
|
|
* ------------------------
|
|
* - unit/executionControl/hipFuncSetAttribute.cc
|
|
* Test requirements
|
|
* ------------------------
|
|
* - Platform specific (AMD)
|
|
* - HIP_VERSION >= 5.2
|
|
*/
|
|
HIP_TEST_CASE(Unit_hipFuncSetAttribute_Positive_PreferredSharedMemoryCarveout_Not_Supported) {
|
|
#if HT_NVIDIA
|
|
HIP_SKIP_TEST(HipTest::SkipReason::kApiUnsupportedOnNvidia);
|
|
#endif
|
|
|
|
hipFuncAttributes old_attributes;
|
|
HIP_CHECK(hipFuncGetAttributes(&old_attributes, reinterpret_cast<void*>(kernel)));
|
|
|
|
HIP_CHECK_ERROR(hipFuncSetAttribute(reinterpret_cast<void*>(kernel),
|
|
hipFuncAttributePreferredSharedMemoryCarveout, 50),
|
|
hipErrorNotSupported);
|
|
|
|
hipFuncAttributes new_attributes;
|
|
HIP_CHECK(hipFuncGetAttributes(&new_attributes, reinterpret_cast<void*>(kernel)));
|
|
|
|
REQUIRE(old_attributes.preferredShmemCarveout == new_attributes.preferredShmemCarveout);
|
|
}
|
|
|
|
/**
|
|
* End doxygen group ExecutionTest.
|
|
* @}
|
|
*/
|