Files
rocm-systems/rocclr/runtime/platform/context.hpp
T
foreman 8cac43ef6c P4 to Git Change 1092066 by xcui@merged_opencl_jxcwin on 2014/10/29 18:11:54
EPR #406328 - modified the opencl runtime so that SVM allocation is done for every SVM capable devices, not just one device. This is the part of changes for SVM multiple device support.

Affected files ...

... //depot/stg/opencl/drivers/opencl/api/opencl/amdocl/cl_svm.cpp#7 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/context.cpp#32 edit
... //depot/stg/opencl/drivers/opencl/runtime/platform/context.hpp#22 edit
2014-10-29 18:17:14 -04:00

202 regels
6.3 KiB
C++

//
// Copyright (c) 2008 Advanced Micro Devices, Inc. All rights reserved.
//
#ifndef CONTEXT_HPP_
#define CONTEXT_HPP_
#include "top.hpp"
#include "device/device.hpp"
#include "platform/object.hpp"
#include "platform/agent.hpp"
#include <vector>
#include <map>
namespace amd {
/*! \addtogroup Runtime
* @{
*
* \addtogroup Contexts
* @{
*/
class GLFunctions;
class DeviceQueue;
class Context : public RuntimeObject
{
std::vector<Device*> devices_;
public:
enum Flags
{
GLDeviceKhr = 1<<0, //!< GL
D3D10DeviceKhr = 1<<1, //!< D3D10
OfflineDevices = 1<<2, //!< Offline devices
CommandIntercept = 1<<3, //!< Command intercept
D3D11DeviceKhr = 1<<4, //!< D3D11
InteropUserSync = 1<<5, //!< Interop user sync enabled
D3D9DeviceKhr = 1<<6, //!< d3d9 device
D3D9DeviceEXKhr = 1<<7, //!< d3d9EX device
D3D9DeviceVAKhr = 1<<8, //!< d3d9VA device
};
//! Context info structure
struct Info
{
uint flags_; //!< Context info flags
intptr_t type_; //!< Context type
void* hDev_; //!< Device object reference
void* hCtx_; //!< Context object reference
size_t propertiesSize_;//!< Size of the original properties in bytes
cl_int (CL_CALLBACK * commandIntercept_)(cl_event, cl_int *);
};
struct DeviceQueueInfo
{
DeviceQueue* defDeviceQueue_; //!< Default device queue
uint deviceQueueCnt_; //!< The number of device queues
DeviceQueueInfo(): defDeviceQueue_(NULL), deviceQueueCnt_(0) {}
};
private:
// Copying a Context is not allowed
Context(const Context&);
Context& operator = (const Context&);
protected:
bool terminate() {
if (Agent::shouldPostContextEvents()) {
Agent::postContextFree(as_cl(this));
}
return true;
}
//! Context destructor
~Context();
public:
/*! \brief Helper function to check the context properties and initialize
* context info structure
*
* \return An errcode if invalid, CL_SUCCESS if valid
*/
static int checkProperties(
const cl_context_properties* properties, //!< Properties
Info* info //!< Info structure
);
//! Default constructor
Context(
const std::vector<Device*>& devices, //!< List of all devices
const Info& info //!< Context info structure
);
//! Compare two Context instances.
bool operator == (const Context& rhs) const { return this == &rhs; }
bool operator != (const Context& rhs) const { return !(*this == rhs); }
/*! Creates the context
*
* \return An errcode if runtime fails the context creation,
* CL_SUCCESS otherwise
*/
int create(
const intptr_t* properties //!< Original context properties
);
/**
* Allocate host memory using either a custom device allocator or a generic
* OS allocator
*
* @param size Allocation size, in bytes
* @param alignment Desired alignment, in bytes
* @param atomics The buffer should support platform (SVM) atomics
*/
void* hostAlloc(size_t size, size_t alignment, bool atomics = false) const;
/**
* Release host memory
* @param ptr Pointer allocated using ::hostAlloc. If the pointer has been
* allocated elsewhere, the behavior is undefined
*/
void hostFree(void* ptr) const;
/**
* Allocate SVM buffer
*
* @param size Allocation size, in bytes
* @param alignment Desired alignment, in bytes
* @param flags The flags to create a svm space
*/
void* svmAlloc(size_t size, size_t alignment, cl_svm_mem_flags flags = CL_MEM_READ_WRITE);
/**
* Release SVM buffer
* @param ptr Pointer allocated using ::svmAlloc. If the pointer has been
* allocated elsewhere, the behavior is undefined
*/
void svmFree(void* ptr) const;
//! Return the devices associated with this context.
const std::vector<Device*>& devices() const { return devices_; }
//! Return the SVM capable devices associated with this context.
const std::vector<Device*>& svmDevices() const { return customSvmAllocDevice_; }
//! Returns true if the given device is associated with this context.
bool containsDevice(const Device* device) const;
//! Returns the context info structure
const Info& info() const { return info_; }
//! Returns a pointer to the original properties
const cl_context_properties* properties() const { return properties_; }
//! Returns a pointer to the OpenGL context
GLFunctions* glenv() const { return glenv_; }
//! RTTI internal implementation
virtual ObjectType objectType() const { return ObjectTypeContext; }
//! Returns context lock for the serialized access to the context
Monitor& lock() { return ctxLock_; }
//! Returns TRUE if runtime succesfully added a device queue
DeviceQueue* defDeviceQueue(const Device& dev) const;
//! Returns TRUE if runtime succesfully added a device queue
bool isDevQueuePossible(const Device& dev);
//! Returns TRUE if runtime succesfully added a device queue
void addDeviceQueue(
const Device& dev, //!< Device object
DeviceQueue* queue, //!< Device queue
bool defDevQueue //!< Added device queue will be the default queue
);
//! Removes a device queue from the list of queues
void removeDeviceQueue(
const Device& dev, //!< Device object
DeviceQueue* queue //!< Device queue
);
private:
const Info info_; //!< Context info structure
cl_context_properties* properties_; //!< Original properties
GLFunctions* glenv_; //!< OpenGL context
Device* customHostAllocDevice_; //!< Device responsible for host allocations
std::vector<Device*> customSvmAllocDevice_; //!< Devices can support SVM allocations
std::map<const Device*, DeviceQueueInfo> deviceQueues_; //!< Device queues mapping
Monitor ctxLock_; //!< Lock for the context access
};
/*! @}
* @}
*/
} // namespace amd
#endif /*CONTEXT_HPP_*/