Skip to content

Commit d0176fe

Browse files
committed
SWDEV-546322 Implement hipMipmappedArrayGetMemoryRequirements
Signed-off-by: Sebastian Luzynski <[email protected]>
1 parent e2d8301 commit d0176fe

File tree

19 files changed

+205
-10
lines changed

19 files changed

+205
-10
lines changed

projects/clr/hipamd/include/hip/amd_detail/hip_api_trace.hpp

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1113,6 +1113,8 @@ typedef hipError_t (*t_hipKernelGetLibrary)(hipLibrary_t* library, hipKernel_t k
11131113
typedef hipError_t (*t_hipKernelGetName)(const char** name, hipKernel_t kernel);
11141114
typedef hipError_t (*t_hipGetProcAddress_spt)(const char* symbol, void** pfn, int hipVersion, uint64_t flags,
11151115
hipDriverProcAddressQueryResult* symbolStatus);
1116+
typedef hipError_t (*t_hipMipmappedArrayGetMemoryRequirements)(
1117+
hipArrayMemoryRequirements* memoryRequirements, hipMipmappedArray_t mipmap, hipDevice_t device);
11161118

11171119
typedef hipError_t (*t_hipKernelGetParamInfo)(hipKernel_t kernel, size_t paramIndex,
11181120
size_t* paramOffset, size_t* paramSize);
@@ -1707,8 +1709,11 @@ struct HipDispatchTable {
17071709
// HIP_RUNTIME_API_TABLE_STEP_VERSION == 20
17081710
t_hipKernelGetParamInfo hipKernelGetParamInfo_fn;
17091711

1710-
// DO NOT EDIT ABOVE!
17111712
// HIP_RUNTIME_API_TABLE_STEP_VERSION == 21
1713+
t_hipMipmappedArrayGetMemoryRequirements hipMipmappedArrayGetMemoryRequirements_fn;
1714+
1715+
// DO NOT EDIT ABOVE!
1716+
// HIP_RUNTIME_API_TABLE_STEP_VERSION == 22
17121717

17131718
// ******************************************************************************************* //
17141719
//
@@ -1745,4 +1750,4 @@ struct HipToolsDispatchTable {
17451750
// 4) GENERATE COMMENT FOR NEXT STEP VERSION
17461751
// 5) ADD "DO NOT EDIT ABOVE!" COMMENT
17471752
// ******************************************************************************************* //
1748-
};
1753+
};

projects/clr/hipamd/include/hip/amd_detail/hip_prof_str.h

Lines changed: 28 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,8 @@ enum hip_api_id_t {
468468
HIP_API_ID_hipKernelGetName = 448,
469469
HIP_API_ID_hipOccupancyAvailableDynamicSMemPerBlock = 449,
470470
HIP_API_ID_hipKernelGetParamInfo = 450,
471-
HIP_API_ID_LAST = 450,
471+
HIP_API_ID_hipMipmappedArrayGetMemoryRequirements = 451,
472+
HIP_API_ID_LAST = 451,
472473

473474
HIP_API_ID_hipChooseDevice = HIP_API_ID_CONCAT(HIP_API_ID_,hipChooseDevice),
474475
HIP_API_ID_hipGetDeviceProperties = HIP_API_ID_CONCAT(HIP_API_ID_,hipGetDeviceProperties),
@@ -859,6 +860,7 @@ static inline const char* hip_api_name(const uint32_t id) {
859860
case HIP_API_ID_hipMipmappedArrayCreate: return "hipMipmappedArrayCreate";
860861
case HIP_API_ID_hipMipmappedArrayDestroy: return "hipMipmappedArrayDestroy";
861862
case HIP_API_ID_hipMipmappedArrayGetLevel: return "hipMipmappedArrayGetLevel";
863+
case HIP_API_ID_hipMipmappedArrayGetMemoryRequirements: return "hipMipmappedArrayGetMemoryRequirements";
862864
case HIP_API_ID_hipModuleGetFunction: return "hipModuleGetFunction";
863865
case HIP_API_ID_hipModuleGetFunctionCount: return "hipModuleGetFunctionCount";
864866
case HIP_API_ID_hipModuleGetGlobal: return "hipModuleGetGlobal";
@@ -1303,6 +1305,7 @@ static inline uint32_t hipApiIdByName(const char* name) {
13031305
if (strcmp("hipMipmappedArrayCreate", name) == 0) return HIP_API_ID_hipMipmappedArrayCreate;
13041306
if (strcmp("hipMipmappedArrayDestroy", name) == 0) return HIP_API_ID_hipMipmappedArrayDestroy;
13051307
if (strcmp("hipMipmappedArrayGetLevel", name) == 0) return HIP_API_ID_hipMipmappedArrayGetLevel;
1308+
if (strcmp("hipMipmappedArrayGetMemoryRequirements", name) == 0) return HIP_API_ID_hipMipmappedArrayGetMemoryRequirements;
13061309
if (strcmp("hipModuleGetFunction", name) == 0) return HIP_API_ID_hipModuleGetFunction;
13071310
if (strcmp("hipModuleGetFunctionCount", name) == 0) return HIP_API_ID_hipModuleGetFunctionCount;
13081311
if (strcmp("hipModuleGetGlobal", name) == 0) return HIP_API_ID_hipModuleGetGlobal;
@@ -3548,6 +3551,12 @@ typedef struct hip_api_data_s {
35483551
hipMipmappedArray_t hMipMappedArray;
35493552
unsigned int level;
35503553
} hipMipmappedArrayGetLevel;
3554+
struct {
3555+
hipArrayMemoryRequirements* memoryRequirements;
3556+
hipArrayMemoryRequirements memoryRequirements__val;
3557+
hipMipmappedArray_t mipmap;
3558+
hipDevice_t device;
3559+
} hipMipmappedArrayGetMemoryRequirements;
35513560
struct {
35523561
hipFunction_t* function;
35533562
hipFunction_t function__val;
@@ -6243,6 +6252,12 @@ typedef struct hip_api_data_s {
62436252
cb_data.args.hipMipmappedArrayGetLevel.hMipMappedArray = (hipMipmappedArray_t)mipmapped_array_ptr; \
62446253
cb_data.args.hipMipmappedArrayGetLevel.level = (unsigned int)mip_level; \
62456254
};
6255+
// hipMipmappedArrayGetMemoryRequirements[('hipArrayMemoryRequirements*', 'memoryRequirements'), ('hipMipmappedArray_t', 'mipmap'), ('hipDevice_t', 'device')]
6256+
#define INIT_hipMipmappedArrayGetMemoryRequirements_CB_ARGS_DATA(cb_data) { \
6257+
cb_data.args.hipMipmappedArrayGetMemoryRequirements.memoryRequirements = (hipArrayMemoryRequirements*)memoryRequirements; \
6258+
cb_data.args.hipMipmappedArrayGetMemoryRequirements.mipmap = (hipMipmappedArray_t)mipmap; \
6259+
cb_data.args.hipMipmappedArrayGetMemoryRequirements.device = (hipDevice_t)device; \
6260+
};
62466261
// hipModuleGetFunction[('hipFunction_t*', 'function'), ('hipModule_t', 'module'), ('const char*', 'kname')]
62476262
#define INIT_hipModuleGetFunction_CB_ARGS_DATA(cb_data) { \
62486263
cb_data.args.hipModuleGetFunction.function = (hipFunction_t*)hfunc; \
@@ -8187,6 +8202,10 @@ static inline void hipApiArgsInit(hip_api_id_t id, hip_api_data_t* data) {
81878202
case HIP_API_ID_hipMipmappedArrayGetLevel:
81888203
if (data->args.hipMipmappedArrayGetLevel.pLevelArray) data->args.hipMipmappedArrayGetLevel.pLevelArray__val = *(data->args.hipMipmappedArrayGetLevel.pLevelArray);
81898204
break;
8205+
// hipMipmappedArrayGetMemoryRequirements[('hipArrayMemoryRequirements*', 'memoryRequirements'), ('hipMipmappedArray_t', 'mipmap'), ('hipDevice_t', 'device')]
8206+
case HIP_API_ID_hipMipmappedArrayGetMemoryRequirements:
8207+
if (data->args.hipMipmappedArrayGetMemoryRequirements.memoryRequirements) data->args.hipMipmappedArrayGetMemoryRequirements.memoryRequirements__val = *(data->args.hipMipmappedArrayGetMemoryRequirements.memoryRequirements);
8208+
break;
81908209
// hipModuleGetFunction[('hipFunction_t*', 'function'), ('hipModule_t', 'module'), ('const char*', 'kname')]
81918210
case HIP_API_ID_hipModuleGetFunction:
81928211
if (data->args.hipModuleGetFunction.function) data->args.hipModuleGetFunction.function__val = *(data->args.hipModuleGetFunction.function);
@@ -11413,6 +11432,14 @@ static inline const char* hipApiString(hip_api_id_t id, const hip_api_data_t* da
1141311432
oss << ", level="; roctracer::hip_support::detail::operator<<(oss, data->args.hipMipmappedArrayGetLevel.level);
1141411433
oss << ")";
1141511434
break;
11435+
case HIP_API_ID_hipMipmappedArrayGetMemoryRequirements:
11436+
oss << "hipMipmappedArrayGetMemoryRequirements(";
11437+
if (data->args.hipMipmappedArrayGetMemoryRequirements.memoryRequirements == NULL) oss << "memoryRequirements=NULL";
11438+
else { oss << "memoryRequirements="; roctracer::hip_support::detail::operator<<(oss, data->args.hipMipmappedArrayGetMemoryRequirements.memoryRequirements__val); }
11439+
oss << ", mipmap="; roctracer::hip_support::detail::operator<<(oss, data->args.hipMipmappedArrayGetMemoryRequirements.mipmap);
11440+
oss << ", device="; roctracer::hip_support::detail::operator<<(oss, data->args.hipMipmappedArrayGetMemoryRequirements.device);
11441+
oss << ")";
11442+
break;
1141611443
case HIP_API_ID_hipModuleGetFunction:
1141711444
oss << "hipModuleGetFunction(";
1141811445
if (data->args.hipModuleGetFunction.function == NULL) oss << "function=NULL";

projects/clr/hipamd/src/amdhip.def

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -523,3 +523,4 @@ hipKernelGetName
523523
hipOccupancyAvailableDynamicSMemPerBlock
524524
hipGetProcAddress_spt
525525
hipKernelGetParamInfo
526+
hipMipmappedArrayGetMemoryRequirements

projects/clr/hipamd/src/hip_api_trace.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -885,6 +885,8 @@ hipError_t hipOccupancyAvailableDynamicSMemPerBlock(size_t* dynamicSmemSize, con
885885
int numBlocks, int blockSize);
886886
hipError_t hipKernelGetParamInfo(hipKernel_t kernel, size_t paramIndex, size_t* paramOffset,
887887
size_t* paramSize);
888+
hipError_t hipMipmappedArrayGetMemoryRequirements(hipArrayMemoryRequirements* memoryRequirements,
889+
hipMipmappedArray_t mipmap, hipDevice_t device);
888890
} // namespace hip
889891

890892
namespace hip {
@@ -1229,6 +1231,8 @@ void UpdateDispatchTable(HipDispatchTable* ptrDispatchTable) {
12291231
ptrDispatchTable->hipMemsetD8Async_fn = hip::hipMemsetD8Async;
12301232
ptrDispatchTable->hipMipmappedArrayCreate_fn = hip::hipMipmappedArrayCreate;
12311233
ptrDispatchTable->hipMipmappedArrayDestroy_fn = hip::hipMipmappedArrayDestroy;
1234+
ptrDispatchTable->hipMipmappedArrayGetMemoryRequirements_fn =
1235+
hip::hipMipmappedArrayGetMemoryRequirements;
12321236
ptrDispatchTable->hipMipmappedArrayGetLevel_fn = hip::hipMipmappedArrayGetLevel;
12331237
ptrDispatchTable->hipModuleGetFunction_fn = hip::hipModuleGetFunction;
12341238
ptrDispatchTable->hipModuleGetFunctionCount_fn = hip::hipModuleGetFunctionCount;
@@ -2114,13 +2118,15 @@ HIP_ENFORCE_ABI(HipDispatchTable, hipOccupancyAvailableDynamicSMemPerBlock_fn, 5
21142118
HIP_ENFORCE_ABI(HipDispatchTable, hipGetProcAddress_spt_fn, 506);
21152119
// HIP_RUNTIME_API_TABLE_STEP_VERSION == 20
21162120
HIP_ENFORCE_ABI(HipDispatchTable, hipKernelGetParamInfo_fn, 507);
2121+
// HIP_RUNTIME_API_TABLE_STEP_VERSION == 21
2122+
HIP_ENFORCE_ABI(HipDispatchTable, hipMipmappedArrayGetMemoryRequirements_fn, 508);
21172123
// if HIP_ENFORCE_ABI entries are added for each new function pointer in the table, the number below
21182124
// will be +1 of the number in the last HIP_ENFORCE_ABI line. E.g.:
21192125
//
21202126
// HIP_ENFORCE_ABI(<table>, <functor>, 8)
21212127
//
21222128
// HIP_ENFORCE_ABI_VERSIONING(<table>, 9) <- 8 + 1 = 9
2123-
HIP_ENFORCE_ABI_VERSIONING(HipDispatchTable, 508)
2129+
HIP_ENFORCE_ABI_VERSIONING(HipDispatchTable, 509)
21242130

21252131
static_assert(HIP_RUNTIME_API_TABLE_MAJOR_VERSION == 0 && HIP_RUNTIME_API_TABLE_STEP_VERSION == 20,
21262132
"If you get this error, add new HIP_ENFORCE_ABI(...) code for the new function "

projects/clr/hipamd/src/hip_conversions.hpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -994,4 +994,9 @@ inline hipMemcpy3DParms getMemcpy3DParms(const hipMemcpy3DPeerParms& desc) {
994994
params.kind = hipMemcpyDeviceToDevice;
995995
return params;
996996
}
997-
}; // namespace hip
997+
998+
inline hipArrayMemoryRequirements getArrayMemoryRequirements(
999+
const hipArrayMemoryRequirements& desc) {
1000+
return hipArrayMemoryRequirements { desc.alignment, desc.size };
1001+
}
1002+
}; // namespace hip

projects/clr/hipamd/src/hip_hcc.map.in

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -645,6 +645,7 @@ global:
645645
hipOccupancyAvailableDynamicSMemPerBlock;
646646
hipGetProcAddress_spt;
647647
hipKernelGetParamInfo;
648+
hipMipmappedArrayGetMemoryRequirements;
648649
local:
649650
*;
650651
} hip_7.1;

projects/clr/hipamd/src/hip_memory.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4304,6 +4304,32 @@ hipError_t ihipMipmappedArrayGetLevel(hipArray_t* level_array_pptr,
43044304
return hipSuccess;
43054305
}
43064306

4307+
hipError_t ihipMipmappedArrayGetMemoryRequirements(hipArrayMemoryRequirements* memoryRequirements,
4308+
hipMipmappedArray_t mipmap,
4309+
hipDevice_t device) {
4310+
if (memoryRequirements == nullptr) {
4311+
return hipErrorInvalidValue;
4312+
}
4313+
if (mipmap == nullptr) {
4314+
return hipErrorInvalidHandle;
4315+
}
4316+
4317+
cl_mem cl_mem_obj = reinterpret_cast<cl_mem>(mipmap->data);
4318+
if (is_valid(cl_mem_obj) == false) {
4319+
return hipErrorInvalidValue;
4320+
}
4321+
4322+
amd::Image* image = as_amd(cl_mem_obj)->asImage();
4323+
if (image == nullptr) {
4324+
return hipErrorInvalidValue;
4325+
}
4326+
4327+
memoryRequirements->alignment = image->getAlignment();
4328+
memoryRequirements->size = image->getSize();
4329+
4330+
return hipSuccess;
4331+
}
4332+
43074333
hipError_t hipMipmappedArrayCreate(hipMipmappedArray_t* mipmapped_array_pptr,
43084334
HIP_ARRAY3D_DESCRIPTOR* mipmapped_array_desc_ptr,
43094335
unsigned int num_mipmap_levels) {
@@ -4328,6 +4354,13 @@ hipError_t hipMipmappedArrayGetLevel(hipArray_t* level_array_pptr,
43284354
HIP_RETURN(ihipMipmappedArrayGetLevel(level_array_pptr, mipmapped_array_ptr, mip_level));
43294355
}
43304356

4357+
hipError_t hipMipmappedArrayGetMemoryRequirements(hipArrayMemoryRequirements* memoryRequirements,
4358+
hipMipmappedArray_t mipmap,
4359+
hipDevice_t device) {
4360+
HIP_INIT_API(hipMipmappedArrayGetMemoryRequirements, memoryRequirements, mipmap, device);
4361+
HIP_RETURN(ihipMipmappedArrayGetMemoryRequirements(memoryRequirements, mipmap, device));
4362+
}
4363+
43314364
hipError_t hipMallocMipmappedArray(hipMipmappedArray_t* mipmappedArray,
43324365
const hipChannelFormatDesc* desc, hipExtent extent,
43334366
unsigned int numLevels, unsigned int flags) {

projects/clr/hipamd/src/hip_table_interface.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2067,4 +2067,9 @@ hipError_t hipKernelGetParamInfo(hipKernel_t kernel, size_t paramIndex, size_t*
20672067
size_t* paramSize) {
20682068
return hip::GetHipDispatchTable()->hipKernelGetParamInfo_fn(kernel, paramIndex, paramOffset,
20692069
paramSize);
2070-
}
2070+
}
2071+
hipError_t hipMipmappedArrayGetMemoryRequirements(hipArrayMemoryRequirements* memoryRequirements,
2072+
hipMipmappedArray_t mipmap, hipDevice_t device) {
2073+
return hip::GetHipDispatchTable()->hipMipmappedArrayGetMemoryRequirements_fn(memoryRequirements,
2074+
mipmap, device);
2075+
}

projects/hip-tests/catch/unit/texture/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -147,6 +147,7 @@ set(TEST_SRC
147147
hipTexRefSetGetMipmapLevelBias.cc
148148
hipTexRefSetGetMipmapLevelClamp.cc
149149
hipTexRefSetGetMipmappedArray.cc
150+
hipMipmappedArrayGetMemoryRequirements.cc
150151
)
151152
endif()
152153

Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
/*
2+
Copyright (c) 2025 Advanced Micro Devices, Inc. All rights reserved.
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy
5+
of this software and associated documentation files (the "Software"), to deal
6+
in the Software without restriction, including without limitation the rights
7+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
copies of the Software, and to permit persons to whom the Software is
9+
furnished to do so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in
12+
all copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20+
THE SOFTWARE.
21+
*/
22+
23+
#include <hip_array_common.hh>
24+
#include <hip_test_common.hh>
25+
26+
TEST_CASE("Unit_hipMipmappedArrayGetMemoryRequirements_Negative_Parameters") {
27+
CHECK_IMAGE_SUPPORT;
28+
29+
#ifdef __linux__
30+
HipTest::HIP_SKIP_TEST("Mipmap APIs are not supported on Linux");
31+
return;
32+
#endif //__linux__
33+
34+
const int device_id = 0;
35+
hipArrayMemoryRequirements memoryRequirements{};
36+
hipmipmappedArray array;
37+
HIP_ARRAY3D_DESCRIPTOR desc = {};
38+
using vec_info = vector_info<float>;
39+
desc.Format = vec_info::format;
40+
desc.NumChannels = vec_info::size;
41+
desc.Width = 4;
42+
desc.Height = 4;
43+
desc.Depth = 6;
44+
desc.Flags = 0;
45+
46+
unsigned int levels = 1 + std::log2(desc.Depth);
47+
48+
HIP_CHECK(hipFree(0));
49+
HIP_CHECK(hipMipmappedArrayCreate(&array, &desc, levels));
50+
51+
SECTION("memoryRequirements is nullptr") {
52+
HIP_CHECK_ERROR(hipMipmappedArrayGetMemoryRequirements(nullptr, array, device_id), hipErrorInvalidValue);
53+
}
54+
55+
SECTION("mipmap is nullptr") {
56+
HIP_CHECK_ERROR(hipMipmappedArrayGetMemoryRequirements(&memoryRequirements, nullptr, device_id), hipErrorInvalidHandle);
57+
}
58+
}

0 commit comments

Comments
 (0)