Software Archive
Read-only legacy content
Announcements
FPGA community forums and blogs on community.intel.com are migrating to the new Altera Community and are read-only. For urgent support needs during this transition, please visit the FPGA Design Resources page or contact an Altera Authorized Distributor.
17060 Discussions

Using OpenMP 4.0 target directives with user libraries

Grund__Aalexander
877 Views

I tried to get an OpenMP 4.0 test case to run where the code calls a user library that is compiled for host and mic (-mmic)
The host library is in current directory (pwd), the MIC lib is in pwd/mic and I set LD_LIBRARY_PATH to pwd and MIC_LD_LIBRARY_PATH to pwd/mic
However the execution fails with "On the sink, dlopen() returned NULL. The result of dlerror() is "/tmp/coi_procs/1/31669/load_lib/iccoutysEa1j: undefined symbol: foo"

The code looks like this:

#include <omp.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include "foo.h"

#pragma omp declare target
int foo();
#pragma omp end declare target

int main()
{
  /* start user code */
#pragma omp target
    {
      foo();
    }
  return 0;
}

Command line is:
icc -shared -fPIC -o libhostlib.so hostlib.c
icc -mmic -shared -fPIC -o mic/libhostlib.so hostlib.c
icc -openmp -o test_mic.o -c test_mic.c
icc -openmp -L. -lhostlib -o test_mic test_mic.o

How can I get something like this to work or is it just impossible to use custom libraries on the target with the offload model?

0 Kudos
1 Solution
Kevin_D_Intel
Employee
877 Views

I revised my earlier reply to match all the names you used.

Try building and running like this:

icc -openmp -fpic -shared -o libhostlib.so hostlib.c
icc -openmp -fpic -mmic -shared -o mic/libhostlib.so hostlib.c
icc -openmp -L. -lhostlib -otest_mic test_mic.c -offload-option,mic,ld,"-L./mic -lhostlib"

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:.
export MIC_LD_LIBRARY_PATH=$MIC_LD_LIBRARY_PATH:./mic
./test_mic

View solution in original post

0 Kudos
3 Replies
Kevin_D_Intel
Employee
878 Views

I revised my earlier reply to match all the names you used.

Try building and running like this:

icc -openmp -fpic -shared -o libhostlib.so hostlib.c
icc -openmp -fpic -mmic -shared -o mic/libhostlib.so hostlib.c
icc -openmp -L. -lhostlib -otest_mic test_mic.c -offload-option,mic,ld,"-L./mic -lhostlib"

export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:.
export MIC_LD_LIBRARY_PATH=$MIC_LD_LIBRARY_PATH:./mic
./test_mic
0 Kudos
Grund__Aalexander
877 Views

This does indeed work.

Thanks for that!

0 Kudos
Kevin_D_Intel
Employee
877 Views

Great!  Thank you for useful question/post. I expect it will help others in the future.
 

0 Kudos
Reply