3f6e18bf6b
SWDEV-198863 - Options for hip-clang-vdi path to provide the chicken bits, or functional equivalents to HCC_DB (phase 1) 1. The log macros is turned off for release build. So log functions has zero impact to release build. 2. The log macros have level, mask, condition control. So we can have more control to avoid log flooding. I also adjusted some existing log to use new log functions. 1. To excercise and test the new log functions. 2. To improve performance slightly. 3. The change is mainly for HIP-ROCM, we can move more in next phases for PAL or ORCA. 4. I make these log feature unavailable for release build. We can revert to old log functions for release build in a case by case method. Tests: 1. http://ocltc.amd.com:8111/viewModification.html?modId=128289&personal=true&tab=vcsModificationBuilds http://ocltc.amd.com:8111/viewModification.html?modId=128358&personal=true&tab=vcsModificationBuilds 2. release build, run hip program, there is no log 3. fastdebug build, run hip program, export LOG_LEVEL=3 export GPU_LOG_MASK=4294967295 There was a lot of logs. 4. fastdebug build, run hip program, export LOG_LEVEL=2 export GPU_LOG_MASK=4294967295 There was no logs. 5. fastdebug build, run hip program, export LOG_LEVEL=3 export GPU_LOG_MASK=4294967294 There was much less logs. 6. fastdebug build, run hip program, export LOG_LEVEL=3 export GPU_LOG_MASK=47102 There was even much less logs. The logs was expected according to the mask. 7. Tested step 2 to 6 similarily in Windows and Linux ReviewBoard: http://ocltc.amd.com/reviews/r/18215 Affected files ... ... //depot/stg/opencl/drivers/opencl/api/hip/hip_internal.hpp#46 edit ... //depot/stg/opencl/drivers/opencl/api/hip/hip_memory.cpp#82 edit ... //depot/stg/opencl/drivers/opencl/api/hip/hip_stream.cpp#26 edit ... //depot/stg/opencl/drivers/opencl/api/hip/hiprtc_internal.hpp#2 edit ... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_svm.cpp#29 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/comgrctx.cpp#6 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/devkernel.cpp#29 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/devprogram.cpp#68 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocdevice.cpp#137 edit ... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocvirtual.cpp#91 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/command.cpp#100 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/commandqueue.cpp#32 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/runtime.cpp#40 edit ... //depot/stg/opencl/drivers/opencl/runtime/utils/debug.hpp#10 edit ... //depot/stg/opencl/drivers/opencl/runtime/utils/flags.hpp#323 edit
137 строки
2.9 KiB
C++
137 строки
2.9 KiB
C++
//
|
|
// Copyright (c) 2008 Advanced Micro Devices, Inc. All rights reserved.
|
|
//
|
|
|
|
#include "platform/runtime.hpp"
|
|
#include "os/os.hpp"
|
|
#include "thread/thread.hpp"
|
|
#include "device/device.hpp"
|
|
#include "utils/flags.hpp"
|
|
#include "utils/options.hpp"
|
|
#include "platform/context.hpp"
|
|
#include "platform/agent.hpp"
|
|
|
|
#include "amdocl/cl_gl_amd.hpp"
|
|
|
|
#ifdef _WIN32
|
|
#include <d3d10_1.h>
|
|
#include <dxgi.h>
|
|
#include "CL/cl_d3d10.h"
|
|
#endif //_WIN32
|
|
|
|
#if defined(_MSC_VER) // both Win32 and Win64
|
|
#include <intrin.h>
|
|
#endif
|
|
|
|
#include <atomic>
|
|
#include <cstdlib>
|
|
#include <iostream>
|
|
|
|
namespace amd {
|
|
|
|
volatile bool Runtime::initialized_ = false;
|
|
|
|
bool Runtime::init() {
|
|
if (initialized_) {
|
|
return true;
|
|
}
|
|
|
|
// Enter a very basic critical region. We want to prevent 2 threads
|
|
// from concurrently executing the init() routines. We can't use a
|
|
// Monitor since the system is not yet initialized.
|
|
|
|
static std::atomic_flag lock = ATOMIC_FLAG_INIT;
|
|
struct CriticalRegion {
|
|
std::atomic_flag& lock_;
|
|
CriticalRegion(std::atomic_flag& lock) : lock_(lock) {
|
|
while (lock.test_and_set(std::memory_order_acquire)) {
|
|
Os::yield();
|
|
}
|
|
}
|
|
~CriticalRegion() { lock_.clear(std::memory_order_release); }
|
|
} region(lock);
|
|
|
|
if (initialized_) {
|
|
return true;
|
|
}
|
|
|
|
if (!Flag::init() || !option::init() || !Device::init()
|
|
// Agent initializes last
|
|
|| !Agent::init()) {
|
|
ClPrint(LOG_ERROR, LOG_INIT, "Runtime initilization failed");
|
|
return false;
|
|
}
|
|
|
|
initialized_ = true;
|
|
ClTrace(LOG_DEBUG, LOG_INIT);
|
|
return true;
|
|
}
|
|
|
|
void Runtime::tearDown() {
|
|
if (!initialized_) {
|
|
return;
|
|
}
|
|
ClTrace(LOG_DEBUG, LOG_INIT);
|
|
|
|
Agent::tearDown();
|
|
Device::tearDown();
|
|
option::teardown();
|
|
Flag::tearDown();
|
|
initialized_ = false;
|
|
}
|
|
|
|
class RuntimeTearDown : public amd::HeapObject {
|
|
public:
|
|
RuntimeTearDown() {}
|
|
~RuntimeTearDown() { /*Runtime::tearDown();*/ }
|
|
} runtime_tear_down;
|
|
|
|
uint ReferenceCountedObject::retain() { return ++make_atomic(referenceCount_); }
|
|
|
|
uint ReferenceCountedObject::release() {
|
|
uint newCount = --make_atomic(referenceCount_);
|
|
if (newCount == 0) {
|
|
if (terminate()) {
|
|
delete this;
|
|
}
|
|
}
|
|
return newCount;
|
|
}
|
|
|
|
#ifdef _WIN32
|
|
#ifdef DEBUG
|
|
static int reportHook(int reportType, char* message, int* returnValue) {
|
|
if (returnValue) {
|
|
*returnValue = 1;
|
|
}
|
|
std::cerr << message;
|
|
::exit(3);
|
|
return TRUE;
|
|
}
|
|
#endif // DEBUG
|
|
|
|
extern "C" BOOL WINAPI DllMain(HINSTANCE hinst, DWORD reason, LPVOID reserved) {
|
|
switch (reason) {
|
|
case DLL_PROCESS_ATTACH:
|
|
#ifdef DEBUG
|
|
if (!::getenv("AMD_OCL_ENABLE_MESSAGE_BOX")) {
|
|
_CrtSetReportHook(reportHook);
|
|
_set_error_mode(_OUT_TO_STDERR);
|
|
}
|
|
#endif // DEBUG
|
|
break;
|
|
case DLL_PROCESS_DETACH:
|
|
break;
|
|
case DLL_THREAD_DETACH: {
|
|
amd::Thread* thread = amd::Thread::current();
|
|
delete thread;
|
|
} break;
|
|
default:
|
|
break;
|
|
}
|
|
return true;
|
|
}
|
|
#endif
|
|
|
|
} // namespace amd
|