Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CUDA architecture is not being set properly #9

Open
kyamant opened this issue Apr 13, 2024 · 6 comments
Open

CUDA architecture is not being set properly #9

kyamant opened this issue Apr 13, 2024 · 6 comments

Comments

@kyamant
Copy link

kyamant commented Apr 13, 2024

Used CMAKE_CUDA_ARCHITECTURES to set compute and sm to 86 but still they appear as 52 under Code Generation CUDA C/C++ of each Visual Studio project's property page. If I set it manually in Visual Studio a new vxproj file is created in addition to ALL_BUILD.vcxproj and INSTALL.vcxproj. Where does this project keep the compute_52,sm_52 values for each project?

@NBickford-NV
Copy link
Contributor

NBickford-NV commented Apr 17, 2024

Hi @kyamant! Was this on the gl_cuda_simple_interop sample?

Setting CMAKE_CUDA_ARCHITECTURES to 86 (list of possible settings here) should work.

To set it from the command line:

gl_cuda_simple_interop/cmake_build> cmake -DCMAKE_CUDA_ARCHITECTURES="86" ..

And to set it from the GUI, click the Add Entry button, enter these settings, then click Configure and Generate:

image

This variable doesn't show in the GUI for some reason, but is still stored in CMakeCache.txt. (Edit: It appears at the top of CMake's variable display the first time I set it; I forgot to look for it there.)

Then you should see the SM version set in the sample's Property Pages > CUDA C/C++ > Command Line > Additional Options:

image

And during the build, you should see the right --generate-code option in the build output:

image

@kyamant
Copy link
Author

kyamant commented Apr 17, 2024

I do not want to go and set it individually for each project: I would like to be able set it for build all (when I ran cmake in build_all directory)

@NBickford-NV
Copy link
Contributor

NBickford-NV commented Apr 17, 2024

Hi @kyamant -- I just tried setting CMAKE_CUDA_ARCHITECTURES on build_all, and it appears to have worked OK -- I can see it propagate to subprojects (although most won't show the additional compiler options, and will show the default compute_52,sm_52, unless they have at least one .cu file, i.e. if they actually compile CUDA code).

@NBickford-NV
Copy link
Contributor

NBickford-NV commented Apr 17, 2024

Note that I set it in the CMake configuration settings and re-ran CMake; if I modified the ALL_BUILD target inside Visual Studio, those changes wouldn't propagate back to CMake. Does setting the options inside CMake work for you? Thanks!

@kyamant
Copy link
Author

kyamant commented Apr 17, 2024

Hi @kyamant -- I just tried setting CMAKE_CUDA_ARCHITECTURES on build_all, and it appears to have worked OK -- I can see it propagate to subprojects (although most won't show the additional compiler options, and will show the default compute_52,sm_52, unless they have at least one .cu file, i.e. if they actually compile CUDA code).

How exactly did you set CMAKE_CUDA_ARCHITECTURES on build_all, there is no such variable in the cmake file?
Thanks

@NBickford-NV
Copy link
Contributor

Hi @kyamant -- it turns out it's possible to set it even if it's not referenced in the CMake file! Ultimately, CMAKE_CUDA_ARCHITECTURES is used by CMake's internals in places like CMakeDetermineCUDACompiler.cmake.

There's two ways to set it -- from the command line, and from the GUI -- I'll show both for completeness.

From the command line, a typical build process specifying CMAKE_CUDA_ARCHITECTURES nlooks something like this:

# Here, build_all and cmake_build are folders next to each other.
# If you don't have NVAPI, you can pass -DBUILD_dx12_present_barrier=OFF
# as an option (to turn off the sample that uses it) instead of
# -DNVAPI_LOCATION, and then CMake will still complete.
nvpro samples\cmake_build> cmake -DCMAKE_CUDA_ARCHITECTURES=86 -DNVAPI_LOCATION=C:\Users\nbickford\Downloads\NVAPI-R525-developer ../build_all

# Then open nvpro-samples.sln, or build it from the command line:
cmake --build .

From the GUI, start by specifying your source code and binary directories:

image

I'm showing the process starting from an empty CMake cache here, but the cache doesn't need to be empty! If you've configured CMake before, you can add the variables following the steps below and everything should still work - no need to delete the cache.

Click "➕ Add Entry" and set CMAKE_CUDA_ARCHITECTURES, like this:

image

Also, set NVAPI_LOCATION (or set BUILD_dx12_present_barrier to OFF):

image

At this point, you'll see the two new variables you added at the top of CMake's variable list:

image

Then press the Configure and Generate buttons, and then press Open Project to open Visual Studio.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants