From 4313686d6ee5cb28698f0b0b1a441212b8e78b01 Mon Sep 17 00:00:00 2001 From: Ben Sander Date: Tue, 21 Nov 2017 15:41:15 -0600 Subject: [PATCH 1/2] Fix warning from default cppchek. --- src/hip_hcc_internal.h | 6 +++--- src/hip_memory.cpp | 3 ++- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/src/hip_hcc_internal.h b/src/hip_hcc_internal.h index 3fd09630d9..69434a6327 100644 --- a/src/hip_hcc_internal.h +++ b/src/hip_hcc_internal.h @@ -248,8 +248,8 @@ static const DbName dbName [] = #if COMPILE_HIP_DB #define tprintf(trace_level, ...) {\ if (HIP_DB & (1<<(trace_level))) {\ - char msgStr[2000];\ - snprintf(msgStr, 2000, __VA_ARGS__);\ + char msgStr[1000];\ + snprintf(msgStr, sizeof(msgStr), __VA_ARGS__);\ fprintf (stderr, " %ship-%s tid:%d:%s%s", dbName[trace_level]._color, dbName[trace_level]._shortName, tls_tidInfo.tid(), msgStr, KNRM); \ }\ } @@ -269,7 +269,7 @@ extern uint64_t recordApiTrace(std::string *fullStr, const std::string &apiStr); #if COMPILE_HIP_ATP_MARKER || (COMPILE_HIP_TRACE_API & 0x1) #define API_TRACE(forceTrace, ...)\ -uint64_t hipApiStartTick;\ +uint64_t hipApiStartTick=0;\ {\ tls_tidInfo.incApiSeqNum();\ if (forceTrace || (HIP_PROFILE_API || (COMPILE_HIP_DB && (HIP_TRACE_API & (1<psize = psize; From 9bba97fdcc825398ba443942b0c0375aa0bba329 Mon Sep 17 00:00:00 2001 From: Ben Sander Date: Tue, 21 Nov 2017 16:44:28 -0600 Subject: [PATCH 2/2] Fix some cppcheck style issues. --- src/hip_device.cpp | 6 +++--- src/hip_hcc.cpp | 2 ++ src/hip_hcc_internal.h | 11 ++++++----- src/hip_memory.cpp | 26 +++++++++++++------------- 4 files changed, 24 insertions(+), 21 deletions(-) diff --git a/src/hip_device.cpp b/src/hip_device.cpp index 521b56b0e9..4f08d49bf3 100644 --- a/src/hip_device.cpp +++ b/src/hip_device.cpp @@ -446,14 +446,14 @@ hipError_t hipChooseDevice( int* device, const hipDeviceProp_t* prop ) { HIP_INIT_API(device,prop); hipDeviceProp_t tempProp; - int deviceCount; - int inPropCount = 0; - int matchedPropCount = 0; hipError_t e = hipSuccess; if((device == NULL) || (prop == NULL)) { e = hipErrorInvalidValue; } if(e == hipSuccess) { + int deviceCount; + int inPropCount = 0; + int matchedPropCount = 0; ihipGetDeviceCount( &deviceCount ); *device = 0; for (int i = 0; i < deviceCount; i++) { diff --git a/src/hip_hcc.cpp b/src/hip_hcc.cpp index 2eff57f18b..f15a0eb1d8 100644 --- a/src/hip_hcc.cpp +++ b/src/hip_hcc.cpp @@ -779,6 +779,8 @@ hipError_t ihipDevice_t::initProperties(hipDeviceProp_t* prop) // Get agent name err = hsa_agent_get_info(_hsaAgent, (hsa_agent_info_t)HSA_AMD_AGENT_INFO_PRODUCT_NAME, &(prop->name)); + DeviceErrorCheck(err); + char archName[256]; err = hsa_agent_get_info(_hsaAgent, HSA_AGENT_INFO_NAME, &archName); diff --git a/src/hip_hcc_internal.h b/src/hip_hcc_internal.h index 69434a6327..3fbd3cfacc 100644 --- a/src/hip_hcc_internal.h +++ b/src/hip_hcc_internal.h @@ -339,7 +339,7 @@ uint64_t hipApiStartTick=0;\ class ihipException : public std::exception { public: - ihipException(hipError_t e) : _code(e) {}; + explicit ihipException(hipError_t e) : _code(e) {}; hipError_t _code; }; @@ -669,7 +669,7 @@ template class ihipEventCriticalBase_t : LockedBase { public: - ihipEventCriticalBase_t(const ihipEvent_t *parentEvent) : + explicit ihipEventCriticalBase_t(const ihipEvent_t *parentEvent) : _parent(parentEvent) {} ~ihipEventCriticalBase_t() {}; @@ -690,7 +690,7 @@ typedef LockedAccessor LockedAccessor_EventCrit_t; // internal hip event structure. class ihipEvent_t { public: - ihipEvent_t(unsigned flags); + explicit ihipEvent_t(unsigned flags); void attachToCompletionFuture(const hc::completion_future *cf, hipStream_t stream, ihipEventType_t eventType); std::pair refreshEventStatus(); // returns pair @@ -720,8 +720,9 @@ template class ihipDeviceCriticalBase_t : LockedBase { public: - ihipDeviceCriticalBase_t(ihipDevice_t *parentDevice) : - _parent(parentDevice) + explicit ihipDeviceCriticalBase_t(ihipDevice_t *parentDevice) : + _parent(parentDevice), + _ctxCount(0) { }; diff --git a/src/hip_memory.cpp b/src/hip_memory.cpp index 8ed5e600e2..cedc3c59b5 100644 --- a/src/hip_memory.cpp +++ b/src/hip_memory.cpp @@ -44,7 +44,7 @@ hipError_t memcpyAsync (void* dst, const void* src, size_t sizeBytes, hipMemcpyK try { stream->locked_copyAsync(dst, src, sizeBytes, kind); } - catch (ihipException ex) { + catch (ihipException &ex) { e = ex._code; } } else { @@ -928,7 +928,7 @@ hipError_t hipMemcpyToSymbolAsync(const void* symbolName, const void *src, size_ try { stream->lockedSymbolCopyAsync(acc, dst, (void*)src, count, offset, kind); } - catch (ihipException ex) { + catch (ihipException &ex) { e = ex._code; } } else { @@ -968,7 +968,7 @@ hipError_t hipMemcpyFromSymbolAsync(void* dst, const void* symbolName, size_t co try { stream->lockedSymbolCopyAsync(acc, dst, src, count, offset, kind); } - catch (ihipException ex) { + catch (ihipException &ex) { e = ex._code; } } else { @@ -993,7 +993,7 @@ hipError_t hipMemcpy(void* dst, const void* src, size_t sizeBytes, hipMemcpyKind stream->locked_copySync(dst, src, sizeBytes, kind); } - catch (ihipException ex) { + catch (ihipException &ex) { e = ex._code; } @@ -1015,7 +1015,7 @@ hipError_t hipMemcpyHtoD(hipDeviceptr_t dst, void* src, size_t sizeBytes) stream->locked_copySync((void*)dst, (void*)src, sizeBytes, hipMemcpyHostToDevice, false); } - catch (ihipException ex) { + catch (ihipException &ex) { e = ex._code; } @@ -1037,7 +1037,7 @@ hipError_t hipMemcpyDtoH(void* dst, hipDeviceptr_t src, size_t sizeBytes) stream->locked_copySync((void*)dst, (void*)src, sizeBytes, hipMemcpyDeviceToHost, false); } - catch (ihipException ex) { + catch (ihipException &ex) { e = ex._code; } @@ -1059,7 +1059,7 @@ hipError_t hipMemcpyDtoD(hipDeviceptr_t dst, hipDeviceptr_t src, size_t sizeByte stream->locked_copySync((void*)dst, (void*)src, sizeBytes, hipMemcpyDeviceToDevice, false); } - catch (ihipException ex) { + catch (ihipException &ex) { e = ex._code; } @@ -1081,7 +1081,7 @@ hipError_t hipMemcpyHtoH(void* dst, void* src, size_t sizeBytes) stream->locked_copySync((void*)dst, (void*)src, sizeBytes, hipMemcpyHostToHost, false); } - catch (ihipException ex) { + catch (ihipException &ex) { e = ex._code; } @@ -1140,7 +1140,7 @@ hipError_t ihipMemcpy2D(void* dst, size_t dpitch, const void* src, size_t spitch stream->locked_copySync((unsigned char*)dst + i*dpitch, (unsigned char*)src + i*spitch, width, kind); } } - catch (ihipException ex) { + catch (ihipException &ex) { e = ex._code; } @@ -1178,7 +1178,7 @@ hipError_t hipMemcpy2DAsync(void* dst, size_t dpitch, const void* src, size_t sp e = hip_internal::memcpyAsync((unsigned char*)dst + i*dpitch, (unsigned char*)src + i*spitch, width, kind,stream); } } - catch (ihipException ex) { + catch (ihipException &ex) { e = ex._code; } @@ -1231,7 +1231,7 @@ hipError_t hipMemcpy2DToArray(hipArray* dst, size_t wOffset, size_t hOffset, con stream->locked_copySync((unsigned char*)dst->data + i*dst_w, (unsigned char*)src + i*src_w, width, kind); } } - catch (ihipException ex) { + catch (ihipException &ex) { e = ex._code; } @@ -1252,7 +1252,7 @@ hipError_t hipMemcpyToArray(hipArray* dst, size_t wOffset, size_t hOffset, try { stream->locked_copySync((char *)dst->data + wOffset, src, count, kind); } - catch (ihipException ex) { + catch (ihipException &ex) { e = ex._code; } @@ -1302,7 +1302,7 @@ hipError_t hipMemcpy3D(const struct hipMemcpy3DParms *p) } } } - catch (ihipException ex) { + catch (ihipException &ex) { e = ex._code; }