From 8ea2da75d229b1b03c2b0836661dcf50df30a030 Mon Sep 17 00:00:00 2001 From: Sarbojit Sarkar Date: Thu, 7 May 2020 03:57:58 -0400 Subject: [PATCH] Enabling hipGetDeviceFlags required in [SWDEV-229170] Change-Id: I998d37e5847f9651345554bada86df6fce86d1eb [ROCm/clr commit: 94699a7a6f61afdf3fb6d945c932474513cc36bb] --- .../hipamd/include/hip/hcc_detail/hip_runtime_api.h | 8 ++++++++ .../hipamd/include/hip/nvcc_detail/hip_runtime_api.h | 4 ++++ projects/clr/hipamd/rocclr/hip_device_runtime.cpp | 10 ++++++++-- projects/clr/hipamd/rocclr/hip_hcc.def.in | 1 + projects/clr/hipamd/rocclr/hip_hcc.map.in | 1 + projects/clr/hipamd/rocclr/hip_internal.hpp | 8 ++++++-- 6 files changed, 28 insertions(+), 4 deletions(-) diff --git a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h index 7363f904ed..17c34b0ad5 100644 --- a/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h +++ b/projects/clr/hipamd/include/hip/hcc_detail/hip_runtime_api.h @@ -506,6 +506,14 @@ hipError_t hipFuncSetCacheConfig(const void* func, hipFuncCache_t config); */ hipError_t hipDeviceGetSharedMemConfig(hipSharedMemConfig* pConfig); +/** + * @brief Gets the flags set for current device + * + * @param [out] flags + * + * @returns #hipSuccess, #hipErrorInvalidDevice, #hipErrorInvalidValue + */ +hipError_t hipGetDeviceFlags(unsigned *flags); /** * @brief The bank width of shared memory on current device is set diff --git a/projects/clr/hipamd/include/hip/nvcc_detail/hip_runtime_api.h b/projects/clr/hipamd/include/hip/nvcc_detail/hip_runtime_api.h index 3890028950..23b8a0619d 100644 --- a/projects/clr/hipamd/include/hip/nvcc_detail/hip_runtime_api.h +++ b/projects/clr/hipamd/include/hip/nvcc_detail/hip_runtime_api.h @@ -1511,6 +1511,10 @@ inline static hipError_t hipProfilerStart() { return hipCUDAErrorTohipError(cuda inline static hipError_t hipProfilerStop() { return hipCUDAErrorTohipError(cudaProfilerStop()); } +inline static hipError_t hipGetDeviceFlags(unsigned int* flags) { + return hipCUDAErrorTohipError(cudaGetDeviceFlags(flags)); +} + inline static hipError_t hipSetDeviceFlags(unsigned int flags) { return hipCUDAErrorTohipError(cudaSetDeviceFlags(flags)); } diff --git a/projects/clr/hipamd/rocclr/hip_device_runtime.cpp b/projects/clr/hipamd/rocclr/hip_device_runtime.cpp index 86a1590533..531f35c732 100644 --- a/projects/clr/hipamd/rocclr/hip_device_runtime.cpp +++ b/projects/clr/hipamd/rocclr/hip_device_runtime.cpp @@ -471,7 +471,12 @@ hipError_t hipGetDeviceCount ( int* count ) { } hipError_t hipGetDeviceFlags ( unsigned int* flags ) { - HIP_RETURN(hipErrorNotSupported); + HIP_INIT_API(hipGetDeviceFlags, flags); + if (flags == nullptr) { + HIP_RETURN(hipErrorInvalidValue); + } + *flags = hip::getCurrentDevice()->getFlags(); + HIP_RETURN(hipSuccess); } hipError_t hipIpcGetEventHandle ( hipIpcEventHandle_t* handle, hipEvent_t event ) { @@ -531,7 +536,8 @@ hipError_t hipSetDeviceFlags ( unsigned int flags ) { default: break; } - + hip::getCurrentDevice()->setFlags(flags & hipDeviceScheduleMask); + HIP_RETURN(hipSuccess); } diff --git a/projects/clr/hipamd/rocclr/hip_hcc.def.in b/projects/clr/hipamd/rocclr/hip_hcc.def.in index 238d7fe02a..579608e685 100755 --- a/projects/clr/hipamd/rocclr/hip_hcc.def.in +++ b/projects/clr/hipamd/rocclr/hip_hcc.def.in @@ -149,6 +149,7 @@ hipPointerGetAttributes hipProfilerStart hipProfilerStop hipRuntimeGetVersion +hipGetDeviceFlags hipSetDevice hipSetDeviceFlags hipStreamAddCallback diff --git a/projects/clr/hipamd/rocclr/hip_hcc.map.in b/projects/clr/hipamd/rocclr/hip_hcc.map.in index f2491cd283..19da8a6991 100755 --- a/projects/clr/hipamd/rocclr/hip_hcc.map.in +++ b/projects/clr/hipamd/rocclr/hip_hcc.map.in @@ -149,6 +149,7 @@ global: hipProfilerStart; hipProfilerStop; hipRuntimeGetVersion; + hipGetDeviceFlags; hipSetDevice; hipSetDeviceFlags; hipStreamAddCallback; diff --git a/projects/clr/hipamd/rocclr/hip_internal.hpp b/projects/clr/hipamd/rocclr/hip_internal.hpp index 4a40018745..643a43341b 100755 --- a/projects/clr/hipamd/rocclr/hip_internal.hpp +++ b/projects/clr/hipamd/rocclr/hip_internal.hpp @@ -119,12 +119,14 @@ namespace hip { int deviceId_; /// ROCclr host queue for default streams Stream null_stream_; - //Maintain list of user enabled peers + /// Store device flags + unsigned int flags_; + /// Maintain list of user enabled peers std::list userEnabledPeers; public: Device(amd::Context* ctx, int devId): - context_(ctx), deviceId_(devId), null_stream_(this, amd::CommandQueue::Priority::Normal, 0, true) + context_(ctx), deviceId_(devId), null_stream_(this, amd::CommandQueue::Priority::Normal, 0, true), flags_(hipDeviceScheduleSpin) { assert(ctx != nullptr); } ~Device() {} @@ -152,6 +154,8 @@ namespace hip { return hipErrorPeerAccessNotEnabled; } } + unsigned int getFlags() const { return flags_; } + void setFlags(unsigned int flags) { flags_ = flags; } amd::HostQueue* NullStream(bool skip_alloc = false); };