microsoft / onnxruntime

ONNX Runtime: cross-platform, high performance ML inferencing and training accelerator
https://onnxruntime.ai
MIT License
14.7k stars 2.93k forks source link

[Build] linking against header-only library cudnn_frontend #22855

Open ConnorBaker opened 4 hours ago

ConnorBaker commented 4 hours ago

Describe the issue

I'm packaging onnxruntime for the Nixpkgs CUDA ecosystem (https://github.com/connorbaker/cuda-packages).

When building with nix, I ran into errors while linking because the linker was unable to find -lcudnn_frontend.

My understanding was that cudnn-frontend was a header-only library (https://github.com/NVIDIA/cudnn-frontend) -- why does onnxruntime try to link against a library?

https://github.com/microsoft/onnxruntime/blob/ac9c135b9543ad0374fe335bc3dc5feb0f24f010/cmake/onnxruntime_unittests.cmake#L70

https://github.com/microsoft/onnxruntime/blob/ac9c135b9543ad0374fe335bc3dc5feb0f24f010/cmake/onnxruntime_providers_cuda.cmake#L208

Urgency

No response

Target platform

x86_64-linux with TensorRT

Build script

nix build -L --builders '' --no-link github:connorbaker/cuda-packages/fabe15378f8cf5a0870d6189115170a042a802f5#pkgsCuda.sm_89.cudaPackages_12.onnxruntime

Error / output

cuda12.6-onnxruntime> /nix/store/va7kw1i822h95im4jacci19v0cqajfyf-binutils-2.43.1/bin/ld: cannot find -lcudnn_frontend: No such file or directory
cuda12.6-onnxruntime> collect2: error: ld returned 1 exit status
cuda12.6-onnxruntime> ninja: build stopped: subcommand failed.

Visual Studio Version

No response

GCC / Compiler Version

13.3.0

tianleiwu commented 4 hours ago

cudnn_frontend is an interface library. Need use target_link_libraries() in CMake. Interface libraries in CMake are special in that they do not generate any compiled output themselves but propagate build properties, such as include directories or other linked libraries, to targets that depend on them.

Example to use it: https://github.com/microsoft/onnxruntime/blob/bbe7c8773837aa7573e202aefd2c633a06be2c23/cmake/onnxruntime_providers_cuda.cmake#L200-L210

Here is related doc about build: https://onnxruntime.ai/docs/build/eps.html#cuda

snnn commented 1 hour ago

cudnn_frontend is a cmake target. It's ok to do so, because the target_link_libraries command will add extra compile flags for the target. In this case, for example, CUDNN_FRONTEND_SKIP_JSON_LIB. But, we may also change it to onnxruntime_add_include_to_target.

onnxruntime_add_include_to_target(${target} cudnn_frontend)

Let me know if it would solve the problem.