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

Release mode cannot find cuda #489

Closed
dbsxdbsx opened this issue May 27, 2022 · 3 comments
Closed

Release mode cannot find cuda #489

dbsxdbsx opened this issue May 27, 2022 · 3 comments

Comments

@dbsxdbsx
Copy link

dbsxdbsx commented May 27, 2022

On Win10 with cuda 11.3, and tch-rs 0.7.2 and torchlib 1.11.0_cuda11.3 of release version, when calling tch::Device::cuda_if_available(), in release mode, it turns to using cpu. If it is forced to using cuda by calling tch::Device::Cuda(0), then it runs into error.

@RundownRhino
Copy link

@dbsxdbsx Had the same issue. After some searching on the repo, realised this is a duplicate of #291. The solution, as per #291 (comment), is to add

tch::maybe_init_cuda();

before you try to create a Cuda(0) device. That fixes the issue for me.

@dbsxdbsx
Copy link
Author

dbsxdbsx commented Jun 3, 2022

@dbsxdbsx Had the same issue. After some searching on the repo, realised this is a duplicate of #291. The solution, as per #291 (comment), is to add

tch::maybe_init_cuda();

before you try to create a Cuda(0) device. That fixes the issue for me.

@RundownRhino , thanks your advice. After putting tch::maybe_init_cuda(); right before tch::Device::Cuda(0);, now it is not only workable when choosing Cuda, but also workable when choosing cuda_if_available():

  let device = loop {
            let cur_index = get_usize_num_from_user_input_str();
            match cur_index {
                1 => break tch::Device::cuda_if_available(),
                2 => break tch::Device::Cpu,
                3 => {
                    tch::maybe_init_cuda();  // modified here
                    break tch::Device::Cuda(0);
                }
                _ => println!("error input"),
            }
        };

I am wondering why tch::maybe_init_cuda() would affect tch::Device::cuda_if_available().
And still, I think tch::maybe_init_cuda(); is still a workround, there should not need to write this line.

@LaurentMazare
Copy link
Owner

tch::maybe_init_cuda is certainly a hacky workaround but the best we get so far as afaik it's not easy to specify the linker flags in order and ensure that they will be used to link the final binaries. Closing this issue for now until we find a better way to handle this.

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

3 participants