It is a fast software library for GPU computing with a simple API.
Here are a few code snippets to help you get started:
// Display list of OpenCL devices af::info(); // Select the second device (0 base) af::device(1); // Display list again af::info();
sample output:
Arrayfire (OpenCL alpha) Device0: Cayman (in use) Device1: Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz Arrayfire (OpenCL alpha) Device0: Cayman Device1: Intel(R) Core(TM) i7 CPU 920 @ 2.67GHz (in use)
// Input data float input[] = {1.0, 2.0, 3.0, 4.0}; // Push to array array a(input, 2, 2); // Print the array print(a);
output:
a = 1.000000 3.000000 2.000000 4.000000
print(a); // Scalar operations array b = 2.0 * a + 1; print(b); // Array operations print(b - a); // Trigonometric functions array c = sin(b) * sin(b) + cos(b) * cos(b); print(c); // Complex operations array d = complex(a, b); print(d);
output:
a = 1.000000 3.000000 2.000000 4.000000 b = 3.000000 7.000000 5.000000 9.000000 b - a = 2.000000 4.000000 3.000000 5.000000 c = 1.000000 1.000000 1.000000 1.000000 d = 1.000000 + 3.000000i 3.000000 + 7.000000i 2.000000 + 5.000000i 4.000000 + 9.000000i
// Print the input print(d); // Print the transpose print(d.T()); // Print the conjugate transpose print(d.H()); // Print real and imaginary parts print(real(d)); print(imag(d)); // Set dimensions print(setdims(d, 4, 1));
output:
d = 1.000000 + 3.000000i 3.000000 + 7.000000i 2.000000 + 5.000000i 4.000000 + 9.000000i d.T() = 1.000000 + 3.000000i 2.000000 + 5.000000i 3.000000 + 7.000000i 4.000000 + 9.000000i d.H() = 1.000000 - 3.000000i 2.000000 - 5.000000i 3.000000 - 7.000000i 4.000000 - 9.000000i real(d) = 1.000000 3.000000 2.000000 4.000000 imag(d) = 3.000000 7.000000 5.000000 9.000000 setdims(d, 4, 1) = 1.000000 + 3.000000i 2.000000 + 5.000000i 3.000000 + 7.000000i 4.000000 + 9.000000i