device.h Source File

device.h
Go to the documentation of this file.
1 /*******************************************************
2 * Copyright (c) 2014, ArrayFire
3 * All rights reserved.
4 *
5 * This file is distributed under 3-clause BSD license.
6 * The complete license agreement can be obtained at:
7 * http://arrayfire.com/licenses/BSD-3-Clause
8 ********************************************************/
9
10 #pragma once
11 #include <af/defines.h>
12
13 #ifdef __cplusplus
14 namespace af
15 {
26 AFAPI void info();
47 AFAPI const char* infoString(const bool verbose = false);
57 AFAPI void deviceInfo(char* d_name, char* d_platform, char *d_toolkit, char* d_compute);
58
64 AFAPI int getDeviceCount();
65
71 AFAPI int getDevice();
72
80 AFAPI bool isDoubleAvailable(const int device);
81
86 AFAPI void setDevice(const int device);
87
92 AFAPI void sync(const int device = -1);
93
104
105 AFAPI void *alloc(const size_t elements, const dtype type);
106
108 //
117 template<typename T>
118 T* alloc(const size_t elements);
120
127 AFAPI void free(const void *ptr);
128
137 AFAPI void *pinned(const size_t elements, const dtype type);
138
143 template<typename T>
144 T* pinned(const size_t elements);
146
151 AFAPI void freePinned(const void *ptr);
152
153 #if AF_API_VERSION >= 33
154 AFAPI void *allocHost(const size_t elements, const dtype type);
164 #endif
165
166 #if AF_API_VERSION >= 33
167 template<typename T>
179 AFAPI T* allocHost(const size_t elements);
180 #endif
181
182 #if AF_API_VERSION >= 33
183 //
190 AFAPI void freeHost(const void *ptr);
191 #endif
192
198 // manager
200 // manager
205 AFAPI void deviceMemInfo(size_t *alloc_bytes, size_t *alloc_buffers,
206 size_t *lock_bytes, size_t *lock_buffers);
207
208 #if AF_API_VERSION >= 33
209 //
215 //
219 AFAPI void printMemInfo(const char *msg = NULL, const int device_id = -1);
220 #endif
221
225 AFAPI void deviceGC();
227
231 AFAPI void setMemStepSize(const size_t size);
232
236 AFAPI size_t getMemStepSize();
237 }
238 #endif
239
240 #ifdef __cplusplus
241 extern "C" {
242 #endif
243
247 AFAPI af_err af_info();
248
252 AFAPI af_err af_init();
253
262 AFAPI af_err af_info_string(char** str, const bool verbose);
263
269 AFAPI af_err af_device_info(char* d_name, char* d_platform, char *d_toolkit, char* d_compute);
270
274 AFAPI af_err af_get_device_count(int *num_of_devices);
275
279 AFAPI af_err af_get_dbl_support(bool* available, const int device);
280
284 AFAPI af_err af_set_device(const int device);
285
289 AFAPI af_err af_get_device(int *device);
290
294 AFAPI af_err af_sync(const int device);
295
301 AFAPI af_err af_alloc_device(void **ptr, const dim_t bytes);
302
308 AFAPI af_err af_free_device(void *ptr);
309
313 AFAPI af_err af_alloc_pinned(void **ptr, const dim_t bytes);
314
318 AFAPI af_err af_free_pinned(void *ptr);
319
320 #if AF_API_VERSION >= 33
321
324 AFAPI af_err af_alloc_host(void **ptr, const dim_t bytes);
325 #endif
326
327 #if AF_API_VERSION >= 33
328
331 AFAPI af_err af_free_host(void *ptr);
332 #endif
333
338 AFAPI af_err af_device_array(af_array *arr, const void *data, const unsigned ndims, const dim_t * const dims, const af_dtype type);
339
344 AFAPI af_err af_device_mem_info(size_t *alloc_bytes, size_t *alloc_buffers,
345 size_t *lock_bytes, size_t *lock_buffers);
346
347 #if AF_API_VERSION >= 33
348 //
359 AFAPI af_err af_print_mem_info(const char *msg, const int device_id);
360 #endif
361
366 AFAPI af_err af_device_gc();
367
372 AFAPI af_err af_set_mem_step_size(const size_t step_bytes);
373
378 AFAPI af_err af_get_mem_step_size(size_t *step_bytes);
379
380 #if AF_API_VERSION >= 31
381
387 #if AF_API_VERSION >= 33
388 DEPRECATED("Use af_lock_array instead")
389 #endif
390 AFAPI af_err af_lock_device_ptr(const af_array arr);
391 #endif
392
393 #if AF_API_VERSION >= 31
394
400 #if AF_API_VERSION >= 33
401 DEPRECATED("Use af_unlock_array instead")
402 #endif
403 AFAPI af_err af_unlock_device_ptr(const af_array arr);
404 #endif
405
406 #if AF_API_VERSION >= 33
407
413 AFAPI af_err af_lock_array(const af_array arr);
414 #endif
415
416 #if AF_API_VERSION >= 33
417
423 AFAPI af_err af_unlock_array(const af_array arr);
424 #endif
425
426 #if AF_API_VERSION >= 34
427
435 AFAPI af_err af_is_locked_array(bool *res, const af_array arr);
436 #endif
437
446 AFAPI af_err af_get_device_ptr(void **ptr, const af_array arr);
447
448
449 #ifdef __cplusplus
450 }
451 #endif
af_alloc_host
AFAPI af_err af_alloc_host(void **ptr, const dim_t bytes)
af::freePinned
AFAPI void freePinned(const void *ptr)
Free pinned memory allocated by ArrayFire&#39;s memory manager.
af
Definition: algorithm.h:14
af_sync
AFAPI af_err af_sync(const int device)
af::freeHost
AFAPI void freeHost(const void *ptr)
Free memory allocated internally by ArrayFire.
af_init
AFAPI af_err af_init()
af_get_device_ptr
AFAPI af_err af_get_device_ptr(void **ptr, const af_array arr)
Get the device pointer and lock the buffer in memory manager.
af_device_gc
AFAPI af_err af_device_gc()
Call the garbage collection routine.
af::pinned
AFAPI void * pinned(const size_t elements, const dtype type)
Allocate pinned memory using ArrayFire&#39;s memory manager.
af_free_device
AFAPI af_err af_free_device(void *ptr)
This function will free a device pointer even if it has been previously locked.
af::getMemStepSize
AFAPI size_t getMemStepSize()
Get the resolution of memory chunks.
af::info
AFAPI void info()
af_is_locked_array
AFAPI af_err af_is_locked_array(bool *res, const af_array arr)
Query if the array has been locked by the user.
af_set_device
AFAPI af_err af_set_device(const int device)
af_alloc_pinned
AFAPI af_err af_alloc_pinned(void **ptr, const dim_t bytes)
af_info_string
AFAPI af_err af_info_string(char **str, const bool verbose)
Gets the output of af_info() as a string.
af_info
AFAPI af_err af_info()
af_unlock_array
AFAPI af_err af_unlock_array(const af_array arr)
Unlock device buffer in the memory manager.
af::deviceGC
AFAPI void deviceGC()
Call the garbage collection function in the memory manager.
af_alloc_device
AFAPI af_err af_alloc_device(void **ptr, const dim_t bytes)
This device memory returned by this function can only be freed using af_free_device.
af::setMemStepSize
AFAPI void setMemStepSize(const size_t size)
Set the resolution of memory chunks.
af_err
af_err
Definition: defines.h:63
af_free_host
AFAPI af_err af_free_host(void *ptr)
DEPRECATED
#define DEPRECATED(msg)
Definition: defines.h:37
defines.h
af::infoString
AFAPI const char * infoString(const bool verbose=false)
af::allocHost
AFAPI void * allocHost(const size_t elements, const dtype type)
Allocate memory on host.
dim_t
long long dim_t
Definition: defines.h:50
af_get_mem_step_size
AFAPI af_err af_get_mem_step_size(size_t *step_bytes)
Get the minimum memory chunk size.
af_get_device_count
AFAPI af_err af_get_device_count(int *num_of_devices)
AFAPI
#define AFAPI
Definition: defines.h:31
af::printMemInfo
AFAPI void printMemInfo(const char *msg=NULL, const int device_id=-1)
Prints buffer details from the ArrayFire Device Manager.
af::sync
AFAPI void sync(const int device=-1)
Blocks until the device is finished processing.
af_free_pinned
AFAPI af_err af_free_pinned(void *ptr)
af::free
AFAPI void free(const void *ptr)
Free device memory allocated by ArrayFire&#39;s memory manager.
af_lock_device_ptr
AFAPI af_err af_lock_device_ptr(const af_array arr)
Lock the device buffer in the memory manager.
af_set_mem_step_size
AFAPI af_err af_set_mem_step_size(const size_t step_bytes)
Set the minimum memory chunk size.
af::isDoubleAvailable
AFAPI bool isDoubleAvailable(const int device)
Queries the current device for double precision floating point support.
af_unlock_device_ptr
AFAPI af_err af_unlock_device_ptr(const af_array arr)
Unlock device buffer in the memory manager.
af::deviceInfo
AFAPI void deviceInfo(char *d_name, char *d_platform, char *d_toolkit, char *d_compute)
Gets the information about device and platform as strings.
af_device_array
AFAPI af_err af_device_array(af_array *arr, const void *data, const unsigned ndims, const dim_t *const dims, const af_dtype type)
Create array from device memory.
af_get_device
AFAPI af_err af_get_device(int *device)
af_array
void * af_array
Definition: defines.h:222
af::alloc
AFAPI void * alloc(const size_t elements, const dtype type)
Allocates memory using ArrayFire&#39;s memory manager.
af::deviceMemInfo
AFAPI void deviceMemInfo(size_t *alloc_bytes, size_t *alloc_buffers, size_t *lock_bytes, size_t *lock_buffers)
Gets information about the memory manager.
af_get_dbl_support
AFAPI af_err af_get_dbl_support(bool *available, const int device)
af::getDeviceCount
AFAPI int getDeviceCount()
Gets the number of devices.
af_device_mem_info
AFAPI af_err af_device_mem_info(size_t *alloc_bytes, size_t *alloc_buffers, size_t *lock_bytes, size_t *lock_buffers)
Get memory information from the memory manager.
af_print_mem_info
AFAPI af_err af_print_mem_info(const char *msg, const int device_id)
Prints buffer details from the ArrayFire Device Manager.
af_dtype
af_dtype
Definition: defines.h:195
af_device_info
AFAPI af_err af_device_info(char *d_name, char *d_platform, char *d_toolkit, char *d_compute)
Gets the information about device and platform as strings.
af_lock_array
AFAPI af_err af_lock_array(const af_array arr)
Lock the device buffer in the memory manager.
af::dtype
af_dtype dtype
Definition: defines.h:468
af::setDevice
AFAPI void setDevice(const int device)
Sets the current device.
af::getDevice
AFAPI int getDevice()
Gets the current device ID.