Do more. Code less. Free software for GPU computing.
<scroll to top>

C Device-level Interface

Basic Example

    #include <arrayfire.h>
    // Generate random data and add all the values (Ignore error codes)
    int main(void)
    {
        // generate random values
        int n = 10000;
        float *d_values;
        af_randu_S(&d_values,  n);

        // sum all the values
        float sum;
        af_sum_vector_S(&sum, n, d_values);
        printf("sum: %g\n", sum);
        return 0;
    }

Using the batch parameter

    #include <arrayfire.h>
    // Performs 10 convolutions in parallel (ignore error checking)
    int main(void)
    {
        // generate random values
        int m = 10000; // Length of Signal
        int n = 500;   // Length of Kernel
        int k = 10;    // Number of Signals to convolve

        float *d_signal, *d_filter, *d_result;

        // Generate 'k' random signals each of length m
        af_randu_S(&d_signal, m * k);

        // Generate one random kernel to convolve the signals with
        af_randu_S(&d_filter, n * 1);

        // Allocate space for result
        af_malloc(&d_result, (m + n - 1) * k * sizeof(float));

        // Perform the convolutions
        af_conv_SS(d_result,       // output
                   m, d_signal, k, // Signal size, pointer, number of signals
                   n, d_filter, 1, // Kernel size, pointer, number of kernels
                   1);             // (FULL: 1, SAME: 0, VALID: -1)
        return 0;
    }

See also:

 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Defines