Hi, I can build and run a C++ example and get the expected output. However when I try to translate this to use the C API, I get an error.
This C++ code works:
$ cat main.c
#include<arrayfire.h>
int main(void) {
af::array M1 = af::randu(2,4);
af::array M2 = af::randu(4,1);
af::array result = af::matmul(M1, M2);
af_print(result);
}
$ g++ -std=c++11 main.cpp -I/opt/arrayfire/include -lafcpu -L/opt/arrayfire/lib64
$ ./a.out
result
[2 1 1 1]
0.9704
0.3218
I attempted to translate this into a C API version. It compiles, but the print function produces "208" error (AF_ERR_DEVICE). What causes this error and how can I fix it?
Below is the C version, compile command, and output:
$ cat main.c
#include<arrayfire.h>
#include<stdio.h>
int main() {
af_array M1, M2, result;
dim_t d1[] = {2, 4};
dim_t d2[] = {4, 1};
if (AF_SUCCESS != af_randu(&M1, 2, d1, f64)) return 1;
if (AF_SUCCESS != af_randu(&M2, 2, d2, f64)) return 1;
if (AF_SUCCESS != af_matmul(&result, M1, M2, AF_MAT_NONE, AF_MAT_NONE)) return 1;
printf("before\n");
printf("%d\n", af_print_array(&result));
printf("after\n");
return 0;
}
$ gcc -std=c11 main.c -I/opt/arrayfire/include -lafcpu -L/opt/arrayfire/lib64
$ ./a.out
Thanks in advance!