Defines | |
#define | print(exp) |
Show expression and its contents. | |
Functions | |
void | disp (const array exp, const char *expstr=NULL) |
Display the value of a variable (see print) | |
template<typename T > | |
T | scalar () const |
Returns host-side scalar of first component of data. | |
template<typename T > | |
T * | device () const |
Device-side pointer to matrix data. | |
template<typename T > | |
T * | host () const |
Host-side pointer to matrix data. | |
template<typename T > | |
static void | hostFree (const T *) |
Releases host-side memory allocated for data by host() |
#define print | ( | exp | ) |
Show expression and its contents.
Example:
produces
A + 1 = 1.23423 1.83285 1.03472 1.64273
T scalar | ( | ) | const [inherited] |
Returns host-side scalar of first component of data.
No need to call unlock() afterward.
void af::disp | ( | const array | exp, |
const char * | expstr = NULL |
||
) |
Display the value of a variable (see print)
T* device | ( | ) | const [inherited] |
Device-side pointer to matrix data.
No need to free this, but unlock() when finished to allow garbage collection.
array A = randu(n); float *d_A = A.device<float>(); custom_kernel<<<blocks,threads>>>(A.elements(), d_A); A.unlock(); // finished
This function does not implement copy-on-write semantics when another array points to same data. Since memory returned by this call may be modified at any point, other arrays sharing this device memory are in danger of modification without copy-on-write semantics. The following example demonstrates how A
is modified inadvertantly.
array A = ones(n); array B = A; // B and A point to same memory float *d_A = A.device<float>(); cudaMemset(d_A, 0, A.bytes()); print(B); // all zeros since pointed to same memory
Use copy() to manually create copies
array A = ones(n); array B = copy(A); // B,A point to different areas but same contents float *d_A = A.device<float>(); cudaMemset(d_A, 0, A.bytes()); print(B); // all ones
T* host | ( | ) | const [inherited] |
Host-side pointer to matrix data.
Call hostFree() when done to allow garbage collection. Modification of this data has no effect on device copy.
array A = randu(5); float *h_A = A.host<float>(); float firstval = h_A[1]; // grab second value array::hostFree(h_A); // finished
static void hostFree | ( | const T * | ) | [static, inherited] |
Releases host-side memory allocated for data by host()