P4 to Git Change 1082378 by lmoriche@lmoriche_opencl_dev on 2014/09/29 17:08:11
ECR #304775 - Replace amd::Atomic with std::atomic Pre-checkin: http://ocltc.amd.com:8111/viewModification.html?modId=40639&personal=true&buildTypeId=&tab=vcsModificationBuilds&show_all_builds=true Affected files ... ... //depot/stg/opencl/drivers/opencl/runtime/os/os_posix.cpp#38 edit ... //depot/stg/opencl/drivers/opencl/runtime/os/os_win32.cpp#40 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/command.cpp#64 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/command.hpp#73 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/memory.cpp#108 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/memory.hpp#86 edit ... //depot/stg/opencl/drivers/opencl/runtime/platform/runtime.cpp#33 edit ... //depot/stg/opencl/drivers/opencl/runtime/thread/monitor.hpp#6 edit ... //depot/stg/opencl/drivers/opencl/runtime/thread/semaphore.cpp#6 edit ... //depot/stg/opencl/drivers/opencl/runtime/thread/semaphore.hpp#6 edit ... //depot/stg/opencl/drivers/opencl/runtime/utils/util.hpp#10 edit
This commit is contained in:
@@ -29,18 +29,16 @@ Event::Event(HostQueue& queue)
|
||||
: context_(queue.context())
|
||||
, callbacks_(NULL)
|
||||
, status_(CL_INT_MAX)
|
||||
, notified_(0)
|
||||
, profilingInfo_(
|
||||
queue.properties().test(CL_QUEUE_PROFILING_ENABLE)
|
||||
|| Agent::shouldPostEventEvents())
|
||||
{ }
|
||||
{ notified_.clear(); }
|
||||
|
||||
Event::Event(Context& context)
|
||||
: context_(context)
|
||||
, callbacks_(NULL)
|
||||
, status_(CL_SUBMITTED)
|
||||
, notified_(0)
|
||||
{ }
|
||||
{ notified_.clear(); }
|
||||
|
||||
Event::~Event()
|
||||
{
|
||||
@@ -95,7 +93,7 @@ Event::setStatus(cl_int status, uint64_t timeStamp)
|
||||
return false;
|
||||
}
|
||||
|
||||
if (callbacks_ != NULL) {
|
||||
if (callbacks_ != (CallBackEntry*)0) {
|
||||
processCallbacks(status);
|
||||
}
|
||||
|
||||
@@ -131,14 +129,14 @@ Event::setCallback(cl_int status, Event::CallBackFunction callback, void* data)
|
||||
}
|
||||
|
||||
entry->next_ = callbacks_;
|
||||
while (!callbacks_.compareAndSet(entry->next_, entry)) {
|
||||
while (!callbacks_.compare_exchange_weak(entry->next_, entry)) {
|
||||
// Someone else is also updating the head of the linked list! reload.
|
||||
entry->next_ = callbacks_;
|
||||
}
|
||||
|
||||
// Check if the event has already reached 'status'
|
||||
if (status_ <= status && entry->callback_ != NULL) {
|
||||
if (entry->callback_.swap(NULL) != NULL) {
|
||||
if (status_ <= status && entry->callback_ != CallBackFunction(0)) {
|
||||
if (entry->callback_.exchange(NULL) != NULL) {
|
||||
callback(as_cl(this), status, entry->data_);
|
||||
}
|
||||
}
|
||||
@@ -157,9 +155,9 @@ Event::processCallbacks(cl_int status) const
|
||||
CallBackEntry* entry;
|
||||
for (entry = callbacks_; entry != NULL; entry = entry->next_) {
|
||||
// If the entry's status matches the mask,
|
||||
if (entry->status_ == mask && entry->callback_ != NULL) {
|
||||
if (entry->status_ == mask && entry->callback_ != CallBackFunction(0)) {
|
||||
// invoke the callback function.
|
||||
CallBackFunction callback = entry->callback_.swap(NULL);
|
||||
CallBackFunction callback = entry->callback_.exchange(NULL);
|
||||
if (callback != NULL) {
|
||||
callback(event, status, entry->data_);
|
||||
}
|
||||
@@ -190,14 +188,12 @@ Event::awaitCompletion()
|
||||
bool
|
||||
Event::notifyCmdQueue()
|
||||
{
|
||||
static uint Notifed = 1;
|
||||
static uint Empty = 0;
|
||||
HostQueue* queue = command().queue();
|
||||
if ((NULL != queue) && notified_.compareAndSet(Empty, Notifed)) {
|
||||
if ((NULL != queue) && !notified_.test_and_set()) {
|
||||
// Make sure the queue is draining the enqueued commands.
|
||||
amd::Command* command = new amd::Marker(*queue, false, nullWaitList, this);
|
||||
if (command == NULL) {
|
||||
notified_.compareAndSet(Notifed, Empty);
|
||||
notified_.clear();
|
||||
return false;
|
||||
}
|
||||
command->enqueue();
|
||||
|
||||
@@ -13,7 +13,6 @@
|
||||
#define COMMAND_HPP_
|
||||
|
||||
#include "top.hpp"
|
||||
#include "thread/atomic.hpp"
|
||||
#include "thread/monitor.hpp"
|
||||
#include "thread/thread.hpp"
|
||||
#include "platform/agent.hpp"
|
||||
@@ -28,6 +27,7 @@
|
||||
#include "CL/cl_ext.h"
|
||||
|
||||
#include <algorithm>
|
||||
#include <atomic>
|
||||
#include <functional>
|
||||
#include <vector>
|
||||
|
||||
@@ -58,7 +58,7 @@ class Event : public RuntimeObject
|
||||
{
|
||||
struct CallBackEntry* next_; //!< the next entry in the callback list.
|
||||
|
||||
Atomic<CallBackFunction> callback_; //!< callback function pointer.
|
||||
std::atomic<CallBackFunction> callback_; //!< callback function pointer.
|
||||
void* data_; //!< user data passed to the callback function.
|
||||
cl_int status_; //!< execution status triggering the callback.
|
||||
|
||||
@@ -76,9 +76,9 @@ private:
|
||||
Monitor lock_;
|
||||
|
||||
SharedReference<Context> context_; //!< context associated with this event.
|
||||
Atomic<CallBackEntry*> callbacks_; //!< linked list of callback entries.
|
||||
volatile cl_int status_; //!< current execution status.
|
||||
Atomic<uint> notified_; //!< Command queue was notified
|
||||
std::atomic<CallBackEntry*> callbacks_; //!< linked list of callback entries.
|
||||
volatile cl_int status_; //!< current execution status.
|
||||
std::atomic_flag notified_; //!< Command queue was notified
|
||||
|
||||
protected:
|
||||
|
||||
|
||||
@@ -87,12 +87,12 @@ Memory::Memory(
|
||||
, isParent_(false)
|
||||
, vDev_(NULL)
|
||||
, forceSysMemAlloc_(false)
|
||||
, mapCount_(0)
|
||||
, svmHostAddress_(svmPtr)
|
||||
, svmPtrCommited_(false)
|
||||
, canBeCached_(true)
|
||||
, lockMemoryOps_("Memory Ops Lock", true)
|
||||
{
|
||||
std::atomic_init(&mapCount_, 0u);
|
||||
}
|
||||
|
||||
Memory::Memory(
|
||||
@@ -117,7 +117,6 @@ Memory::Memory(
|
||||
, isParent_(false)
|
||||
, vDev_(NULL)
|
||||
, forceSysMemAlloc_(false)
|
||||
, mapCount_(0)
|
||||
, svmHostAddress_(parent.getSvmPtr())
|
||||
, svmPtrCommited_(parent.isSvmPtrCommited())
|
||||
, canBeCached_(true)
|
||||
@@ -142,6 +141,8 @@ Memory::Memory(
|
||||
(CL_MEM_HOST_READ_ONLY | CL_MEM_HOST_WRITE_ONLY |
|
||||
CL_MEM_HOST_NO_ACCESS);
|
||||
}
|
||||
|
||||
std::atomic_init(&mapCount_, 0u);
|
||||
}
|
||||
|
||||
void
|
||||
@@ -438,7 +439,7 @@ Memory::setDestructorCallback(DestructorCallBackFunction callback, void* data)
|
||||
}
|
||||
|
||||
entry->next_ = destructorCallbacks_;
|
||||
while (!destructorCallbacks_.compareAndSet(entry->next_, entry)) {
|
||||
while (!destructorCallbacks_.compare_exchange_weak(entry->next_, entry)) {
|
||||
// Someone else is also updating the head of the linked list! reload.
|
||||
entry->next_ = destructorCallbacks_;
|
||||
}
|
||||
|
||||
@@ -7,13 +7,13 @@
|
||||
|
||||
#include "top.hpp"
|
||||
#include "utils/flags.hpp"
|
||||
#include "thread/atomic.hpp"
|
||||
#include "thread/monitor.hpp"
|
||||
#include "platform/context.hpp"
|
||||
#include "platform/object.hpp"
|
||||
#include "platform/interop.hpp"
|
||||
#include "device/device.hpp"
|
||||
|
||||
#include <atomic>
|
||||
#include <utility>
|
||||
#include <vector>
|
||||
#include <list>
|
||||
@@ -155,7 +155,7 @@ protected:
|
||||
std::map<const Device*, AllocState> deviceAlloced_;
|
||||
|
||||
//! Linked list of destructor callbacks.
|
||||
Atomic<DestructorCallBackEntry*> destructorCallbacks_;
|
||||
std::atomic<DestructorCallBackEntry*> destructorCallbacks_;
|
||||
|
||||
SharedReference<Context> context_; //!< Owning context
|
||||
Memory* parent_;
|
||||
@@ -170,7 +170,7 @@ protected:
|
||||
bool isParent_; //!< This object is a parent
|
||||
device::VirtualDevice* vDev_; //!< Memory object belongs to a virtual device only
|
||||
bool forceSysMemAlloc_; //!< Forces system memory allocation
|
||||
Atomic<uint> mapCount_; //!< Keep track of number of mappings for a memory object
|
||||
std::atomic_uint mapCount_; //!< Keep track of number of mappings for a memory object
|
||||
void * svmHostAddress_; //!< svm host address;
|
||||
bool svmPtrCommited_; //!< svm host address committed flag;
|
||||
bool canBeCached_; //!< flag to if the object can be cached;
|
||||
|
||||
@@ -3,7 +3,6 @@
|
||||
//
|
||||
|
||||
#include "platform/runtime.hpp"
|
||||
#include "thread/atomic.hpp"
|
||||
#include "os/os.hpp"
|
||||
#include "thread/thread.hpp"
|
||||
#include "device/device.hpp"
|
||||
@@ -24,14 +23,10 @@
|
||||
#include <intrin.h>
|
||||
#endif
|
||||
|
||||
#include <atomic>
|
||||
#include <cstdlib>
|
||||
#include <iostream>
|
||||
|
||||
#ifdef TIMEBOMB
|
||||
# include <cstdio>
|
||||
# include <time.h>
|
||||
#endif // TIMEBOMB
|
||||
|
||||
namespace amd {
|
||||
|
||||
#ifdef __linux__
|
||||
@@ -60,22 +55,19 @@ Runtime::init()
|
||||
// from concurrently executing the init() routines. We can't use a
|
||||
// Monitor since the system is not yet initialized.
|
||||
|
||||
static Atomic<int> lock = 0;
|
||||
static std::atomic_flag lock = ATOMIC_FLAG_INIT;
|
||||
struct CriticalRegion
|
||||
{
|
||||
Atomic<int>& lock_;
|
||||
CriticalRegion(Atomic<int>& lock) : lock_(lock)
|
||||
std::atomic_flag& lock_;
|
||||
CriticalRegion(std::atomic_flag& lock) : lock_(lock)
|
||||
{
|
||||
while (true) {
|
||||
if (lock == 0 && lock.swap(1) == 0) {
|
||||
break;
|
||||
}
|
||||
while (lock.test_and_set(std::memory_order_acquire)) {
|
||||
Os::yield();
|
||||
}
|
||||
}
|
||||
~CriticalRegion()
|
||||
{
|
||||
lock_.storeRelease(0);
|
||||
lock_.clear(std::memory_order_release);
|
||||
}
|
||||
} region(lock);
|
||||
|
||||
@@ -83,20 +75,6 @@ Runtime::init()
|
||||
return true;
|
||||
}
|
||||
|
||||
#ifdef TIMEBOMB
|
||||
time_t current = time(NULL);
|
||||
time_t expiration = TIMEBOMB;
|
||||
|
||||
if (current > expiration) {
|
||||
fprintf(stderr, "Expired on %s", asctime(gmtime(&expiration)));
|
||||
return false;
|
||||
}
|
||||
else {
|
||||
fprintf(stderr, "For test only: Expires on %s",
|
||||
asctime(gmtime(&expiration)));
|
||||
}
|
||||
#endif // TIMEBOMB
|
||||
|
||||
if ( !Flag::init()
|
||||
|| !option::init()
|
||||
|| !Device::init()
|
||||
|
||||
Reference in New Issue
Block a user