From 57a0d997d363b37c8d27dd9bb6501ddc4b3099cb Mon Sep 17 00:00:00 2001 From: sdashmiz Date: Mon, 4 Apr 2022 16:22:16 -0400 Subject: [PATCH] SWDEV-325711 - add Graph memory APIs skeleton - hipDeviceGet/SetGraphMemAttr - hipDeviceGraphMemTrim - there is no memory pool for graphs currently Signed-off-by: sdashmiz Change-Id: I11db76ea7ea1c7732175fc93264448052357e8dc [ROCm/clr commit: e8194dca76e4946e0cfb6859d1ad97f162c39d3a] --- .../include/hip/amd_detail/hip_prof_str.h | 68 ++++++++++++++++++- .../nvidia_detail/nvidia_hip_runtime_api.h | 13 ++++ projects/clr/hipamd/src/amdhip.def | 3 + projects/clr/hipamd/src/hip_graph.cpp | 53 +++++++++++++++ projects/clr/hipamd/src/hip_hcc.def.in | 3 + projects/clr/hipamd/src/hip_hcc.map.in | 3 + 6 files changed, 142 insertions(+), 1 deletion(-) diff --git a/projects/clr/hipamd/include/hip/amd_detail/hip_prof_str.h b/projects/clr/hipamd/include/hip/amd_detail/hip_prof_str.h index f49cc7fbc8..f1e129e083 100644 --- a/projects/clr/hipamd/include/hip/amd_detail/hip_prof_str.h +++ b/projects/clr/hipamd/include/hip/amd_detail/hip_prof_str.h @@ -344,7 +344,10 @@ enum hip_api_id_t { HIP_API_ID_hipMemRetainAllocationHandle = 331, HIP_API_ID_hipMemSetAccess = 332, HIP_API_ID_hipMemUnmap = 333, - HIP_API_ID_LAST = 333, + HIP_API_ID_hipDeviceSetGraphMemAttribute = 334, + HIP_API_ID_hipDeviceGetGraphMemAttribute = 335, + HIP_API_ID_hipDeviceGraphMemTrim = 336, + HIP_API_ID_LAST = 336, HIP_API_ID_hipArray3DGetDescriptor = HIP_API_ID_NONE, HIP_API_ID_hipArrayGetDescriptor = HIP_API_ID_NONE, @@ -554,6 +557,9 @@ static inline const char* hip_api_name(const uint32_t id) { case HIP_API_ID_hipGraphicsSubResourceGetMappedArray: return "hipGraphicsSubResourceGetMappedArray"; case HIP_API_ID_hipGraphicsUnmapResources: return "hipGraphicsUnmapResources"; case HIP_API_ID_hipGraphicsUnregisterResource: return "hipGraphicsUnregisterResource"; + case HIP_API_ID_hipDeviceSetGraphMemAttribute: return "hipDeviceSetGraphMemAttribute"; + case HIP_API_ID_hipDeviceGetGraphMemAttribute: return "hipDeviceGetGraphMemAttribute"; + case HIP_API_ID_hipDeviceGraphMemTrim: return "hipDeviceGraphMemTrim"; case HIP_API_ID_hipHccModuleLaunchKernel: return "hipHccModuleLaunchKernel"; case HIP_API_ID_hipHostAlloc: return "hipHostAlloc"; case HIP_API_ID_hipHostFree: return "hipHostFree"; @@ -889,6 +895,9 @@ static inline uint32_t hipApiIdByName(const char* name) { if (strcmp("hipGraphicsResourceGetMappedPointer", name) == 0) return HIP_API_ID_hipGraphicsResourceGetMappedPointer; if (strcmp("hipGraphicsSubResourceGetMappedArray", name) == 0) return HIP_API_ID_hipGraphicsSubResourceGetMappedArray; if (strcmp("hipGraphicsUnmapResources", name) == 0) return HIP_API_ID_hipGraphicsUnmapResources; + if (strcmp("hipDeviceGetGraphMemAttribute", name) == 0) return HIP_API_ID_hipDeviceGetGraphMemAttribute; + if (strcmp("hipDeviceSetGraphMemAttribute", name) == 0) return HIP_API_ID_hipDeviceSetGraphMemAttribute; + if (strcmp("hipDeviceGraphMemTrim", name) == 0) return HIP_API_ID_hipDeviceGraphMemTrim; if (strcmp("hipGraphicsUnregisterResource", name) == 0) return HIP_API_ID_hipGraphicsUnregisterResource; if (strcmp("hipHccModuleLaunchKernel", name) == 0) return HIP_API_ID_hipHccModuleLaunchKernel; if (strcmp("hipHostAlloc", name) == 0) return HIP_API_ID_hipHostAlloc; @@ -1930,6 +1939,19 @@ typedef struct hip_api_data_s { size_t size__val; hipGraphicsResource_t resource; } hipGraphicsResourceGetMappedPointer; + struct { + int device; + hipGraphMemAttributeType attr; + void* value; + } hipDeviceGetGraphMemAttribute; + struct { + int device; + hipGraphMemAttributeType attr; + void* value; + } hipDeviceSetGraphMemAttribute; + struct { + int device; + } hipDeviceGraphMemTrim; struct { hipArray_t* array; hipArray_t array__val; @@ -3903,6 +3925,22 @@ typedef struct hip_api_data_s { #define INIT_hipGraphicsUnregisterResource_CB_ARGS_DATA(cb_data) { \ cb_data.args.hipGraphicsUnregisterResource.resource = (hipGraphicsResource_t)resource; \ }; +// hipDeviceGetGraphMemAttribute[('int', 'device'), ('hipGraphMemAttributeType', 'attr'), ('void*', 'value')] +#define INIT_hipDeviceGetGraphMemAttribute_CB_ARGS_DATA(cb_data) { \ + cb_data.args.hipDeviceGetGraphMemAttribute.device = (int)device; \ + cb_data.args.hipDeviceGetGraphMemAttribute.attr = (hipGraphMemAttributeType)attr; \ + cb_data.args.hipDeviceGetGraphMemAttribute.value = (void*)value; \ +}; +// hipDeviceSetGraphMemAttribute[('int', 'device'), ('hipGraphMemAttributeType', 'attr'), ('void*', 'value')] +#define INIT_hipDeviceSetGraphMemAttribute_CB_ARGS_DATA(cb_data) { \ + cb_data.args.hipDeviceSetGraphMemAttribute.device = (int)device; \ + cb_data.args.hipDeviceSetGraphMemAttribute.attr = (hipGraphMemAttributeType)attr; \ + cb_data.args.hipDeviceSetGraphMemAttribute.value = (void*)value; \ +}; +// hipDeviceGraphMemTrim[('int', 'device')] +#define INIT_hipDeviceGraphMemTrim_CB_ARGS_DATA(cb_data) { \ + cb_data.args.hipDeviceGraphMemTrim.device = (int)device; \ +}; // hipHccModuleLaunchKernel[('hipFunction_t', 'f'), ('unsigned int', 'globalWorkSizeX'), ('unsigned int', 'globalWorkSizeY'), ('unsigned int', 'globalWorkSizeZ'), ('unsigned int', 'blockDimX'), ('unsigned int', 'blockDimY'), ('unsigned int', 'blockDimZ'), ('size_t', 'sharedMemBytes'), ('hipStream_t', 'hStream'), ('void**', 'kernelParams'), ('void**', 'extra'), ('hipEvent_t', 'startEvent'), ('hipEvent_t', 'stopEvent')] #define INIT_hipHccModuleLaunchKernel_CB_ARGS_DATA(cb_data) { \ cb_data.args.hipHccModuleLaunchKernel.f = (hipFunction_t)f; \ @@ -5715,6 +5753,15 @@ static inline void hipApiArgsInit(hip_api_id_t id, hip_api_data_t* data) { // hipGraphicsUnregisterResource[('hipGraphicsResource_t', 'resource')] case HIP_API_ID_hipGraphicsUnregisterResource: break; +// hipDeviceSetGraphMemAttribute[('int', 'device'), ('hipGraphMemAttributeType', 'attr'), ('void*', 'value')] + case HIP_API_ID_hipDeviceSetGraphMemAttribute: + break; +// hipDeviceGetGraphMemAttribute[('int', 'device'), ('hipGraphMemAttributeType', 'attr'), ('void*', 'value')] + case HIP_API_ID_hipDeviceGetGraphMemAttribute: + break; +// hipDeviceGraphMemTrim [('int', 'device')] + case HIP_API_ID_hipDeviceGraphMemTrim: + break; // hipHccModuleLaunchKernel[('hipFunction_t', 'f'), ('unsigned int', 'globalWorkSizeX'), ('unsigned int', 'globalWorkSizeY'), ('unsigned int', 'globalWorkSizeZ'), ('unsigned int', 'blockDimX'), ('unsigned int', 'blockDimY'), ('unsigned int', 'blockDimZ'), ('size_t', 'sharedMemBytes'), ('hipStream_t', 'hStream'), ('void**', 'kernelParams'), ('void**', 'extra'), ('hipEvent_t', 'startEvent'), ('hipEvent_t', 'stopEvent')] case HIP_API_ID_hipHccModuleLaunchKernel: if (data->args.hipHccModuleLaunchKernel.kernelParams) data->args.hipHccModuleLaunchKernel.kernelParams__val = *(data->args.hipHccModuleLaunchKernel.kernelParams); @@ -7533,6 +7580,25 @@ static inline const char* hipApiString(hip_api_id_t id, const hip_api_data_t* da oss << ", numDependencies=" << data->args.hipGraphRemoveDependencies.numDependencies; oss << ")"; break; + case HIP_API_ID_hipDeviceSetGraphMemAttribute: + oss << "hipDeviceSetGraphMemAttribute("; + oss << "device=" << data->args.hipDeviceSetGraphMemAttribute.device; + oss << ", attr=" << data->args.hipDeviceSetGraphMemAttribute.attr; + oss << ", value=" << data->args.hipDeviceSetGraphMemAttribute.value; + oss << ")"; + break; + case HIP_API_ID_hipDeviceGraphMemTrim: + oss << "hipDeviceGraphMemTrim("; + oss << "device=" << data->args.hipDeviceGraphMemTrim.device; + oss << ")"; + break; + case HIP_API_ID_hipDeviceGetGraphMemAttribute: + oss << "hipDeviceGetGraphMemAttribute("; + oss << "device=" << data->args.hipDeviceGetGraphMemAttribute.device; + oss << ", attr=" << data->args.hipDeviceGetGraphMemAttribute.attr; + oss << ", value=" << data->args.hipDeviceGetGraphMemAttribute.value; + oss << ")"; + break; case HIP_API_ID_hipGraphicsGLRegisterBuffer: oss << "hipGraphicsGLRegisterBuffer("; if (data->args.hipGraphicsGLRegisterBuffer.resource == NULL) oss << "resource=NULL"; diff --git a/projects/clr/hipamd/include/hip/nvidia_detail/nvidia_hip_runtime_api.h b/projects/clr/hipamd/include/hip/nvidia_detail/nvidia_hip_runtime_api.h index b9e095a676..008d734b50 100644 --- a/projects/clr/hipamd/include/hip/nvidia_detail/nvidia_hip_runtime_api.h +++ b/projects/clr/hipamd/include/hip/nvidia_detail/nvidia_hip_runtime_api.h @@ -1133,6 +1133,7 @@ typedef enum cudaStreamCaptureStatus hipStreamCaptureStatus; typedef union cudaKernelNodeAttrValue hipKernelNodeAttrValue; typedef enum cudaKernelNodeAttrID hipKernelNodeAttrID; +typedef enum cudaGraphMemAttributeType hipGraphMemAttributeType; #if CUDA_VERSION >= CUDA_11030 typedef enum cudaStreamUpdateCaptureDependenciesFlags hipStreamUpdateCaptureDependenciesFlags; @@ -3018,6 +3019,18 @@ inline static hipError_t hipGraphExecEventWaitNodeSetEvent(hipGraphExec_t hGraph hipGraphNode_t hNode, hipEvent_t event) { return hipCUDAErrorTohipError(cudaGraphExecEventWaitNodeSetEvent(hGraphExec, hNode, event)); } + +inline static hipError_t hipDeviceGetGraphMemAttribute(int device, hipGraphMemAttributeType attr, void* value) { + return hipCUDAErrorTohipError(cudaDeviceGetGraphMemAttribute(device, attr, value)); +} + +inline static hipError_t hipDeviceSetGraphMemAttribute(int device, hipGraphMemAttributeType attr, void* value) { + return hipCUDAErrorTohipError(cudaDeviceSetGraphMemAttribute(device, attr, value)); +} + +inline static hipError_t hipDeviceGraphMemTrim(int device) { + return hipCUDAErrorTohipError(cudaDeviceGraphMemTrim(device)); +} #endif inline static hipError_t hipGraphHostNodeSetParams(hipGraphNode_t node, diff --git a/projects/clr/hipamd/src/amdhip.def b/projects/clr/hipamd/src/amdhip.def index ffeb73a351..ce5e7f020f 100644 --- a/projects/clr/hipamd/src/amdhip.def +++ b/projects/clr/hipamd/src/amdhip.def @@ -361,6 +361,9 @@ hipGraphExecHostNodeSetParams hipGraphExecUpdate hipGraphInstantiateWithFlags hipGraphExecMemsetNodeSetParams +hipDeviceGetGraphMemAttribute +hipDeviceSetGraphMemAttribute +hipDeviceGraphMemTrim amd_dbgapi_get_build_name amd_dbgapi_get_git_hash amd_dbgapi_get_build_id diff --git a/projects/clr/hipamd/src/hip_graph.cpp b/projects/clr/hipamd/src/hip_graph.cpp index 8367d54e1e..1e03177518 100644 --- a/projects/clr/hipamd/src/hip_graph.cpp +++ b/projects/clr/hipamd/src/hip_graph.cpp @@ -1836,3 +1836,56 @@ hipError_t hipGraphExecUpdate(hipGraphExec_t hGraphExec, hipGraph_t hGraph, *updateResult_out = hipGraphExecUpdateSuccess; HIP_RETURN(hipSuccess); } + +hipError_t hipDeviceGetGraphMemAttribute(int device, hipGraphMemAttributeType attr, void* value) { + HIP_INIT_API(hipDeviceGetGraphMemAttribute, device, attr, value); + if ((static_cast(device) >= g_devices.size()) || device < 0 || value == nullptr) { + HIP_RETURN(hipErrorInvalidDevice); + } + // later use this to access memory pool + auto* deviceHandle = g_devices[device]->devices()[0]; + switch (attr) { + case hipGraphMemAttrUsedMemCurrent: + *reinterpret_cast(value) = 0; + break; + case hipGraphMemAttrUsedMemHigh: + *reinterpret_cast(value) = 0; + break; + case hipGraphMemAttrReservedMemCurrent: + *reinterpret_cast(value) = 0; + break; + case hipGraphMemAttrReservedMemHigh: + *reinterpret_cast(value) = 0; + break; + default: + return HIP_RETURN(hipErrorInvalidValue); + } + return HIP_RETURN(hipSuccess); +} + +hipError_t hipDeviceSetGraphMemAttribute(int device, hipGraphMemAttributeType attr, void* value) { + HIP_INIT_API(hipDeviceSetGraphMemAttribute, device, attr, value); + if ((static_cast(device) >= g_devices.size()) || device < 0 || value == nullptr) { + HIP_RETURN(hipErrorInvalidDevice); + } + // later use this to access memory pool + auto* deviceHandle = g_devices[device]->devices()[0]; + switch (attr) { + case hipGraphMemAttrUsedMemHigh: + break; + case hipGraphMemAttrReservedMemHigh: + break; + default: + return HIP_RETURN(hipErrorInvalidValue); + } + return HIP_RETURN(hipSuccess); +} + +hipError_t hipDeviceGraphMemTrim(int device) { + HIP_INIT_API(hipDeviceGraphMemTrim, device); + if ((static_cast(device) >= g_devices.size()) || device < 0) { + HIP_RETURN(hipErrorInvalidDevice); + } + // not implemented yet + return HIP_RETURN(hipSuccess); +} \ No newline at end of file diff --git a/projects/clr/hipamd/src/hip_hcc.def.in b/projects/clr/hipamd/src/hip_hcc.def.in index 02ac30a13e..8692258922 100644 --- a/projects/clr/hipamd/src/hip_hcc.def.in +++ b/projects/clr/hipamd/src/hip_hcc.def.in @@ -372,6 +372,9 @@ hipGraphExecHostNodeSetParams hipGraphExecUpdate hipGraphInstantiateWithFlags hipGraphExecMemsetNodeSetParams +hipDeviceGetGraphMemAttribute +hipDeviceSetGraphMemAttribute +hipDeviceGraphMemTrim amd_dbgapi_get_build_name amd_dbgapi_get_git_hash amd_dbgapi_get_build_id diff --git a/projects/clr/hipamd/src/hip_hcc.map.in b/projects/clr/hipamd/src/hip_hcc.map.in index d31ace338f..1cdbc92124 100644 --- a/projects/clr/hipamd/src/hip_hcc.map.in +++ b/projects/clr/hipamd/src/hip_hcc.map.in @@ -382,6 +382,9 @@ global: hipGraphExecUpdate; hipGraphInstantiateWithFlags; hipGraphExecMemsetNodeSetParams; + hipDeviceGetGraphMemAttribute; + hipDeviceSetGraphMemAttribute; + hipDeviceGraphMemTrim; amd_dbgapi_get_build_name; amd_dbgapi_get_git_hash; amd_dbgapi_get_build_id;