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

Windows compatibility #29

Open
wants to merge 4 commits into
base: v2
Choose a base branch
from
Open

Windows compatibility #29

wants to merge 4 commits into from

Conversation

phernst
Copy link

@phernst phernst commented Sep 10, 2021

This should make building the package work on both Linux and Windows.

Probably needs a bit of cleaning up (the templated function toType is redundantly defined in backprojection.cu and forward.cu, and some code is not used any more, e.g. make.py and ptx_annotation.py).

Tested on Windows 10 (CUDA 11.4, GTX 1060), Manjaro (CUDA 11.4, RTX A6000) and Ubuntu 18.04 (CUDA 11.4, Tesla V100).

@phernst
Copy link
Author

phernst commented Sep 10, 2021

Might close Issue #18

@@ -1,14 +1,14 @@
from setuptools import setup
from torch.utils.cpp_extension import BuildExtension, CUDAExtension
import os
from make import build
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The setup is used also in the CI/CD pipeline to create the precompiled packages so I would keep both the Linux version with the make.py file and the new Windows version ad add an if os.name=='posix' to choose between the two versions of the code

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah I see. I will add the if os.name=='posix'.
Since this will include setting cuda_home = os.getenv("CUDA_HOME", "/usr/local/cuda") again, what do you think about replacing this with from torch.utils.cpp_extension import CUDA_HOME? On Manjaro, for example, the path to cuda is CUDA_PATH="/opt/cuda" and CUDA_HOME is not set. The torch import would take care of that.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect, thanks.
Replacing the CUDA_HOME definition seems a good idea!

__device__ T toType(float);

template<>
__device__ float toType(float f)
Copy link
Owner

@matteo-ronchetti matteo-ronchetti Sep 13, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are these required?

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The cuda compiler on windows doesn't allow implicit casts from 32bit floats to 16bit floats. In radon_backward_kernel, for example, accumulator is a 32bit float array, but output might be 16bit float. toType casts 32bit floats to the target type.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I just found out that CUDAExtension defines __CUDA_NO_HALF_CONVERSIONS__ for nvcc, which deactivates these implicit conversions. Since you don't compile the cuda files with CUDAExtension, you didn't get these errors.
There are 2 possibilities now:

  1. keep the templated casts in the cuda files
  2. undefine __CUDA_NO_HALF_CONVERSIONS__ for CUDAExtension

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am ok with keeping the templated casts. Please put them in a separate file in order to avoid duplication of code

@matteo-ronchetti
Copy link
Owner

Thank you very much for taking the time to do this PR, I really appreciate it.
I have some minor comments but everything else looks good to me

@phernst
Copy link
Author

phernst commented Sep 16, 2021

I haven't checked the code updates on Windows yet. I will let you know if it still works soon.

@phernst
Copy link
Author

phernst commented Sep 19, 2021

Works on my Windows pc. I'm not sure why the CI build fails, though. Seems like it cannot find numpy for python 3.6

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

Successfully merging this pull request may close these issues.

2 participants