CUDA C++ cython extension throws "DLL load failed while importing" - dll

I have written a C++ CUDA extension of some linalg in visual studio, and I have created a .dll and .lib file. I have also created a wrapper using cython, but there is obviously some kind of dll dependency problem that I can't resolve. When I try to import the .pyd file, I get DLL load failed while importing safe: The specified module could not be found.
The following is my setup.py file:
from distutils.core import setup
from distutils.extension import Extension
from Cython.Distutils import build_ext
import numpy as np
import os
ext_modules = [
Extension('safe',
['safe.pyx'],
language="c++",
libraries=['safe', 'cudart_static', 'cusolver', 'cublas'],
library_dirs=['.', "C:\\Program Files\\NVIDIA GPU Computing Toolkit\\CUDA\\v11.6\\lib\\x64"]),
]
setup(
name = 'safe',
cmdclass = {'build_ext': build_ext},
ext_modules = ext_modules,
include_dirs=[np.get_include()]
)
And the following is the output of the dumpbin command that shows the dependencies for my dll:
cublas64_11.dll
cusolver64_11.dll
KERNEL32.dll
MSVCP140.dll
VCRUNTIME140.dll
VCRUNTIME140_1.dll
api-ms-win-crt-math-l1-1-0.dll
api-ms-win-crt-heap-l1-1-0.dll
api-ms-win-crt-string-l1-1-0.dll
api-ms-win-crt-time-l1-1-0.dll
api-ms-win-crt-runtime-l1-1-0.dll
I should also mention that my .lib, .dll and generally all related files are in the same directories, and the directories of the cuda dlls are added in PATH. Any help is appreciated.

Related

Not able to link HDF5 path in CMake configuration

I'm trying to create make files of C++ code on a server doing
cmake ../
and I get the error
-- Could NOT find HDF5 (missing: HDF5_INCLUDE_DIRS) (found version "1.10.7")
CMake Error at src/CMakeLists.txt:180 (message):
HDF5 support was requested, but no HDF5 library was found on this system
I have installed HDF5 in /home/directory/ so I have HDF5 include and library files in
/home/directory/include
/home/directory/lib
I've tried to add in CMakeLists.txt the following lines:
set(HDF5_LIBRARIES "/home/directory/")
set(HDF5_CXX_LIBRARIES "/home/directory/")
set(HDF5_INCLUDE_DIRS "/home/directory/")
set(HDF5_CXX_INCLUDE_DIRS "/home/directory/")
But still getting the error.
I've also tried to export HDF5_ROOT=/home/directory/ without success.
The error come from the following lines in the code:
if (HDF5_FOUND)
target_include_directories(soft PUBLIC ${HDF5_INCLUDE_DIRS})
target_link_libraries(soft PUBLIC ${HDF5_LIBRARIES})
else (HDF5_FOUND)
message(FATAL_ERROR "HDF5 support was requested, but no HDF5 library was found on this system")
endif (HDF5_FOUND)
Any help?
Using CMake 3.19.3 and hdf5-1.10.7

Statically link custom op from .a file in tensorflow serving

I have a custom op implemented CUDA and built using Makefile like this hdrnet. I can build .so and import in tensorflow. For tf-serving statically linking .a file is required but all tutorials reference bazel build process for custom op instead of directly linking compiled op from .a file.
Do I have to write build process as referenced by examples or I can build tf-serving with .so/.a files directly?
I ended up compile tensorflow-serving from source with op-linked in. Tensorflow tutorials are not complete for this and additional dependency was missing which I resolved in this issue issue.

Using DLLs in Cython project

I have a C++ project (lets call it base.cpp) using Armadillo library (that needs libs and dlls for BLAS and LAPACK libraries). I want to import function from this C++ project via Cython by my another python project (main.py). I am using setup.py (including all .cpp, .h and .lib files) for building the .pyd file (call it test.pyd). The building of test.pyd file is succesfull, however when I run my main.py file, during the part of importing function from test "ImportError:DLL Load failed: The specified module cannot be found" is raised. The Cython uses MSVC 2014 compiler. I have checked the directories where Windows looks for DLL files (https://msdn.microsoft.com/en-us/library/7d83bc18.aspx), but when I tried inserting there my dll files, nothing changed. My test.pyx file looks like this:
cdef extern from "base.h":
void printer()
def printer_wrapper():
printer()
where the function printer is just a function defined in base.cpp computing eigenvalues of a matrix. The main.py is just:
from test import printer_wrapper
if __name__ == '__main__':
printer_wrapper()
Do you have any suggestions where I might put my dll files in order to be found during the main.py runtime?

Linking 64bit dll mingw

I'm linking a dll with some dependencies on other dlls.
I have a trouble with linking a 64bit version of my project. With 32bit version all is ok as far as I use mingw32. But when I switch to 64bit version of dependent dlls and mingw-w64 it tells the following:
c:/.../x86_64-w64-mingw32/bin/ld.exe: skipping incompatible .\lib\native/libblabla.dll when searching for -llibblabla
Where 'libblabla' is a library I depend on. I'm absolutely sure it is 64bit version and should be compatible. Is it a bug in mingw?
Also, I tried to link using lib file, but provided lib is also considered as incompatible and the one generated by dlltool has no import table generated!
I'm totally stuck with this.
Thank you.
First, to get some possible misunderstanding out of the way:
GCC/ld can link to (properly exporting) 32-bit DLLs and .lib/.a import and static libraries.
GCC/ld should be able to link to a properly exporting 64-bit DLL or .a import or static lib, but never a 64-bit .lib file.
You aren't building/linking with -m32, are you?
By "properly exporting" I mean that dumpbin /exports or nm -t reveal exported symbols when run on the DLL.
What you should try:
Build the through a call to gcc, not any direct calls to binutils. The options -shared -o name.dll -Wl,--import-lib, libname.dll.a should get you started.
Use MinGW-w64's gendef (it's in the mingw-w64-tools directory in their SVN/sources) to generate a .def file, which you can create an import library.
If these produce no symbols in the import library, you're not exporting any symbols. Although this would be surprising as the error message says the dll is 32-bit. What does MSYS/Cygwin's file command on the dll return?

How to install objective-c header files on ubuntu OS?

I am trying to import #import<objc/object.h> in my code. But it is giving me an error "No such file or directory compilation terminated.". Is this because I didn't install the header files or because I didn't included the headers files path to the compiled object library.