2 Copyright (c) 2012 Advanced Micro Devices, Inc.
4 This software is provided 'as-is', without any express or implied warranty.
5 In no event will the authors be held liable for any damages arising from the use of this software.
6 Permission is granted to anyone to use this software for any purpose,
7 including commercial applications, and to alter it and redistribute it freely,
8 subject to the following restrictions:
10 1. The origin of this software must not be misrepresented; you must not claim that you wrote the original software. If you use this software in a product, an acknowledgment in the product documentation would be appreciated but is not required.
11 2. Altered source versions must be plainly marked as such, and must not be misrepresented as being the original software.
12 3. This notice may not be removed or altered from any source distribution.
14 //Originally written by Takahiro Harada
20 #pragma warning( disable : 4996 )
21 #include <Adl/AdlConfig.h>
22 #include <Adl/AdlError.h>
26 #define max(a,b) (((a) > (b)) ? (a) : (b))
30 #define min(a,b) (((a) < (b)) ? (a) : (b))
86 Config() : m_type(DEVICE_GPU), m_deviceIdx(0), m_vendor(VD_AMD){}
90 DeviceVendor m_vendor;
95 int getNDevices( DeviceType type );
97 static Device* allocate( DeviceType type, Config& cfg );
99 static void deallocate( Device* deviceData );
101 static void waitForCompletion( const Device* deviceData );
104 //==========================
106 //==========================
111 typedef DeviceUtils::Config Config;
113 Device( DeviceType type ) : m_type( type ), m_memoryUsage(0)
117 virtual void* getContext() const { return 0; }
118 virtual void initialize(const Config& cfg){}
119 virtual void release(){}
120 virtual void waitForCompletion() const {}
121 virtual void getDeviceName( char nameOut[128] ) const {}
122 virtual Kernel* getKernel(const char* fileName, const char* funcName, const char* option = NULL, const char* src = NULL, bool cacheKernel = true ) const { ADLASSERT(0); return 0;}
123 virtual unsigned int getUsedMemory() const { return m_memoryUsage; }
126 unsigned int m_memoryUsage;
129 //==========================
131 //==========================
135 // overload each deviceDatas
137 struct Buffer : public BufferBase
142 Buffer(const Device* device, int nElems, BufferType type = BUFFER );
147 void setRawPtr( const Device* device, T* ptr, int size, BufferType type = BUFFER );
149 void allocate(const Device* device, int nElems, BufferType type = BUFFER );
151 void write(T* hostSrcPtr, int nElems, int dstOffsetNElems = 0);
153 void read(T* hostDstPtr, int nElems, int srcOffsetNElems = 0) const;
155 void write(Buffer<T>& src, int nElems);
157 void read(Buffer<T>& dst, int nElems) const;
159 // Buffer<T>& operator = (const Buffer<T>& buffer);
161 int getSize() const { return m_size; }
163 DeviceType getType() const { ADLASSERT( m_device ); return m_device->m_type; }
166 const Device* m_device;
172 bool m_allocated; // todo. move this to a bit
178 template<DeviceType TYPE, bool COPY, typename T>
181 typename Buffer<T>* map(const Device* device, const Buffer<T>* in, int copySize = -1);
183 template<bool COPY, typename T>
186 void unmap( Buffer<T>* native, const Buffer<T>* orig, int copySize = -1 );
189 //==========================
191 //==========================
195 struct HostBuffer : public Buffer<T>
198 HostBuffer():Buffer<T>(){}
200 HostBuffer(const Device* device, int nElems, BufferType type = BUFFER ) : Buffer<T>(device, nElems, type) {}
201 // HostBuffer(const Device* deviceData, T* rawPtr, int nElems);
205 T& operator[](int idx);
207 const T& operator[](int idx) const;
209 T* begin() { return m_ptr; }
212 HostBuffer<T>& operator = (const Buffer<T>& device);
217 #include <Adl/AdlKernel.h>
218 #if defined(ADL_ENABLE_CL)
219 #include <Adl/CL/AdlCL.inl>
221 #if defined(ADL_ENABLE_DX11)
222 #include <Adl/DX11/AdlDX11.inl>
225 #include <Adl/Host/AdlHost.inl>
226 #include <Adl/AdlKernel.inl>
227 #include <Adl/Adl.inl>
230 #include <Adl/AdlStopwatch.h>
232 #include <Adl/Host/AdlStopwatchHost.inl>
233 #include <Adl/AdlStopwatch.inl>