Skip to content

Commit 76228e1

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

File tree

18 files changed

+194
-13
lines changed

18 files changed

+194
-13
lines changed

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

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1103,8 +1103,9 @@ typedef hipError_t (*t_hipLibraryLoadFromFile)(hipLibrary_t* library, const char
11031103
typedef hipError_t (*t_hipLibraryUnload)(hipLibrary_t library);
11041104
typedef hipError_t (*t_hipLibraryGetKernel)(hipKernel_t* pKernel, hipLibrary_t library,
11051105
const char* name);
1106-
typedef hipError_t (*t_hipLibraryGetKernelCount)(unsigned int *count,
1107-
hipLibrary_t library);
1106+
typedef hipError_t (*t_hipLibraryGetKernelCount)(unsigned int* count, hipLibrary_t library);
1107+
typedef hipError_t (*t_hipMipmappedArrayGetMemoryRequirements)(
1108+
hipArrayMemoryRequirements* memoryRequirements, hipMipmappedArray_t mipmap, hipDevice_t device);
11081109

11091110
// HIP Compiler dispatch table
11101111
struct HipCompilerDispatchTable {
@@ -1682,6 +1683,7 @@ struct HipDispatchTable {
16821683

16831684
// HIP_RUNTIME_API_TABLE_STEP_VERSION = 16
16841685
t_hipStreamCopyAttributes hipStreamCopyAttributes_fn;
1686+
t_hipMipmappedArrayGetMemoryRequirements hipMipmappedArrayGetMemoryRequirements_fn;
16851687

16861688
// DO NOT EDIT ABOVE!
16871689
// HIP_RUNTIME_API_TABLE_STEP_VERSION == 17
@@ -1721,4 +1723,4 @@ struct HipToolsDispatchTable {
17211723
// 4) GENERATE COMMENT FOR NEXT STEP VERSION
17221724
// 5) ADD "DO NOT EDIT ABOVE!" COMMENT
17231725
// ******************************************************************************************* //
1724-
};
1726+
};

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
@@ -463,7 +463,8 @@ enum hip_api_id_t {
463463
HIP_API_ID_hipLibraryGetKernelCount = 443,
464464
HIP_API_ID_hipMemGetHandleForAddressRange = 444,
465465
HIP_API_ID_hipStreamCopyAttributes = 445,
466-
HIP_API_ID_LAST = 445,
466+
HIP_API_ID_hipMipmappedArrayGetMemoryRequirements = 446,
467+
HIP_API_ID_LAST = 446,
467468

468469
HIP_API_ID_hipChooseDevice = HIP_API_ID_CONCAT(HIP_API_ID_,hipChooseDevice),
469470
HIP_API_ID_hipGetDeviceProperties = HIP_API_ID_CONCAT(HIP_API_ID_,hipGetDeviceProperties),
@@ -850,6 +851,7 @@ static inline const char* hip_api_name(const uint32_t id) {
850851
case HIP_API_ID_hipMipmappedArrayCreate: return "hipMipmappedArrayCreate";
851852
case HIP_API_ID_hipMipmappedArrayDestroy: return "hipMipmappedArrayDestroy";
852853
case HIP_API_ID_hipMipmappedArrayGetLevel: return "hipMipmappedArrayGetLevel";
854+
case HIP_API_ID_hipMipmappedArrayGetMemoryRequirements: return "hipMipmappedArrayGetMemoryRequirements";
853855
case HIP_API_ID_hipModuleGetFunction: return "hipModuleGetFunction";
854856
case HIP_API_ID_hipModuleGetFunctionCount: return "hipModuleGetFunctionCount";
855857
case HIP_API_ID_hipModuleGetGlobal: return "hipModuleGetGlobal";
@@ -1289,6 +1291,7 @@ static inline uint32_t hipApiIdByName(const char* name) {
12891291
if (strcmp("hipMipmappedArrayCreate", name) == 0) return HIP_API_ID_hipMipmappedArrayCreate;
12901292
if (strcmp("hipMipmappedArrayDestroy", name) == 0) return HIP_API_ID_hipMipmappedArrayDestroy;
12911293
if (strcmp("hipMipmappedArrayGetLevel", name) == 0) return HIP_API_ID_hipMipmappedArrayGetLevel;
1294+
if (strcmp("hipMipmappedArrayGetMemoryRequirements", name) == 0) return HIP_API_ID_hipMipmappedArrayGetMemoryRequirements;
12921295
if (strcmp("hipModuleGetFunction", name) == 0) return HIP_API_ID_hipModuleGetFunction;
12931296
if (strcmp("hipModuleGetFunctionCount", name) == 0) return HIP_API_ID_hipModuleGetFunctionCount;
12941297
if (strcmp("hipModuleGetGlobal", name) == 0) return HIP_API_ID_hipModuleGetGlobal;
@@ -3509,6 +3512,12 @@ typedef struct hip_api_data_s {
35093512
hipMipmappedArray_t hMipMappedArray;
35103513
unsigned int level;
35113514
} hipMipmappedArrayGetLevel;
3515+
struct {
3516+
hipArrayMemoryRequirements* memoryRequirements;
3517+
hipArrayMemoryRequirements memoryRequirements__val;
3518+
hipMipmappedArray_t mipmap;
3519+
hipDevice_t device;
3520+
} hipMipmappedArrayGetMemoryRequirements;
35123521
struct {
35133522
hipFunction_t* function;
35143523
hipFunction_t function__val;
@@ -6174,6 +6183,12 @@ typedef struct hip_api_data_s {
61746183
cb_data.args.hipMipmappedArrayGetLevel.hMipMappedArray = (hipMipmappedArray_t)mipmapped_array_ptr; \
61756184
cb_data.args.hipMipmappedArrayGetLevel.level = (unsigned int)mip_level; \
61766185
};
6186+
// hipMipmappedArrayGetMemoryRequirements[('hipArrayMemoryRequirements*', 'memoryRequirements'), ('hipMipmappedArray_t', 'mipmap'), ('hipDevice_t', 'device')]
6187+
#define INIT_hipMipmappedArrayGetMemoryRequirements_CB_ARGS_DATA(cb_data) { \
6188+
cb_data.args.hipMipmappedArrayGetMemoryRequirements.memoryRequirements = (hipArrayMemoryRequirements*)memoryRequirements; \
6189+
cb_data.args.hipMipmappedArrayGetMemoryRequirements.mipmap = (hipMipmappedArray_t)mipmap; \
6190+
cb_data.args.hipMipmappedArrayGetMemoryRequirements.device = (hipDevice_t)device; \
6191+
};
61776192
// hipModuleGetFunction[('hipFunction_t*', 'function'), ('hipModule_t', 'module'), ('const char*', 'kname')]
61786193
#define INIT_hipModuleGetFunction_CB_ARGS_DATA(cb_data) { \
61796194
cb_data.args.hipModuleGetFunction.function = (hipFunction_t*)hfunc; \
@@ -8094,6 +8109,10 @@ static inline void hipApiArgsInit(hip_api_id_t id, hip_api_data_t* data) {
80948109
case HIP_API_ID_hipMipmappedArrayGetLevel:
80958110
if (data->args.hipMipmappedArrayGetLevel.pLevelArray) data->args.hipMipmappedArrayGetLevel.pLevelArray__val = *(data->args.hipMipmappedArrayGetLevel.pLevelArray);
80968111
break;
8112+
// hipMipmappedArrayGetMemoryRequirements[('hipArrayMemoryRequirements*', 'memoryRequirements'), ('hipMipmappedArray_t', 'mipmap'), ('hipDevice_t', 'device')]
8113+
case HIP_API_ID_hipMipmappedArrayGetMemoryRequirements:
8114+
if (data->args.hipMipmappedArrayGetMemoryRequirements.memoryRequirements) data->args.hipMipmappedArrayGetMemoryRequirements.memoryRequirements__val = *(data->args.hipMipmappedArrayGetMemoryRequirements.memoryRequirements);
8115+
break;
80978116
// hipModuleGetFunction[('hipFunction_t*', 'function'), ('hipModule_t', 'module'), ('const char*', 'kname')]
80988117
case HIP_API_ID_hipModuleGetFunction:
80998118
if (data->args.hipModuleGetFunction.function) data->args.hipModuleGetFunction.function__val = *(data->args.hipModuleGetFunction.function);
@@ -11284,6 +11303,14 @@ static inline const char* hipApiString(hip_api_id_t id, const hip_api_data_t* da
1128411303
oss << ", level="; roctracer::hip_support::detail::operator<<(oss, data->args.hipMipmappedArrayGetLevel.level);
1128511304
oss << ")";
1128611305
break;
11306+
case HIP_API_ID_hipMipmappedArrayGetMemoryRequirements:
11307+
oss << "hipMipmappedArrayGetMemoryRequirements(";
11308+
if (data->args.hipMipmappedArrayGetMemoryRequirements.memoryRequirements == NULL) oss << "memoryRequirements=NULL";
11309+
else { oss << "memoryRequirements="; roctracer::hip_support::detail::operator<<(oss, data->args.hipMipmappedArrayGetMemoryRequirements.memoryRequirements__val); }
11310+
oss << ", mipmap="; roctracer::hip_support::detail::operator<<(oss, data->args.hipMipmappedArrayGetMemoryRequirements.mipmap);
11311+
oss << ", device="; roctracer::hip_support::detail::operator<<(oss, data->args.hipMipmappedArrayGetMemoryRequirements.device);
11312+
oss << ")";
11313+
break;
1128711314
case HIP_API_ID_hipModuleGetFunction:
1128811315
oss << "hipModuleGetFunction(";
1128911316
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
@@ -517,3 +517,4 @@ hipLibraryUnload
517517
hipLibraryGetKernel
518518
hipLibraryGetKernelCount
519519
hipStreamCopyAttributes
520+
hipMipmappedArrayGetMemoryRequirements

projects/clr/hipamd/src/hip_api_trace.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -875,6 +875,8 @@ hipError_t hipLibraryLoadFromFile(hipLibrary_t* library, const char* fileName,
875875
hipError_t hipLibraryUnload(hipLibrary_t library);
876876
hipError_t hipLibraryGetKernel(hipKernel_t* pKernel, hipLibrary_t library, const char* name);
877877
hipError_t hipLibraryGetKernelCount(unsigned int* count, hipLibrary_t library);
878+
hipError_t hipMipmappedArrayGetMemoryRequirements(hipArrayMemoryRequirements* memoryRequirements,
879+
hipMipmappedArray_t mipmap, hipDevice_t device);
878880
} // namespace hip
879881

880882
namespace hip {
@@ -1219,6 +1221,8 @@ void UpdateDispatchTable(HipDispatchTable* ptrDispatchTable) {
12191221
ptrDispatchTable->hipMemsetD8Async_fn = hip::hipMemsetD8Async;
12201222
ptrDispatchTable->hipMipmappedArrayCreate_fn = hip::hipMipmappedArrayCreate;
12211223
ptrDispatchTable->hipMipmappedArrayDestroy_fn = hip::hipMipmappedArrayDestroy;
1224+
ptrDispatchTable->hipMipmappedArrayGetMemoryRequirements_fn =
1225+
hip::hipMipmappedArrayGetMemoryRequirements;
12221226
ptrDispatchTable->hipMipmappedArrayGetLevel_fn = hip::hipMipmappedArrayGetLevel;
12231227
ptrDispatchTable->hipModuleGetFunction_fn = hip::hipModuleGetFunction;
12241228
ptrDispatchTable->hipModuleGetFunctionCount_fn = hip::hipModuleGetFunctionCount;
@@ -2088,13 +2092,14 @@ HIP_ENFORCE_ABI(HipDispatchTable, hipLibraryGetKernel_fn, 499);
20882092
HIP_ENFORCE_ABI(HipDispatchTable, hipLibraryGetKernelCount_fn, 500);
20892093
// HIP_RUNTIME_API_TABLE_STEP_VERSION == 16
20902094
HIP_ENFORCE_ABI(HipDispatchTable, hipStreamCopyAttributes_fn, 501);
2095+
HIP_ENFORCE_ABI(HipDispatchTable, hipMipmappedArrayGetMemoryRequirements_fn, 502);
20912096
// if HIP_ENFORCE_ABI entries are added for each new function pointer in the table, the number below
20922097
// will be +1 of the number in the last HIP_ENFORCE_ABI line. E.g.:
20932098
//
20942099
// HIP_ENFORCE_ABI(<table>, <functor>, 8)
20952100
//
20962101
// HIP_ENFORCE_ABI_VERSIONING(<table>, 9) <- 8 + 1 = 9
2097-
HIP_ENFORCE_ABI_VERSIONING(HipDispatchTable, 502)
2102+
HIP_ENFORCE_ABI_VERSIONING(HipDispatchTable, 503)
20982103

20992104
static_assert(HIP_RUNTIME_API_TABLE_MAJOR_VERSION == 0 && HIP_RUNTIME_API_TABLE_STEP_VERSION == 16,
21002105
"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: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,7 @@ global:
639639
hipLibraryGetKernel;
640640
hipLibraryGetKernelCount;
641641
hipStreamCopyAttributes;
642+
hipMipmappedArrayGetMemoryRequirements;
642643
local:
643644
*;
644-
} hip_7.1;
645+
} hip_7.1;

projects/clr/hipamd/src/hip_memory.cpp

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4264,6 +4264,32 @@ hipError_t ihipMipmappedArrayGetLevel(hipArray_t* level_array_pptr,
42644264
return hipSuccess;
42654265
}
42664266

4267+
hipError_t ihipMipmappedArrayGetMemoryRequirements(hipArrayMemoryRequirements* memoryRequirements,
4268+
hipMipmappedArray_t mipmap,
4269+
hipDevice_t device) {
4270+
if (memoryRequirements == nullptr) {
4271+
return hipErrorInvalidValue;
4272+
}
4273+
if (mipmap == nullptr) {
4274+
return hipErrorInvalidHandle;
4275+
}
4276+
4277+
cl_mem cl_mem_obj = reinterpret_cast<cl_mem>(mipmap->data);
4278+
if (is_valid(cl_mem_obj) == false) {
4279+
return hipErrorInvalidValue;
4280+
}
4281+
4282+
amd::Image* image = as_amd(cl_mem_obj)->asImage();
4283+
if (image == nullptr) {
4284+
return hipErrorInvalidValue;
4285+
}
4286+
4287+
memoryRequirements->alignment = image->getAlignment();
4288+
memoryRequirements->size = image->getSize();
4289+
4290+
return hipSuccess;
4291+
}
4292+
42674293
hipError_t hipMipmappedArrayCreate(hipMipmappedArray_t* mipmapped_array_pptr,
42684294
HIP_ARRAY3D_DESCRIPTOR* mipmapped_array_desc_ptr,
42694295
unsigned int num_mipmap_levels) {
@@ -4288,6 +4314,13 @@ hipError_t hipMipmappedArrayGetLevel(hipArray_t* level_array_pptr,
42884314
HIP_RETURN(ihipMipmappedArrayGetLevel(level_array_pptr, mipmapped_array_ptr, mip_level));
42894315
}
42904316

4317+
hipError_t hipMipmappedArrayGetMemoryRequirements(hipArrayMemoryRequirements* memoryRequirements,
4318+
hipMipmappedArray_t mipmap,
4319+
hipDevice_t device) {
4320+
HIP_INIT_API(hipMipmappedArrayGetMemoryRequirements, memoryRequirements, mipmap, device);
4321+
HIP_RETURN(ihipMipmappedArrayGetMemoryRequirements(memoryRequirements, mipmap, device));
4322+
}
4323+
42914324
hipError_t hipMallocMipmappedArray(hipMipmappedArray_t* mipmappedArray,
42924325
const hipChannelFormatDesc* desc, hipExtent extent,
42934326
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
@@ -2040,4 +2040,9 @@ hipError_t hipLibraryGetKernel(hipKernel_t* pKernel, hipLibrary_t library, const
20402040
hipError_t hipLibraryGetKernelCount(unsigned int *count, hipLibrary_t library) {
20412041
return hip::GetHipDispatchTable()->hipLibraryGetKernelCount_fn(count,
20422042
library);
2043-
}
2043+
}
2044+
hipError_t hipMipmappedArrayGetMemoryRequirements(hipArrayMemoryRequirements* memoryRequirements,
2045+
hipMipmappedArray_t mipmap, hipDevice_t device) {
2046+
return hip::GetHipDispatchTable()->hipMipmappedArrayGetMemoryRequirements_fn(memoryRequirements,
2047+
mipmap, device);
2048+
}

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
tex2DLod.cc
148148
tex2DLayeredLod.cc
149149
tex3DLod.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)