Can I compile a cuda program without having a cuda device

17,452

The answer to your question is YES.

The nvcc compiler driver is not related to the physical presence of a device, so you can compile CUDA codes even without a CUDA capable GPU. Be warned however that, as remarked by Robert Crovella, the CUDA driver library libcuda.so (cuda.lib for Windows) comes with the NVIDIA driver and not with the CUDA toolkit installer. This means that codes requiring driver APIs (whose entry points are prefixed with cu, see Appendix H of the CUDA C Programming Guide) will need a forced installation of a "recent" driver without the presence of an NVIDIA GPU, running the driver installer separately with the --help command line switch.

Following the same rationale, you can compile CUDA codes for an architecture when your node hosts a GPU of a different architecture. For example, you can compile a code for a GeForce GT 540M (compute capability 2.1) on a machine hosting a GT 210 (compute capability 1.2).

Of course, in both the cases (no GPU or GPU with different architecture), you will not be able to successfully run the code.

For the early versions of CUDA, it was possible to compile the code under an emulation modality and run the compiled code on a CPU, but device emulation is since some time deprecated. If you don't have a CUDA capable device, but want to run CUDA codes you can try using gpuocelot (but I don't have any experience with that).

Share:
17,452

Related videos on Youtube

DEV
Author by

DEV

Updated on November 03, 2022

Comments

  • DEV
    DEV over 1 year

    Is it possible to compile a CUDA program without having a CUDA capable device on the same node, using only NVIDIA CUDA Toolkit...?

    • Vitality
      Vitality over 10 years
      Yes. The nvcc compiler driver is not related to the physical presence of a device, so you can compile even without a CUDA capable GPU. Following the same rationale, you can compile CUDA codes for an architecture when your node hosts a GPU of different architecture. Of course, in both the cases, you will not be able to successfully run the code. Remember that device emulation is since some time deprecated, so if you don't have a CUDA capable device you can try gpuocelot (but I don't have any experience with that).
    • Vitality
      Vitality over 10 years
      @RobertCrovella Thanks for the clarification. I have converted the comment to a full answer. Please, feel free to edit it or adding comments if I'm missing something.
    • nickpapior
      nickpapior almost 3 years
      @RobertCrovella the largest part of the cuda environments ship a "stub" libcuda.so so one can compile without having drivers located. Much easier in these cases. It typically lies in the lib*/stubs/ folder so a simple addition of this path to library search path solves the problem.
  • nickpapior
    nickpapior almost 3 years
    The majority of cuda toolkits ship a stub library for libcuda.so such that you don't need the driver located. It generally lies in the lib*/stubs/ folder.
  • Robert Crovella
    Robert Crovella almost 3 years
    8 years ago, that wasn't the case.