46a6201be0
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
[ROCm/clr commit: 3f6e18bf6b]
211 satır
5.3 KiB
C++
211 satır
5.3 KiB
C++
//
|
|
// Copyright (c) 2012 Advanced Micro Devices, Inc. All rights reserved.
|
|
//
|
|
|
|
#include "commandqueue.hpp"
|
|
#include "thread/monitor.hpp"
|
|
#include "device/device.hpp"
|
|
#include "platform/context.hpp"
|
|
|
|
/*!
|
|
* \file commandQueue.cpp
|
|
* \brief Definitions for HostQueue object.
|
|
*
|
|
* \author Laurent Morichetti (laurent.morichetti@amd.com)
|
|
* \date October 2008
|
|
*/
|
|
|
|
namespace amd {
|
|
|
|
HostQueue::HostQueue(Context& context, Device& device, cl_command_queue_properties properties,
|
|
uint queueRTCUs, Priority priority)
|
|
: CommandQueue(context, device, properties, device.info().queueProperties_,
|
|
queueRTCUs, priority),
|
|
lastEnqueueCommand_(nullptr) {
|
|
if (thread_.state() >= Thread::INITIALIZED) {
|
|
ScopedLock sl(queueLock_);
|
|
thread_.start(this);
|
|
queueLock_.wait();
|
|
}
|
|
}
|
|
|
|
bool HostQueue::terminate() {
|
|
if (Os::isThreadAlive(thread_)) {
|
|
Command* marker = nullptr;
|
|
|
|
// Send a finish if the queue is still accepting commands.
|
|
{
|
|
ScopedLock sl(queueLock_);
|
|
if (thread_.acceptingCommands_) {
|
|
marker = new Marker(*this, false);
|
|
if (marker != nullptr) {
|
|
append(*marker);
|
|
queueLock_.notify();
|
|
}
|
|
}
|
|
}
|
|
if (marker != nullptr) {
|
|
marker->awaitCompletion();
|
|
marker->release();
|
|
}
|
|
|
|
// Wake-up the command loop, so it can exit
|
|
{
|
|
ScopedLock sl(queueLock_);
|
|
thread_.acceptingCommands_ = false;
|
|
queueLock_.notify();
|
|
}
|
|
|
|
// FIXME_lmoriche: fix termination handshake
|
|
while (thread_.state() < Thread::FINISHED) {
|
|
Os::yield();
|
|
}
|
|
}
|
|
|
|
if (Agent::shouldPostCommandQueueEvents()) {
|
|
Agent::postCommandQueueFree(as_cl(this->asCommandQueue()));
|
|
}
|
|
|
|
return true;
|
|
}
|
|
|
|
void HostQueue::finish() {
|
|
// Send a finish to make sure we finished all commands
|
|
Command* command = new Marker(*this, false);
|
|
if (command == NULL) {
|
|
return;
|
|
}
|
|
ClPrint(LOG_DEBUG, LOG_CMD, "marker is queued");
|
|
command->enqueue();
|
|
command->awaitCompletion();
|
|
command->release();
|
|
ClPrint(LOG_DEBUG, LOG_CMD, "All commands finished");
|
|
}
|
|
|
|
void HostQueue::loop(device::VirtualDevice* virtualDevice) {
|
|
// Notify the caller that the queue is ready to accept commands.
|
|
{
|
|
ScopedLock sl(queueLock_);
|
|
thread_.acceptingCommands_ = true;
|
|
queueLock_.notify();
|
|
}
|
|
// Create a command batch with all the commands present in the queue.
|
|
Command* head = NULL;
|
|
Command* tail = NULL;
|
|
while (true) {
|
|
// Get one command from the queue
|
|
Command* command = queue_.dequeue();
|
|
if (command == NULL) {
|
|
ScopedLock sl(queueLock_);
|
|
while ((command = queue_.dequeue()) == NULL) {
|
|
if (!thread_.acceptingCommands_) {
|
|
return;
|
|
}
|
|
queueLock_.wait();
|
|
}
|
|
}
|
|
|
|
command->retain();
|
|
|
|
// Process the command's event wait list.
|
|
const Command::EventWaitList& events = command->eventWaitList();
|
|
bool dependencyFailed = false;
|
|
|
|
for (const auto& it : events) {
|
|
// Only wait if the command is enqueued into another queue.
|
|
if (it->command().queue() != this) {
|
|
virtualDevice->flush(head, true);
|
|
tail = head = NULL;
|
|
dependencyFailed |= !it->awaitCompletion();
|
|
}
|
|
}
|
|
|
|
// Insert the command to the linked list.
|
|
if (NULL == head) { // if the list is empty
|
|
head = tail = command;
|
|
} else {
|
|
tail->setNext(command);
|
|
tail = command;
|
|
}
|
|
|
|
if (dependencyFailed) {
|
|
command->setStatus(CL_EXEC_STATUS_ERROR_FOR_EVENTS_IN_WAIT_LIST);
|
|
continue;
|
|
}
|
|
|
|
ClPrint(LOG_DEBUG, LOG_CMD, "command is submitted: %p", command);
|
|
command->setStatus(CL_SUBMITTED);
|
|
// Submit to the device queue.
|
|
command->submit(*virtualDevice);
|
|
|
|
// if this is a user invisible marker command, then flush
|
|
if (0 == command->type()) {
|
|
virtualDevice->flush(head);
|
|
tail = head = NULL;
|
|
}
|
|
} // while (true) {
|
|
}
|
|
|
|
void HostQueue::append(Command& command) {
|
|
// We retain the command here. It will be released when its status
|
|
// changes to CL_COMPLETE
|
|
if ((command.getWaitBits() & 0x1) != 0) {
|
|
finish();
|
|
}
|
|
command.retain();
|
|
command.setStatus(CL_QUEUED);
|
|
queue_.enqueue(&command);
|
|
}
|
|
|
|
bool HostQueue::isEmpty() {
|
|
// Get a snapshot of queue size
|
|
return queue_.empty();
|
|
}
|
|
|
|
void HostQueue::setLastQueuedCommand(Command* lastCommand) {
|
|
// Set last submitted command
|
|
ScopedLock sl(queueLock_);
|
|
if (lastEnqueueCommand_ != nullptr) {
|
|
lastEnqueueCommand_->release();
|
|
}
|
|
lastEnqueueCommand_ = lastCommand;
|
|
if (lastCommand != nullptr) {
|
|
lastEnqueueCommand_->retain();
|
|
}
|
|
}
|
|
|
|
Command* HostQueue::getLastQueuedCommand(bool retain) {
|
|
// Get last submitted command
|
|
ScopedLock sl(queueLock_);
|
|
if (lastEnqueueCommand_ == nullptr) {
|
|
return nullptr;
|
|
}
|
|
|
|
if (retain) {
|
|
lastEnqueueCommand_->retain();
|
|
}
|
|
return lastEnqueueCommand_;
|
|
}
|
|
|
|
DeviceQueue::~DeviceQueue() {
|
|
delete virtualDevice_;
|
|
ScopedLock lock(context().lock());
|
|
context().removeDeviceQueue(device(), this);
|
|
}
|
|
|
|
bool DeviceQueue::create() {
|
|
static const bool InteropQueue = true;
|
|
const bool defaultDeviceQueue = properties().test(CL_QUEUE_ON_DEVICE_DEFAULT);
|
|
bool result = false;
|
|
|
|
virtualDevice_ = device().createVirtualDevice(this);
|
|
if (virtualDevice_ != NULL) {
|
|
result = true;
|
|
context().addDeviceQueue(device(), this, defaultDeviceQueue);
|
|
}
|
|
|
|
return result;
|
|
}
|
|
|
|
} // namespace amd
|