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 
81  AFAPI bool isDoubleAvailable(const int device);
82 
91  AFAPI bool isHalfAvailable(const int device);
92 
97  AFAPI void setDevice(const int device);
98 
103  AFAPI void sync(const int device = -1);
104 
115 
116  AFAPI void *alloc(const size_t elements, const dtype type);
117 
119  //
128  template<typename T>
129  T* alloc(const size_t elements);
131 
138  AFAPI void free(const void *ptr);
139 
148  AFAPI void *pinned(const size_t elements, const dtype type);
149 
154  template<typename T>
155  T* pinned(const size_t elements);
157 
162  AFAPI void freePinned(const void *ptr);
163 
164 #if AF_API_VERSION >= 33
165  AFAPI void *allocHost(const size_t elements, const dtype type);
175 #endif
176 
177 #if AF_API_VERSION >= 33
178  template<typename T>
190  AFAPI T* allocHost(const size_t elements);
191 #endif
192 
193 #if AF_API_VERSION >= 33
194  //
201  AFAPI void freeHost(const void *ptr);
202 #endif
203 
209  // manager
211  // manager
216  AFAPI void deviceMemInfo(size_t *alloc_bytes, size_t *alloc_buffers,
217  size_t *lock_bytes, size_t *lock_buffers);
218 
219 #if AF_API_VERSION >= 33
220  //
226  //
230  AFAPI void printMemInfo(const char *msg = NULL, const int device_id = -1);
231 #endif
232 
236  AFAPI void deviceGC();
238 
242  AFAPI void setMemStepSize(const size_t size);
243 
247  AFAPI size_t getMemStepSize();
248 }
249 #endif
250 
251 #ifdef __cplusplus
252 extern "C" {
253 #endif
254 
258  AFAPI af_err af_info();
259 
263  AFAPI af_err af_init();
264 
273  AFAPI af_err af_info_string(char** str, const bool verbose);
274 
280  AFAPI af_err af_device_info(char* d_name, char* d_platform, char *d_toolkit, char* d_compute);
281 
285  AFAPI af_err af_get_device_count(int *num_of_devices);
286 
290  AFAPI af_err af_get_dbl_support(bool* available, const int device);
291 
295  AFAPI af_err af_get_half_support(bool *available, const int device);
296 
300  AFAPI af_err af_set_device(const int device);
301 
305  AFAPI af_err af_get_device(int *device);
306 
310  AFAPI af_err af_sync(const int device);
311 
318  AFAPI af_err af_alloc_device(void **ptr, const dim_t bytes);
319 
326  AFAPI af_err af_free_device(void *ptr);
327 
331  AFAPI af_err af_alloc_pinned(void **ptr, const dim_t bytes);
332 
336  AFAPI af_err af_free_pinned(void *ptr);
337 
338 #if AF_API_VERSION >= 33
339 
342  AFAPI af_err af_alloc_host(void **ptr, const dim_t bytes);
343 #endif
344 
345 #if AF_API_VERSION >= 33
346 
349  AFAPI af_err af_free_host(void *ptr);
350 #endif
351 
356  AFAPI af_err af_device_array(af_array *arr, void *data, const unsigned ndims, const dim_t * const dims, const af_dtype type);
357 
362  AFAPI af_err af_device_mem_info(size_t *alloc_bytes, size_t *alloc_buffers,
363  size_t *lock_bytes, size_t *lock_buffers);
364 
365 #if AF_API_VERSION >= 33
366 
388  AFAPI af_err af_print_mem_info(const char *msg, const int device_id);
389 #endif
390 
396 
401  AFAPI af_err af_set_mem_step_size(const size_t step_bytes);
402 
407  AFAPI af_err af_get_mem_step_size(size_t *step_bytes);
408 
409 #if AF_API_VERSION >= 31
410 
416 #if AF_API_VERSION >= 33
417  AF_DEPRECATED("Use af_lock_array instead")
418 #endif
420 #endif
421 
422 #if AF_API_VERSION >= 31
423 
429 #if AF_API_VERSION >= 33
430  AF_DEPRECATED("Use af_unlock_array instead")
431 #endif
433 #endif
434 
435 #if AF_API_VERSION >= 33
436 
442  AFAPI af_err af_lock_array(const af_array arr);
443 #endif
444 
445 #if AF_API_VERSION >= 33
446 
453 #endif
454 
455 #if AF_API_VERSION >= 34
456 
464  AFAPI af_err af_is_locked_array(bool *res, const af_array arr);
465 #endif
466 
475  AFAPI af_err af_get_device_ptr(void **ptr, const af_array arr);
476 
477 
478 #ifdef __cplusplus
479 }
480 #endif
af_info_string
AFAPI af_err af_info_string(char **str, const bool verbose)
Gets the output of af_info() as a string.
af_set_device
AFAPI af_err af_set_device(const int device)
af_get_mem_step_size
AFAPI af_err af_get_mem_step_size(size_t *step_bytes)
Get the minimum memory chunk size.
af::isHalfAvailable
AFAPI bool isHalfAvailable(const int device)
Queries the current device for half precision floating point support.
dim_t
long long dim_t
Definition: defines.h:56
af::info
AFAPI void info()
af::deviceGC
AFAPI void deviceGC()
Call the garbage collection function in the memory manager.
af::setDevice
AFAPI void setDevice(const int device)
Sets the current device.
af::getDevice
AFAPI int getDevice()
Gets the current device ID.
af::dtype
af_dtype dtype
Definition: defines.h:549
AFAPI
#define AFAPI
Definition: defines.h:38
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
Definition: algorithm.h:14
af::freePinned
AFAPI void freePinned(const void *ptr)
Free pinned memory allocated by ArrayFire's 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_unlock_device_ptr
AFAPI af_err af_unlock_device_ptr(const af_array arr)
Unlock device buffer in the memory manager.
af_get_half_support
AFAPI af_err af_get_half_support(bool *available, const int device)
af_array
void * af_array
Definition: defines.h:240
af_alloc_host
AFAPI af_err af_alloc_host(void **ptr, const dim_t bytes)
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_lock_device_ptr
AFAPI af_err af_lock_device_ptr(const af_array arr)
Lock the device buffer in 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_lock_array
AFAPI af_err af_lock_array(const af_array arr)
Lock the device buffer in the memory manager.
af::getDeviceCount
AFAPI int getDeviceCount()
Gets the number of devices.
af_free_host
AFAPI af_err af_free_host(void *ptr)
af_dtype
af_dtype
Definition: defines.h:210
af::allocHost
AFAPI void * allocHost(const size_t elements, const dtype type)
Allocate memory on host.
af_init
AFAPI af_err af_init()
af::free
AFAPI void free(const void *ptr)
Free device memory allocated by ArrayFire'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_free_pinned
AFAPI af_err af_free_pinned(void *ptr)
af::isDoubleAvailable
AFAPI bool isDoubleAvailable(const int device)
Queries the current device for double precision floating point support.
af_get_device
AFAPI af_err af_get_device(int *device)
af_alloc_device
AFAPI af_err af_alloc_device(void **ptr, const dim_t bytes)
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::freeHost
AFAPI void freeHost(const void *ptr)
Free memory allocated internally by ArrayFire.
AF_DEPRECATED
#define AF_DEPRECATED(msg)
Definition: defines.h:44
af_get_dbl_support
AFAPI af_err af_get_dbl_support(bool *available, const int device)
af_get_device_count
AFAPI af_err af_get_device_count(int *num_of_devices)
af::sync
AFAPI void sync(const int device=-1)
Blocks until the device is finished processing.
af::setMemStepSize
AFAPI void setMemStepSize(const size_t size)
Set the resolution of memory chunks.
af_alloc_pinned
AFAPI af_err af_alloc_pinned(void **ptr, const dim_t bytes)
af::alloc
AFAPI void * alloc(const size_t elements, const dtype type)
Allocates memory using ArrayFire's memory manager.
af::getMemStepSize
AFAPI size_t getMemStepSize()
Get the resolution of memory chunks.
af::pinned
AFAPI void * pinned(const size_t elements, const dtype type)
Allocate pinned memory using ArrayFire's memory manager.
af::infoString
const AFAPI char * infoString(const bool verbose=false)
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_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_device_array
AFAPI af_err af_device_array(af_array *arr, void *data, const unsigned ndims, const dim_t *const dims, const af_dtype type)
Create array from device memory.
af_err
af_err
Definition: defines.h:71
af_unlock_array
AFAPI af_err af_unlock_array(const af_array arr)
Unlock device buffer in the memory manager.
defines.h
af::printMemInfo
AFAPI void printMemInfo(const char *msg=NULL, const int device_id=-1)
Prints buffer details from the ArrayFire Device Manager.
af_info
AFAPI af_err af_info()
af_free_device
AFAPI af_err af_free_device(void *ptr)
af_sync
AFAPI af_err af_sync(const int device)