AGX Dynamics 2.38.0.2
Loading...
Searching...
No Matches
Device.h
Go to the documentation of this file.
1/*
2Copyright 2007-2024. Algoryx Simulation AB.
3
4All AGX source code, intellectual property, documentation, sample code,
5tutorials, scene files and technical white papers, are copyrighted, proprietary
6and confidential material of Algoryx Simulation AB. You may not download, read,
7store, distribute, publish, copy or otherwise disseminate, use or expose this
8material unless having a written signed agreement with Algoryx Simulation AB, or having been
9advised so by Algoryx Simulation AB for a time limited evaluation, or having purchased a
10valid commercial license from Algoryx Simulation AB.
11
12Algoryx Simulation AB disclaims all responsibilities for loss or damage caused
13from using this software, unless otherwise stated in written agreements with
14Algoryx Simulation AB.
15*/
16
17#pragma once
18
19
20#include <agx/config/AGX_USE_OPENGL.h>
21#include <agx/config/AGX_USE_OPENCL.h>
22#include <agx/agxCore_export.h>
23#include <agx/Component.h>
24#include <agx/HashTable.h>
25#include <agx/Allocator.h>
26#include <agx/MemoryPool.h>
27#include <agxData/Buffer.h>
28#include <agx/SyncTag.h>
29#include <agx/Job.h>
30
31#ifdef _MSC_VER
32# pragma warning(push)
33# pragma warning( disable : 4275 ) // warning C4275: non dll-interface class
34# pragma warning( disable : 4702) // warning C4702: unreachable code
35#endif
36
37
38
39namespace agx
40{
44 // AGX_DECLARE_POINTER_TYPES(HostDevice);
45
57 class AGXCORE_EXPORT Device : public Component, public Object::EventListener
58 {
59 public:
61
62 static Device *load(TiXmlElement *eDevice, Device *device);
63
64 public:
65
73
75 enum Type
76 {
78 #if AGX_USE_OPENCL()
80 #endif
81 #if AGX_USE_OPENGL()
83 #endif
85
88 GROUP
89 };
90
91 public:
96 Device(const agx::Name& name, Type type, const agx::String& typeName, ByteOrder byteOrder = UNDEFINED);
97
101 Type getType() const;
102
106 const agx::String& getTypeName() const;
107
111 ByteOrder getByteOrder() const;
112
117 void setTypeFormat(const agx::String& typeName, const agx::String& formatName);
118
123
124
125
128
130
131
141 virtual agx::SyncTag *sendData(const void *hostBuffer, agxData::Buffer *Buffer, size_t offset, size_t size, bool blocking) = 0;
142
152 virtual agx::SyncTag *receiveData(void *hostBuffer, agxData::Buffer *Buffer, size_t offset, size_t size, bool blocking) = 0;
153
154 protected:
155 virtual ~Device();
156 // friend class HostDevice;
157 void setByteOrder(ByteOrder byteOrder);
158
159 virtual void destroyCallback(agx::Object* object) override;
160
161
162 private:
163 Type m_type;
164 String m_typeName;
165 ByteOrder m_byteOrder;
167 TypeFormatTable m_typeFormatTable;
168
170 BufferTable m_bufferTable;
171 };
172
173
174 //---------------------------------------------------------------
175
180 {
181 public:
182 class SyncTag : public agx::SyncTag
183 {
184 public:
185 virtual Status wait() override { return SYNC_TAG_COMPLETED; }
186 virtual Status getStatus() override { return SYNC_TAG_COMPLETED; }
187 };
188
189 public:
191
192 using Device::createBuffer;
193 virtual agxData::Buffer *createBuffer(agxData::Format *format) override;
194
195 virtual agx::SyncTag* sendData(
196 const void *hostBuffer, agxData::Buffer* buffer, size_t offset, size_t size, bool blocking) override;
197
198 virtual agx::SyncTag* receiveData(
199 void *hostBuffer, agxData::Buffer* buffer, size_t offset, size_t size, bool blocking) override;
200
201 public:
202 void enqueue(Task *task);
203 // void setNumThreads(int numThreads);
204 // int getNumThreads() const;
205 void wait(bool passive = false);
206
207 protected:
208 virtual ~CpuDevice();
209
210 private:
211 CpuDevice(const Name& name = "CpuDevice");
212
213 private:
214 SyncTagRef m_dummyTag;
215
216 // ThreadPtrVector m_threads;
217 // ThreadPtrVector m_deactivatedThreads;
218 MemoryPool<RangeJob> m_jobAllocator;
219 };
220
221 //---------------------------------------------------------------
222
227 {
228 public:
229 DeviceGroup(const Name& name, Device *primaryDevice);
230
233
235
236 // const DeviceRefVector& getDevices() const;
237 // Device *getDevice(const String& name);
238
239 // void addDevice(const Device *device);
240 // void removeDevice(const Device *device);
241 // void removeDevice(const String& name);
242
243 virtual agxData::Buffer *createBuffer(agxData::Format* /*format*/) override { agxAbort1("DeviceGroup"); return nullptr; }
244
245 virtual agx::SyncTag *sendData(const void* /*hostBuffer*/, agxData::Buffer* /*Buffer*/, size_t /*offset*/, size_t /*size*/, bool /*blocking*/) override { agxAbort1("DeviceGroup"); return nullptr; }
246 virtual agx::SyncTag *receiveData(void* /*hostBuffer*/, agxData::Buffer* /*Buffer*/, size_t /*offset*/, size_t /*size*/, bool /*blocking*/) override { agxAbort1("DeviceGroup"); return nullptr; }
247
248
249 protected:
250 virtual ~DeviceGroup();
251
252 private:
253 DeviceRef m_primaryDevice;
254 // DeviceRefVector m_devices;
256 DeviceTable m_deviceTable;
257 };
258
259
260 //---------------------------------------------------------------
261
262 /* Implementation */
264 AGX_FORCE_INLINE const String& Device::getTypeName() const { return m_typeName; }
266
267 // AGX_FORCE_INLINE Device *DeviceGroup::getPrimaryDevice() { return m_primaryDevice; }
268}
269
270#ifdef _MSC_VER
271# pragma warning(pop)
272#endif
273
#define AGX_DECLARE_POINTER_TYPES(type)
Definition Referenced.h:254
#define AGXCORE_EXPORT
Abstract representation of a data buffer.
Definition Buffer.h:56
A format is an implementation of a agxData::Type.
Definition Format.h:64
Abstracted type.
Definition Type.h:98
A component is an object containing other objects, enabling hierarchical structuring.
Definition Component.h:39
virtual Status getStatus() override
Definition Device.h:186
virtual Status wait() override
Definition Device.h:185
Representation of the CPU.
Definition Device.h:180
virtual ~CpuDevice()
void wait(bool passive=false)
virtual agxData::Buffer * createBuffer(agxData::Format *format) override
void enqueue(Task *task)
static CpuDevice * instance()
virtual agx::SyncTag * receiveData(void *hostBuffer, agxData::Buffer *buffer, size_t offset, size_t size, bool blocking) override
Receive data from a buffer on the device.
virtual agx::SyncTag * sendData(const void *hostBuffer, agxData::Buffer *buffer, size_t offset, size_t size, bool blocking) override
Send data to a buffer on the device.
A device group contain other devices, enables hierarchical device structuring.
Definition Device.h:227
Device * getPrimaryDevice()
virtual ~DeviceGroup()
DeviceGroup(const Name &name, Device *primaryDevice)
Device * getOrCreateDevice(Type deviceType)
virtual agx::SyncTag * sendData(const void *, agxData::Buffer *, size_t, size_t, bool) override
Send data to a buffer on the device.
Definition Device.h:245
virtual agxData::Buffer * createBuffer(agxData::Format *) override
Definition Device.h:243
void setPrimaryDevice(Device *device)
virtual agx::SyncTag * receiveData(void *, agxData::Buffer *, size_t, size_t, bool) override
Receive data from a buffer on the device.
Definition Device.h:246
An agx::Device is an abstract representation of a device on which data can be stored and processed.
Definition Device.h:58
static Device * load(TiXmlElement *eDevice, Device *device)
virtual agxData::Buffer * createBuffer(agxData::Format *format)=0
virtual agx::SyncTag * receiveData(void *hostBuffer, agxData::Buffer *Buffer, size_t offset, size_t size, bool blocking)=0
Receive data from a buffer on the device.
Type getType() const
Definition Device.h:263
virtual void destroyCallback(agx::Object *object) override
agxData::Buffer * getBuffer(agxData::Buffer *buffer)
void setTypeFormat(const agx::String &typeName, const agx::String &formatName)
Type
Explicit list of device types.
Definition Device.h:76
@ NUM_COMPUTE_DEVICES
Definition Device.h:84
@ REMOTE_HOST
Definition Device.h:87
ByteOrder
Device dependent byte order, AGX prefix to avoid clash with macro definitions.
Definition Device.h:68
@ AGX_LITTLE_ENDIAN
Definition Device.h:69
@ AGX_BIG_ENDIAN
Definition Device.h:70
virtual ~Device()
static agx::Model * ClassModel()
void setByteOrder(ByteOrder byteOrder)
const agx::String & getTypeName() const
Definition Device.h:264
agxData::Buffer * createBuffer(agxData::Type *type)
agxData::Format * getTypeFormat(agxData::Type *type)
void setTypeFormat(agxData::Type *type, agxData::Format *format)
Set the type format for a specific type.
virtual agx::SyncTag * sendData(const void *hostBuffer, agxData::Buffer *Buffer, size_t offset, size_t size, bool blocking)=0
Send data to a buffer on the device.
ByteOrder getByteOrder() const
Definition Device.h:265
Device(const agx::Name &name, Type type, const agx::String &typeName, ByteOrder byteOrder=UNDEFINED)
Constructor.
Inheritance with partial specialization due to bug with ref_ptr containers.
Memory pool.
Definition MemoryPool.h:89
A model is an abstract representation of the class of an agx::Object.
Definition Model.h:41
Representation of a name string.
Definition Name.h:33
agx::Object is a refcounted object with a name.
Definition Object.h:59
A representation of a generic task.
Definition Task.h:58
#define agxAbort1(msg)
Definition debug.h:165
#define AGX_FORCE_INLINE
Definition macros.h:58
The agx namespace contains the dynamics/math part of the AGX Dynamics API.