I would like to use AMD AOCL sparse library in a C program.
Specifically, I am using aocl library compiled using gcc.
I can build and run the C++ examples in the amd-sparse folder of aocl.
For example "sample_spmv.cpp" builds on my system using:
g++ sample_spmv.cpp -o sample_spmv -I/home/USER/aocl/4.1.0/gcc/include/ -L/home/USER/aocl/4.1.0/gcc/lib/ -L/home/USER/aocl/4.1.0/gcc/lib/libblis-mt.so -L/home/USER/aocl/4.1.0/gcc/lib_LP64/libaoclsparse.so -lflame -lblis-mt -laoclsparse -lm -lstdc++
The problem is that when I try to convert this example to a minimal C example, I get the following compiler errors:
gcc -Wall -c "min_ex.c" -I/home/USER/aocl/4.1.0/gcc/include/ -L/home/USER/aocl/4.1.0/gcc/lib/ -lflame -lblis-mt -lm -lstdc++
In file included from /home/USER/aocl/4.1.0/gcc/include/aoclsparse.h:45,
from min_ex.c:2:
/home/USER/aocl/4.1.0/gcc/include/aoclsparse_auxiliary.h:275:63: error: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token
275 | aoclsparse_status aoclsparse_create_scsr(aoclsparse_matrix &mat,
| ^
/home/USER/aocl/4.1.0/gcc/include/aoclsparse_auxiliary.h:285:63: error: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token
285 | aoclsparse_status aoclsparse_create_dcsr(aoclsparse_matrix &mat,
| ^
/home/USER/aocl/4.1.0/gcc/include/aoclsparse_auxiliary.h:339:67: error: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token
339 | aoclsparse_status aoclsparse_export_mat_csr(aoclsparse_matrix &csr,
| ^
/home/USER/aocl/4.1.0/gcc/include/aoclsparse_auxiliary.h:361:56: error: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token
361 | aoclsparse_status aoclsparse_destroy(aoclsparse_matrix &mat);
| ^
In file included from /home/USER/aocl/4.1.0/gcc/include/aoclsparse.h:48,
from min_ex.c:2:
/home/USER/aocl/4.1.0/gcc/include/aoclsparse_solvers.h:197:71: error: expected ‘;’, ‘,’ or ‘)’ before ‘&’ token
197 | aoclsparse_status aoclsparse_itsol_option_set(aoclsparse_itsol_handle &handle,
| ^
Compilation failed.
I tried to do a simple type redefinition, but it didn't work:
#include <stdio.h>
#include "aoclsparse.h"
/*
gcc min_ex.c -o min_ex -I/home/USER/aocl/4.1.0/gcc/include/ -L/home/USER/aocl/4.1.0/gcc/lib/ -L/home/USER/aocl/4.1.0/gcc/lib/libblis-mt.so -L/home/USER/aocl/4.1.0/gcc/lib_LP64/libaoclsparse.so -lflame -lblis-mt -laoclsparse -lm -lstdc++
*/
#define AOCLSPARSE_REF_TO_PTR(type) type *
#define aoclsparse_create_scsr(mat, ...) aoclsparse_create_scsr(mat, __VA_ARGS__)
#define aoclsparse_create_dcsr(mat, ...) aoclsparse_create_dcsr(mat, __VA_ARGS__)
#define aoclsparse_export_mat_csr(csr, ...) aoclsparse_export_mat_csr(csr, __VA_ARGS__)
#define aoclsparse_destroy(mat) aoclsparse_destroy(mat)
int main(void)
{
return 0;
}
Am I missing something simple?
Could you convert "sample_spmv.cpp" to "sample_spmv.c" so that I can see how to use the library from C?
Thanks.
Hello @amd0
Thank you for writing to ServerGuru.
We are currently investigating this issue and will keep you updated on the same.
Hello @amd0
Below shared code is a C code referring to sample_spmv.cpp :
sample_spmv.c :
The changes between the cpp and C files are as below :
1. std::cout >> printf
2. #include <iostream> to #include <stdio.h>
#include <stdlib.h>
This code can be compiled using the command :
gcc -Wall -xc++ sample_spmv.c -I~/aocl-linux-gcc-4.1.0/4.1.0/gcc/include -L~/aocl-linux-gcc-4.1.0/4.1.0/gcc/lib -lflame -lblis-mt -laoclsparse -lm
Please let us know if there is any further clarification required.
Hello @amd0
Can you please confirm if the above solution worked for you.
Also please let us know if there is any further clarification required.