Static CUDA Build with Opencv

Hello, I was writing a training project and encountered a problem.

In short, I wanted to build a static version of Opencv and CUDA toolkit with CUDNN in order to use programs compiled by such a library on another PC where only the nvidia driver is installed. But after a series of attempts, I faced the fact that cublas and cudnn refuse to assemble statically. Some information about the system on which I collect all this Ubuntu 22.04 LTS, rtx 3050

It’s possible to link to cublas statically on linux. The basic library to link against would be libcublas_static.a which you can find in a linux CUDA install. Depending on what you are doing, you may need some additional links, such as:

 -lcublas_static \
 -lculibos \
 -ldl -lpthread

I’m not sure about cudnn, but you could ask about that on the cudnn forum

Is there any dependence on the CUDA version?

I tried to build with cublas static(-cublas_static -lcublasLt_static), but some functions are not included in the static package. CUDA version 12.4

sure, cublas has changed over time. Some stuff that was available in CUBLAS 9.2 is no longer available.

but I’m not aware of things that are available for dynamic linking that are not available for static linking.

The static linking requires you to specify a proper set of libraries. If you’ve got unresolved functions it may be that other libraries need to be specified.

After all my attempts to run the code to check my static dynamic library, I get an undefined symbol: cublasZgeam. I compiled with -lcublas_static -lcublasLt_static

I didn’t seem to have any trouble statically linking cublasZgeam in a simple test case on CUDA 13.0:

# cat t427.cu
#include <cublas_v2.h>

int main(){

  cublasHandle_t handle;
  int m = 32;
  int n = 32;
  const cuDoubleComplex *alpha = NULL;
  const cuDoubleComplex *A =  NULL;
  int lda = 32;
  const cuDoubleComplex *beta = NULL;
  const cuDoubleComplex *B = NULL;
  int ldb = 32;
  cuDoubleComplex *C = NULL;
  int ldc = 32;
  cublasStatus_t s = cublasCreate(&handle);

  s = cublasZgeam(handle,
                          CUBLAS_OP_N, CUBLAS_OP_N,
                          m, n,
                          alpha,
                          A, lda,
                          beta,
                          B, ldb,
                          C, ldc);
}
# nvcc -o t427 t427.cu -lcublas_static -lcublasLt_static -lculibos
#