Skip to content

Commit e3b8754

Browse files
committed
SWDEV-477584 - Match hipGetLastError behavior with CUDA using env var
Change-Id: I4c5acff180ae904028f7c5fdf4e109ffd1f0c4ef
1 parent 17e7b7c commit e3b8754

File tree

6 files changed

+46
-14
lines changed

6 files changed

+46
-14
lines changed

CHANGELOG.md

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,12 @@
22

33
Full documentation for HIP is available at [rocm.docs.amd.com](https://rocm.docs.amd.com/projects/HIP/en/latest/index.html)
44

5+
## HIP 6.4 (For ROCm 6.4)
6+
7+
### Changed
8+
* Added new environment variable
9+
- `DEBUG_HIP_7_PREVIEW` This is used for enabling the backward incompatible changes before the next major ROCm release 7.0. By default this is set to 0. Users can set this variable to 0x1, to match the behavior of hipGetLastError with its corresponding CUDA API.
10+
511
## HIP 6.3 for ROCm 6.3
612

713
### Changed

hipamd/src/hip_event.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ hipError_t hipEventSynchronize(hipEvent_t event) {
439439
hip::Stream* s = reinterpret_cast<hip::Stream*>(e->GetCaptureStream());
440440
if ((s != nullptr) && (s->GetCaptureStatus() == hipStreamCaptureStatusActive)) {
441441
s->SetCaptureStatus(hipStreamCaptureStatusInvalidated);
442-
return HIP_RETURN(hipErrorCapturedEvent);
442+
HIP_RETURN(hipErrorCapturedEvent);
443443
}
444444
if (hip::Stream::StreamCaptureOngoing(e->GetCaptureStream()) == true) {
445445
HIP_RETURN(hipErrorStreamCaptureUnsupported);
@@ -460,7 +460,7 @@ hipError_t ihipEventQuery(hipEvent_t event) {
460460
hip::Stream* s = reinterpret_cast<hip::Stream*>(e->GetCaptureStream());
461461
if ((s != nullptr) && (s->GetCaptureStatus() == hipStreamCaptureStatusActive)) {
462462
s->SetCaptureStatus(hipStreamCaptureStatusInvalidated);
463-
return HIP_RETURN(hipErrorCapturedEvent);
463+
HIP_RETURN(hipErrorCapturedEvent);
464464
}
465465
return e->query();
466466
}

hipamd/src/hip_internal.hpp

Lines changed: 28 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -164,19 +164,36 @@ const char* ihipGetErrorName(hipError_t hip_error);
164164
HIP_RETURN(hipErrorNoDevice); \
165165
}
166166

167-
#define HIP_INIT_API_NO_RETURN(cid, ...) \
167+
#define HIP_INIT_API_NO_RETURN(cid, ...) \
168168
HIP_INIT_API_INTERNAL(1, cid, __VA_ARGS__)
169169

170170
#define HIP_RETURN_DURATION(ret, ...) \
171-
hip::tls.last_error_ = ret; \
171+
hip::tls.last_command_error_ = ret; \
172+
if (DEBUG_HIP_7_PREVIEW & amd::CHANGE_HIP_GET_LAST_ERROR) { \
173+
if (hip::tls.last_command_error_ != hipSuccess && \
174+
hip::tls.last_command_error_ != hipErrorNotReady) { \
175+
hip::tls.last_error_ = hip::tls.last_command_error_; \
176+
} \
177+
} else { \
178+
hip::tls.last_error_ = hip::tls.last_command_error_; \
179+
} \
172180
HIPPrintDuration(amd::LOG_INFO, amd::LOG_API, &startTimeUs, "%s: Returned %s : %s", __func__, \
173-
hip::ihipGetErrorName(hip::tls.last_error_), ToString(__VA_ARGS__).c_str()); \
174-
return hip::tls.last_error_;
175-
176-
#define HIP_RETURN(ret, ...) \
177-
hip::tls.last_error_ = ret; \
178-
HIP_ERROR_PRINT(hip::tls.last_error_, __VA_ARGS__) \
179-
return hip::tls.last_error_;
181+
hip::ihipGetErrorName(hip::tls.last_command_error_), \
182+
ToString(__VA_ARGS__).c_str()); \
183+
return hip::tls.last_command_error_;
184+
185+
#define HIP_RETURN(ret, ...) \
186+
hip::tls.last_command_error_ = ret; \
187+
if (DEBUG_HIP_7_PREVIEW & amd::CHANGE_HIP_GET_LAST_ERROR) { \
188+
if (hip::tls.last_command_error_ != hipSuccess && \
189+
hip::tls.last_command_error_ != hipErrorNotReady) { \
190+
hip::tls.last_error_ = hip::tls.last_command_error_; \
191+
} \
192+
} else { \
193+
hip::tls.last_error_ = hip::tls.last_command_error_; \
194+
} \
195+
HIP_ERROR_PRINT(hip::tls.last_command_error_, __VA_ARGS__) \
196+
return hip::tls.last_command_error_;
180197

181198
#define HIP_RETURN_ONFAIL(func) \
182199
do { \
@@ -610,14 +627,15 @@ class stream_per_thread {
610627
public:
611628
Device* device_;
612629
std::stack<Device*> ctxt_stack_;
613-
hipError_t last_error_;
630+
hipError_t last_error_, last_command_error_;
614631
std::vector<hip::Stream*> capture_streams_;
615632
hipStreamCaptureMode stream_capture_mode_;
616633
std::stack<ihipExec_t> exec_stack_;
617634
stream_per_thread stream_per_thread_obj_;
618635

619636
TlsAggregator(): device_(nullptr),
620637
last_error_(hipSuccess),
638+
last_command_error_(hipSuccess),
621639
stream_capture_mode_(hipStreamCaptureModeGlobal) {
622640
}
623641
~TlsAggregator() {

hipamd/src/hip_memory.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4621,7 +4621,7 @@ hipError_t hipExternalMemoryGetMappedMipmappedArray(
46214621
hip::getNumChannels(mipmapDesc->formatDesc),
46224622
mipmapDesc->flags};
46234623
if (!hip::CheckArrayFormat(mipmapDesc->formatDesc)) {
4624-
return HIP_RETURN(hipErrorInvalidValue);
4624+
HIP_RETURN(hipErrorInvalidValue);
46254625
}
46264626

46274627
HIP_RETURN(ihipMipmapArrayCreate(mipmap, &allocateArray, mipmapDesc->numLevels,

rocclr/utils/debug.hpp

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ enum LogMask {
6868
LOG_ALWAYS = -1 //!< (0xFFFFFFFF) Log always even mask flag is zero
6969
};
7070

71+
// Flags to support backward incompatible changes before 7.0
72+
enum BreakingHipChange7 {
73+
CHANGE_HIP_GET_LAST_ERROR = 1, //!< (0x1) HIP_GET_LAST_ERROR
74+
};
75+
7176
//! \brief log file output
7277
extern FILE* outFile;
7378

rocclr/utils/flags.hpp

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -266,9 +266,12 @@ release(bool, DEBUG_CLR_SYSMEM_POOL, false, \
266266
release(bool, DEBUG_HIP_KERNARG_COPY_OPT, true, \
267267
"Enable/Disable multiple kern arg copies") \
268268
release(bool, DEBUG_CLR_USE_STDMUTEX_IN_AMD_MONITOR, false, \
269-
"Use std::mutex in amd::monotor") \
269+
"Use std::mutex in amd::monitor") \
270270
release(bool, DEBUG_CLR_KERNARG_HDP_FLUSH_WA, false, \
271271
"Toggle kernel arg copy workaround") \
272+
release(uint, DEBUG_HIP_7_PREVIEW, 0, \
273+
"Enables specific backward incompatible changes support before 7.0," \
274+
"using the mask. By default the changes are disabled and is set to 0")\
272275

273276
namespace amd {
274277

0 commit comments

Comments
 (0)