8f7df519da
SWDEV-79445 - OCL generic changes and code clean-up
1. This change replaces the use of std::map with std::unordered_map to improve lookup/insert time.
2. Replace the use of std::make_pair and std::pair constructor with uniform initialization for cleaner code.
3. Replace the use of std::Container::iterator type with the auto keyword for cleaner code.
4. Use range based for loops where needed.
ReviewBoardURL = http://ocltc.amd.com/reviews/r/14517/diff/
Affected files ...
... //depot/stg/opencl/drivers/opencl/api/hip/hip_platform.cpp#4 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_context.cpp#58 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_d3d10.cpp#16 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_d3d10_amd.hpp#9 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_d3d11.cpp#24 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_d3d11_amd.hpp#13 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_d3d9.cpp#34 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_d3d9_amd.hpp#17 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_gl.cpp#57 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_pipe.cpp#7 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_program.cpp#46 edit
... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_svm.cpp#23 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/appprofile.hpp#14 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/cpu/cpuprogram.cpp#72 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/cpu/cpuvirtual.cpp#27 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/device.cpp#216 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/device.hpp#297 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuappprofile.cpp#13 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpubinary.cpp#59 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpucompiler.cpp#158 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpudevice.cpp#587 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpukernel.cpp#322 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuprintf.cpp#46 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuprogram.cpp#237 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuprogram.hpp#70 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuresource.cpp#242 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuvirtual.cpp#415 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/gpu/gpuvirtual.hpp#143 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palappprofile.cpp#3 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palcompiler.cpp#22 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/paldevice.cpp#79 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palprintf.cpp#9 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palprogram.cpp#59 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palresource.cpp#60 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palvirtual.cpp#84 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/pal/palvirtual.hpp#46 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/CMakeLists.txt#11 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/pro/prodevice.cpp#4 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/pro/prodevice.hpp#5 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocbinary.hpp#6 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/roccompiler.cpp#42 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/roccounters.cpp#3 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocprintf.cpp#10 edit
... //depot/stg/opencl/drivers/opencl/runtime/device/rocm/rocprogram.cpp#81 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/command.cpp#81 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/command.hpp#89 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/commandqueue.cpp#24 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/context.cpp#49 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/context.hpp#29 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/memory.cpp#129 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/memory.hpp#102 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/perfctr.hpp#7 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/program.cpp#91 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/program.hpp#43 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/sampler.hpp#9 edit
... //depot/stg/opencl/drivers/opencl/runtime/utils/flags.cpp#17 edit
[ROCm/clr commit: d09ca72f74]
173 lines
4.6 KiB
C++
173 lines
4.6 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_ | CL_QUEUE_COMMAND_INTERCEPT_ENABLE_AMD,
|
|
queueRTCUs, priority) {
|
|
if (thread_.state() >= Thread::INITIALIZED) {
|
|
ScopedLock sl(queueLock_);
|
|
thread_.start(this);
|
|
queueLock_.wait();
|
|
}
|
|
}
|
|
|
|
bool HostQueue::terminate() {
|
|
if (Os::isThreadAlive(thread_)) {
|
|
// Make sure all the commands are finished on the device.
|
|
finish();
|
|
|
|
// Kill the command queue loop.
|
|
thread_.acceptingCommands_ = false;
|
|
|
|
// Wake-up the command loop, so it can exit
|
|
flush();
|
|
|
|
// 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;
|
|
}
|
|
|
|
command->enqueue();
|
|
command->awaitCompletion();
|
|
command->release();
|
|
}
|
|
|
|
void HostQueue::loop(device::VirtualDevice* virtualDevice) {
|
|
cl_int(CL_CALLBACK * commandIntercept)(cl_event, cl_int*) =
|
|
properties().test(CL_QUEUE_COMMAND_INTERCEPT_ENABLE_AMD) ? context().info().commandIntercept_
|
|
: NULL;
|
|
|
|
// 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;
|
|
}
|
|
|
|
command->setStatus(CL_SUBMITTED);
|
|
|
|
cl_int result;
|
|
if ((commandIntercept != NULL) && commandIntercept(as_cl<Event>(command), &result)) {
|
|
// The command was handled by the callback.
|
|
command->setStatus(CL_RUNNING, command->profilingInfo().submitted_);
|
|
command->setStatus(result);
|
|
continue;
|
|
}
|
|
|
|
// Submit to the device queue.
|
|
command->submit(*virtualDevice);
|
|
|
|
// if we are in intercept mode or this is a user invisible marker command
|
|
if ((0 == command->type()) || (commandIntercept != NULL)) {
|
|
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
|
|
command.retain();
|
|
command.setStatus(CL_QUEUED);
|
|
queue_.enqueue(&command);
|
|
}
|
|
|
|
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 {
|