device.h (2020-10-27 00:11:00 -0400, (build d99887ae))
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  * https://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 
122  AF_DEPRECATED("Use af::allocV2 instead")
123  AFAPI void *alloc(const size_t elements, const dtype type);
124 
125 #if AF_API_VERSION >= 38
126  AFAPI void *allocV2(const size_t bytes);
136 #endif
137 
139  //
154  template <typename T>
155  AF_DEPRECATED("Use af::allocV2 instead")
156  T *alloc(const size_t elements);
158 
170  AF_DEPRECATED("Use af::freeV2 instead")
171  AFAPI void free(const void *ptr);
172 
173 #if AF_API_VERSION >= 38
174  AFAPI void freeV2(const void *ptr);
181 #endif
182 
190  AFAPI void *pinned(const size_t elements, const dtype type);
191 
196  template<typename T>
197  T* pinned(const size_t elements);
199 
204  AFAPI void freePinned(const void *ptr);
205 
206 #if AF_API_VERSION >= 33
207  AFAPI void *allocHost(const size_t elements, const dtype type);
217 #endif
218 
219 #if AF_API_VERSION >= 33
220  template<typename T>
232  AFAPI T* allocHost(const size_t elements);
233 #endif
234 
235 #if AF_API_VERSION >= 33
236  //
243  AFAPI void freeHost(const void *ptr);
244 #endif
245 
251  // manager
253  // manager
258  AFAPI void deviceMemInfo(size_t *alloc_bytes, size_t *alloc_buffers,
259  size_t *lock_bytes, size_t *lock_buffers);
260 
261 #if AF_API_VERSION >= 33
262  //
268  //
272  AFAPI void printMemInfo(const char *msg = NULL, const int device_id = -1);
273 #endif
274 
278  AFAPI void deviceGC();
280 
285  AFAPI void setMemStepSize(const size_t size);
286 
291  AFAPI size_t getMemStepSize();
292 }
293 #endif
294 
295 #ifdef __cplusplus
296 extern "C" {
297 #endif
298 
302  AFAPI af_err af_info();
303 
307  AFAPI af_err af_init();
308 
317  AFAPI af_err af_info_string(char** str, const bool verbose);
318 
324  AFAPI af_err af_device_info(char* d_name, char* d_platform, char *d_toolkit, char* d_compute);
325 
329  AFAPI af_err af_get_device_count(int *num_of_devices);
330 
334  AFAPI af_err af_get_dbl_support(bool* available, const int device);
335 
339  AFAPI af_err af_get_half_support(bool *available, const int device);
340 
344  AFAPI af_err af_set_device(const int device);
345 
349  AFAPI af_err af_get_device(int *device);
350 
354  AFAPI af_err af_sync(const int device);
355 
375  AF_DEPRECATED("Use af_alloc_device_v2 instead")
376  AFAPI af_err af_alloc_device(void **ptr, const dim_t bytes);
377 
390  AF_DEPRECATED("Use af_free_device_v2 instead")
391  AFAPI af_err af_free_device(void *ptr);
392 
393 #if AF_API_VERSION >= 38
394 
410  AFAPI af_err af_alloc_device_v2(void **ptr, const dim_t bytes);
411 
423  AFAPI af_err af_free_device_v2(void *ptr);
424 #endif
425 
428  AFAPI af_err af_alloc_pinned(void **ptr, const dim_t bytes);
429 
433  AFAPI af_err af_free_pinned(void *ptr);
434 
435 #if AF_API_VERSION >= 33
436 
439  AFAPI af_err af_alloc_host(void **ptr, const dim_t bytes);
440 #endif
441 
442 #if AF_API_VERSION >= 33
443 
446  AFAPI af_err af_free_host(void *ptr);
447 #endif
448 
453  AFAPI af_err af_device_array(af_array *arr, void *data, const unsigned ndims, const dim_t * const dims, const af_dtype type);
454 
459  AFAPI af_err af_device_mem_info(size_t *alloc_bytes, size_t *alloc_buffers,
460  size_t *lock_bytes, size_t *lock_buffers);
461 
462 #if AF_API_VERSION >= 33
463 
485  AFAPI af_err af_print_mem_info(const char *msg, const int device_id);
486 #endif
487 
493 
500  AFAPI af_err af_set_mem_step_size(const size_t step_bytes);
501 
508  AFAPI af_err af_get_mem_step_size(size_t *step_bytes);
509 
510 #if AF_API_VERSION >= 31
511 
517 #if AF_API_VERSION >= 33
518  AF_DEPRECATED("Use af_lock_array instead")
519 #endif
521 #endif
522 
523 #if AF_API_VERSION >= 31
524 
530 #if AF_API_VERSION >= 33
531  AF_DEPRECATED("Use af_unlock_array instead")
532 #endif
534 #endif
535 
536 #if AF_API_VERSION >= 33
537 
543  AFAPI af_err af_lock_array(const af_array arr);
544 #endif
545 
546 #if AF_API_VERSION >= 33
547 
554 #endif
555 
556 #if AF_API_VERSION >= 34
557 
565  AFAPI af_err af_is_locked_array(bool *res, const af_array arr);
566 #endif
567 
576  AFAPI af_err af_get_device_ptr(void **ptr, const af_array arr);
577 
578 #if AF_API_VERSION >= 38
579 
596  AFAPI af_err af_set_kernel_cache_directory(const char* path,
597  int override_env);
598 
618  AFAPI af_err af_get_kernel_cache_directory(size_t *length, char *path);
619 
620 #endif
621 
622 #ifdef __cplusplus
623 }
624 #endif
AFAPI af_err af_set_kernel_cache_directory(const char *path, int override_env)
Sets the path where the kernels generated at runtime will be cached.
AFAPI void freeV2(const void *ptr)
Returns memory to ArrayFire&#39;s memory manager.
AFAPI af_err af_alloc_host(void **ptr, const dim_t bytes)
AFAPI void freePinned(const void *ptr)
Free pinned memory allocated by ArrayFire&#39;s memory manager.
Definition: algorithm.h:14
AFAPI af_err af_sync(const int device)
AFAPI void freeHost(const void *ptr)
Free memory allocated internally by ArrayFire.
AFAPI af_err af_init()
AFAPI af_err af_get_device_ptr(void **ptr, const af_array arr)
Get the device pointer and lock the buffer in memory manager.
AFAPI af_err af_device_gc()
Call the garbage collection routine.
AFAPI void * pinned(const size_t elements, const dtype type)
Allocate pinned memory using ArrayFire&#39;s memory manager.
AFAPI af_err af_free_device(void *ptr)
Returns memory to ArrayFire&#39;s memory manager.
AFAPI size_t getMemStepSize()
Get the resolution of memory chunks.
#define AF_DEPRECATED(msg)
Definition: defines.h:44
AFAPI void info()
AFAPI af_err af_is_locked_array(bool *res, const af_array arr)
Query if the array has been locked by the user.
AFAPI af_err af_free_device_v2(void *ptr)
Returns memory to ArrayFire&#39;s memory manager.
AFAPI af_err af_set_device(const int device)
AFAPI af_err af_alloc_pinned(void **ptr, const dim_t bytes)
AFAPI af_err af_info_string(char **str, const bool verbose)
Gets the output of af_info() as a string.
AFAPI af_err af_info()
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.
AFAPI af_err af_unlock_array(const af_array arr)
Unlock device buffer in the memory manager.
AFAPI void deviceGC()
Call the garbage collection function in the memory manager.
AFAPI af_err af_alloc_device(void **ptr, const dim_t bytes)
Allocates memory using ArrayFire&#39;s memory managerThis device memory returned by this function can onl...
AFAPI void setMemStepSize(const size_t size)
Set the resolution of memory chunks.
AFAPI af_err af_get_kernel_cache_directory(size_t *length, char *path)
Gets the path where the kernels generated at runtime will be cached.
af_err
Definition: defines.h:71
AFAPI af_err af_free_host(void *ptr)
AFAPI bool isHalfAvailable(const int device)
Queries the current device for half precision floating point support.
AFAPI const char * infoString(const bool verbose=false)
AFAPI void * allocHost(const size_t elements, const dtype type)
Allocate memory on host.
long long dim_t
Definition: defines.h:56
AFAPI af_err af_get_mem_step_size(size_t *step_bytes)
Get the minimum memory chunk size.
AFAPI af_err af_get_device_count(int *num_of_devices)
AFAPI af_err af_alloc_device_v2(void **ptr, const dim_t bytes)
Allocates memory using ArrayFire&#39;s memory manager.
#define AFAPI
Definition: defines.h:38
AFAPI void printMemInfo(const char *msg=NULL, const int device_id=-1)
Prints buffer details from the ArrayFire Device Manager.
AFAPI void sync(const int device=-1)
Blocks until the device is finished processing.
AFAPI af_err af_free_pinned(void *ptr)
AFAPI af_err af_get_half_support(bool *available, const int device)
AFAPI void free(const void *ptr)
Returns memory to ArrayFire&#39;s memory manager.
AFAPI af_err af_lock_device_ptr(const af_array arr)
Lock the device buffer in the memory manager.
AFAPI af_err af_set_mem_step_size(const size_t step_bytes)
Set the minimum memory chunk size.
AFAPI bool isDoubleAvailable(const int device)
Queries the current device for double precision floating point support.
AFAPI af_err af_unlock_device_ptr(const af_array arr)
Unlock device buffer in the memory manager.
AFAPI void deviceInfo(char *d_name, char *d_platform, char *d_toolkit, char *d_compute)
Gets the information about device and platform as strings.
AFAPI af_err af_get_device(int *device)
void * af_array
Definition: defines.h:240
AFAPI void * alloc(const size_t elements, const dtype type)
Allocates memory using ArrayFire&#39;s memory manager.
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.
AFAPI af_err af_get_dbl_support(bool *available, const int device)
AFAPI int getDeviceCount()
Gets the number of devices.
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.
AFAPI af_err af_print_mem_info(const char *msg, const int device_id)
Prints buffer details from the ArrayFire Device Manager.
af_dtype
Definition: defines.h:210
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.
AFAPI af_err af_lock_array(const af_array arr)
Lock the device buffer in the memory manager.
af_dtype dtype
Definition: defines.h:549
AFAPI void setDevice(const int device)
Sets the current device.
AFAPI int getDevice()
Gets the current device ID.
AFAPI void * allocV2(const size_t bytes)
Allocates memory using ArrayFire&#39;s memory manager.