Rate This Document
Findability
Accuracy
Completeness
Readability

API Calling Example

This section provides sample code for calling HMPP interface functions to help you quickly get started with the library.

  1. Create a test.cpp file.
  2. Add the following code to the test.cpp file.
     1
     2
     3
     4
     5
     6
     7
     8
     9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    #include <stdio.h>
    #include <stdlib.h>
    #include "hmpp.h"
    #define BUFFER_SIZE_T 500
    void AddExample() {
        uint32_t *src1 = HMPPS_Malloc_32u(BUFFER_SIZE_T);
        uint32_t *src2 = HMPPS_Malloc_32u(BUFFER_SIZE_T);
        uint32_t *dst = HMPPS_Malloc_32u(BUFFER_SIZE_T);
        int32_t i, result;
    
        if (src1 == NULL || src2 == NULL || dst == NULL) {
            return;
        }
        for (i = 0; i < BUFFER_SIZE_T; ++i) {
             src1[i] = i;
             src2[i] = i + 1;
        }
        
        result = HMPPS_Add_32u(src1, src2, dst, BUFFER_SIZE_T);
        printf("result = %d \n dst = ", result);
        for (i = 0; i < BUFFER_SIZE_T; i++) {
            printf("%d ", dst[i]);
        }
        printf("\n");
    
        HMPPS_Free(src1);
        HMPPS_Free(src2);
        HMPPS_Free(dst);
    }
    
    1
    2
    3
    4
    int main(void){
        AddExample();
        return 0;
    }
    

Example of Compiling and Executing the File

  • Compile the file.
    1
    g++ test.cpp -o test -L /usr/local/kml/lib/ -lkfft -lkfftf -L /usr/local/kml/lib/kvml/single -lkvml -lkm -lm -L /usr/local/kml/lib/kblas/locking -lkblas -L /usr/local/lib/HMPP -lHMPP_signal -lHMPP_core -lpthread
    
  • Execute the file.
    1
    ./test
    

Troubleshooting

Symptom:

  1. The header file contains the error "fatal error: hmpp.h: No such file or directory".
  2. DDL reference error: "./test: error while loading shared libraries: libHMPP_core.so.xxxx: cannot open shared object file: No such file or directory"

xxxx indicates the version number.

Cause:

  1. The installation package may not be correctly installed. The header file and dynamic library of the HMPP library are not stored in their respective directory.
  2. After the installation package is installed, the environment variables are not properly written into the system and thus do not take effect.

Procedure:

  1. Check whether the header file and dynamic library exist in /usr/local/include/HMPP and /usr/local/lib/HMPP respectively. If not, install them again.
  2. Add environment variables.
    1. Open /etc/profile.
      vi /etc/profile
    2. Add the following environment variables to the file:
      export C_INCLUDE_PATH=$C_INCLUDE_PATH:/usr/local/include/HMPP
      export CPLUS_INCLUDE_PATH=$CPLUS_INCLUDE_PATH:/usr/local/include/HMPP
      if [ ! -n "$LD_LIBRARY_PATH" ]
      then
              export LD_LIBRARY_PATH=/usr/local/lib/HMPP
      else
              export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/local/lib/HMPP
      fi
    3. Press Esc, type :wq!, and press Enter to save the file and exit.
  3. Make the configuration file take effect.
    source /etc/profile