Hey guys,
I’m having some trouble using f2py with the pgi fortran compilers.
cpu_wrapper.f90
subroutine wrap_stuff(Z, ni)
use cudafor
implicit none
real, dimension(:), intent(out) :: Z
integer, intent(in) :: ni
type(dim3) :: grid, tBlock
real, device, dimension(:), allocatable :: Z_d
allocate(Z_d(ni))
tBlock = dim3(32,1,1)
grid = dim3(1,1,1)
Z_d = Z
call do_stuff<<<grid, tBlock>>>(Z_d, ni)
Z = Z_d
end subroutine
gpu_code.f90
attributes(global) subroutine do_stuff(Z, N)
use cudafor
implicit none
real, dimension(:), device :: Z
integer, intent(in) :: N
integer :: i
do i = threadIdx%x, N, blockDim%x
Z(i) = Z(i) ** 2.0
enddo
end subroutine do_stuff
command line: f2py --fcompiler=pg -m test -c cpu_wrapper.f90 gpu_code.f90 --f90flags=“-Mcuda -fPIC”
everything compiles fine, however running ldd -r on test.cpython-37m-x86_64-linux-gnu.so yields the following:
ldd -r test.cpython-37m-x86_64-linux-gnu.so
linux-vdso.so.1 (0x00007ffd3058d000)
libpgf90rtl.so => /opt/pgi/linux86-64/2019/lib/libpgf90rtl.so (0x00007f3c9e748000)
libpgf90.so => /opt/pgi/linux86-64/2019/lib/libpgf90.so (0x00007f3c9e1b0000)
libpgf90_rpm1.so => /opt/pgi/linux86-64/2019/lib/libpgf90_rpm1.so (0x00007f3c9dfae000)
libpgf902.so => /opt/pgi/linux86-64/2019/lib/libpgf902.so (0x00007f3c9dd9b000)
libpgftnrtl.so => /opt/pgi/linux86-64/2019/lib/libpgftnrtl.so (0x00007f3c9db5c000)
libpgatm.so => /opt/pgi/linux86-64/2019/lib/libpgatm.so (0x00007f3c9d953000)
libpgkomp.so => /opt/pgi/linux86-64/2019/lib/libpgkomp.so (0x00007f3c9d750000)
libomp.so => /home/nick/anaconda3/lib/libomp.so (0x00007f3c9ecc2000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f3c9d531000)
libpgmath.so => /opt/pgi/linux86-64/2019/lib/libpgmath.so (0x00007f3c9d11c000)
libpgc.so => /opt/pgi/linux86-64/2019/lib/libpgc.so (0x00007f3c9cdc3000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f3c9cbbb000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f3c9c81d000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f3c9c42c000)
libgcc_s.so.1 => /home/nick/anaconda3/lib/libgcc_s.so.1 (0x00007f3c9ec83000)
/lib64/ld-linux-x86-64.so.2 (0x00007f3c9eb72000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f3c9c228000)
undefined symbol: PyExc_ValueError (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyCapsule_Type (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: _Py_NoneStruct (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyExc_AttributeError (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyType_Type (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyExc_RuntimeError (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyExc_TypeError (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyExc_ImportError (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyComplex_Type (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyLong_AsLong (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyDict_GetItemString (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyObject_GetAttrString (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyMem_Free (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyType_IsSubtype (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyModule_GetDict (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyErr_NoMemory (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyDict_SetItemString (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyUnicode_FromFormat (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: __cudaRegisterFunction (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyArg_ParseTupleAndKeywords (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: _PyObject_New (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyNumber_Long (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyBytes_FromString (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyErr_Format (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyMem_Malloc (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: Py_BuildValue (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyImport_ImportModule (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: __pgiLaunchKernelFromStub (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyUnicode_FromString (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PySequence_Check (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: pgf90_dev_allocated_i8 (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyErr_Clear (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: pgf90_dev_copyin (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: __pgiLaunchKernel (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyOS_snprintf (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyDict_New (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyErr_SetString (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyCapsule_New (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: pgf90_dev_dealloc03_i8 (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: __pgi_cuda_register_fat_binaryA (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyObject_SetAttrString (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyCapsule_GetPointer (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: pgf90_dev_copyout (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyObject_Free (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PySequence_GetItem (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyErr_NewException (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyModule_Create2 (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: pgf90_dev_alloc04_i8 (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyErr_Occurred (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyObject_GenericGetAttr (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: pgf90_dev_dealloc_mbr03_i8 (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyDict_DelItemString (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyErr_Print (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyUnicode_Concat (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: PyUnicode_FromStringAndSize (./test.cpython-37m-x86_64-linux-gnu.so)
clearly, the python3 libraries are missing, so adding this with the following command line:
f2py --fcompiler=pg --f90exec=/opt/pgi/linux86-64/2019/bin/pgfortran -m test -c cpu_wrapper.f90 gpu_code.f90 --f90flags=“-Mcuda -fPIC” /home/nick/anaconda3/lib/libpython3.so
yields:
ldd -r test.cpython-37m-x86_64-linux-gnu.so
linux-vdso.so.1 (0x00007fff510fb000)
libpython3.so => /home/nick/anaconda3/lib/libpython3.so (0x00007f7c79f56000)
libpgf90rtl.so => /opt/pgi/linux86-64/2019/lib/libpgf90rtl.so (0x00007f7c7990c000)
libpgf90.so => /opt/pgi/linux86-64/2019/lib/libpgf90.so (0x00007f7c79374000)
libpgf90_rpm1.so => /opt/pgi/linux86-64/2019/lib/libpgf90_rpm1.so (0x00007f7c79172000)
libpgf902.so => /opt/pgi/linux86-64/2019/lib/libpgf902.so (0x00007f7c78f5f000)
libpgftnrtl.so => /opt/pgi/linux86-64/2019/lib/libpgftnrtl.so (0x00007f7c78d20000)
libpgatm.so => /opt/pgi/linux86-64/2019/lib/libpgatm.so (0x00007f7c78b17000)
libpgkomp.so => /opt/pgi/linux86-64/2019/lib/libpgkomp.so (0x00007f7c78914000)
libomp.so => /home/nick/anaconda3/lib/libomp.so (0x00007f7c79e81000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f7c786f5000)
libpgmath.so => /opt/pgi/linux86-64/2019/lib/libpgmath.so (0x00007f7c782e0000)
libpgc.so => /opt/pgi/linux86-64/2019/lib/libpgc.so (0x00007f7c77f87000)
librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007f7c77d7f000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f7c779e1000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f7c775f0000)
libgcc_s.so.1 => /home/nick/anaconda3/lib/libgcc_s.so.1 (0x00007f7c79e40000)
libpython3.7m.so.1.0 => /home/nick/anaconda3/lib/./libpython3.7m.so.1.0 (0x00007f7c77287000)
/lib64/ld-linux-x86-64.so.2 (0x00007f7c79d36000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f7c77083000)
libutil.so.1 => /lib/x86_64-linux-gnu/libutil.so.1 (0x00007f7c76e80000)
undefined symbol: __cudaRegisterFunction (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: __pgiLaunchKernelFromStub (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: pgf90_dev_allocated_i8 (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: pgf90_dev_copyin (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: __pgiLaunchKernel (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: pgf90_dev_dealloc03_i8 (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: __pgi_cuda_register_fat_binaryA (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: pgf90_dev_copyout (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: pgf90_dev_alloc04_i8 (./test.cpython-37m-x86_64-linux-gnu.so)
undefined symbol: pgf90_dev_dealloc_mbr03_i8 (./test.cpython-37m-x86_64-linux-gnu.so)
I can’t keep adding individual libraries, so I was wondering if anyone has any ideas?
This code works fine when used from a program file and an executable is created the “usual” way.