I’ve been struggling with creation of .so from a simple C code containing Acceleration part. The software I work on uses a plugin approach, so I highly rely on shared library loading mechanism.
The builds were performed on Ubuntu 9.04 x64 with latest updates, using PGI 9.0.4.
====== test.c ======
#include <stdio.h>
#include <stdlib.h>
int main(int argc, char** argv) {
float a[1000];
#pragma acc region
{
for (int i = 0; i < 1000; i++) {
a _= i+2;
}
}
return (EXIT_SUCCESS);
}
================
pgcc -shared -o sample.so -ta=nvidia -Minfo test.c
Compilation went fine, the block has been accelerated, kernel created successfully, but on the link time I’ve got an error:
tester@ubuntu:~/work/test$ pgcc -shared -ta=nvidia -Minfo -o test.so empty.c
main:
17, Generating copyout(a[0:999])
19, Loop is parallelizable
Accelerator kernel generated
19, #pragma for parallel, vector(256)
/usr/bin/ld: /opt/pgi/linux86-64/9.0-4/lib/libacc1.a(nvalloc.o): relocation R_X86_64_32S against `a local symbol’ can not be used when making a shared object; recompile with -fPIC
/opt/pgi/linux86-64/9.0-4/lib/libacc1.a: could not read symbols: Bad value
There’s no error when I produce an executable from the same code.
pgcc -o sample -ta=nvidia -Minfo test.c
I’ve tried a number of different ways: introduced -fpic (-fPIC), tried -mcmodel=small or mcmodel=medium, tried explicit linking with libacc1.a and the other static libs (libacc1.a is the only library containing the need CUDA methods). Nothing helped.
At the very moment I use a workaround: compile a static library, which is then linked inside my main executable together with libacc1.a and other necessary static libs. Not what I need, but at least this works.
\
- Is it by design that it is not possible to create shared libraries with an acceleration code inside? (hopefully not)
\ - What would be the way out? Can you please recompile libacc1.a with -fPIC as it is suggested (the best solution for me)? Can you alternatively produce libacc1.so, so the linker will be happy to live with it?
\ - any other working solution will be greatly appreciated.
Thank you for your help and a very great product!
kind regards
Dimitri_