API Calling Example
- Create a test.c file.
- Add the following code to the test.c file:
#include <stdio.h> #include <stdlib.h> #include <stdint.h> #include "kvsip.h" #include "vsip.h" #include "vsip_type.h" void TestExample() { int32_t row = 4; int32_t col = 3; int64_t rowStride = 1; int64_t colStride = row * rowStride; uint64_t offset = 0; int32_t len = 2 * (col * colStride + offset); float *src1 = (float *)malloc(len * sizeof(float)); float *src2 = (float *)malloc(len * sizeof(float)); float *dst = (float *)malloc(len * sizeof(float)); for (int32_t i = 0; i < len; ++i) { src1[i] = 1 + i / 100.0f; src2[i] = 2 + i / 100.0f; } vsip_cblock_f *block_a = vsip_cblockbind_f(src1, NULL, len, VSIP_MEM_NONE); vsip_cblock_f *block_b = vsip_cblockbind_f(src2, NULL, len, VSIP_MEM_NONE); vsip_cblock_f *block_r = vsip_cblockbind_f(dst, NULL, len, VSIP_MEM_NONE); vsip_cmview_f *a = vsip_cmbind_f(block_a, offset, colStride, col, rowStride, row); vsip_cblockadmit_f(block_a, VSIP_TRUE); vsip_cmview_f *b = vsip_cmbind_f(block_b, offset, colStride, col, rowStride, row); vsip_cblockadmit_f(block_b, VSIP_TRUE); vsip_cmview_f *r = vsip_cmbind_f(block_r, offset, colStride, col, rowStride, row); vsip_cblockadmit_f(block_r, VSIP_TRUE); vsip_cmadd_f(a, b, r); vsip_cmalldestroy_f(a); vsip_cmalldestroy_f(b); vsip_cmalldestroy_f(r); printf("src1:\n"); for (int32_t i = 0; i < col; ++i) { for (int32_t j = 0; j < row * 2; ++j) { printf("%.5f ", src1[i * row * 2 + j]); } printf("\n"); } printf("\nsrc2:\n"); for (int32_t i = 0; i < col; ++i) { for (int32_t j = 0; j < row * 2; ++j) { printf("%.5f ", src2[i * row * 2 + j]); } printf("\n"); } printf("\ndst:\n"); for (int32_t i = 0; i < col; ++i) { for (int32_t j = 0; j < row * 2; ++j) { printf("%.5f ", dst[i * row * 2 + j]); } printf("\n"); } free(src1); free(src2); free(dst); }int main(void) { TestExample(); return 0; }
Example of Compiling and Executing the File
- Compile the file.
gcc test.c -o test -I /usr/local/include/KVSIP/ -L /usr/local/lib/KVSIP/ -lkvsip_fft -lkvsip_fftf -lkvsip -lm -fPIC
- Execute the file.
./test
Multi-thread Support
The VSIP library supports multiple threads. You can set the number of concurrent threads by setting the OMP_NUM_THREADS environment variable. By default, a single thread is used. For example, to set the number of concurrent threads to 8, run the following command:
export OMP_NUM_THREADS=8
Troubleshooting
Symptom:
- "fatal error: vsip.h: No such file or directory"
- "./test: error while loading shared libraries: libkvsip.so.xxxx: cannot open shared object file: No such file or directory"
In the preceding messages, xxxx indicates the version number.
Procedure:
- Check whether header files and dynamic libraries exist in /usr/local/include/KVSIP and /usr/local/lib/KVSIP.
- Add the following environment variables to /etc/profile:
export C_INCLUDE_PATH=$C_INCLUDE_PATH:/usr/local/include/KVSIP export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/local/include/KVSIP if [ ! -n "$LD_LIBRARY_PATH" ] then export LD_LIBRARY_PATH=/usr/local/lib/KVSIP else export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/KVSIP fi - Make the configuration file take effect.
source /etc/profile
Parent topic: Using the KVSIP