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

Add CUDA support for MSVC #426

Merged
merged 10 commits into from Aug 12, 2019
Merged

Add CUDA support for MSVC #426

merged 10 commits into from Aug 12, 2019

Conversation

trolleyman
Copy link
Contributor

@trolleyman trolleyman commented Jul 28, 2019

Tested building https://github.com/trolleyman/cuda-macros with this (the cuda-macros-test crate) and it builds & links correctly. Haven't had a chance to test that this runs yet, but will in the morning.

I wasn't sure that this way is the most elegant, but this seemed like the way that did the least amount of changes. I am also not sure that this is the correct way of doing this, especially regarding cross-compiling, but it gets it up and running at least.

To test you can do a cargo build in the root of the repo linked above. The build stuff is a bit hacky, but essentially it generates the CUDA function below & calls it.

extern "C" __global__ void hello(int32_t* x, int32_t y) {
    printf("Hello from block %d, thread %d (y=%d)\n", blockIdx.x, threadIdx.x, y);
    *x = 2;
}
extern "C" unsafe fn hello(x: *mut i32, y: i32);

@alexcrichton
Copy link
Member

Thanks! It looks like the main difference here is /X vs -X but I think that MSVC considers them equivalent for C compilation, could the MSVC bits just be updated to use the dash instead?

@trolleyman
Copy link
Contributor Author

Oh cool, didn't know that. Does that mean we can remove all of those *_flag functions from the compiler family struct & just use raw string literals everywhere?

@alexcrichton
Copy link
Member

Perhaps yeah! I forget which target those were added for, so I'd just follow the various logic internally to see if it's necessary to keep it or not.

@trolleyman
Copy link
Contributor Author

Alright, there we go. I also tested cuda-macros & it compiles & runs a simple test program. Should be ready to merge

@trolleyman
Copy link
Contributor Author

trolleyman commented Jul 30, 2019

Ah. That commit broke it

@trolleyman
Copy link
Contributor Author

There we go

src/lib.rs Outdated
@@ -1276,8 +1248,11 @@ impl Build {
// the SDK, but for all released versions of the
// Windows SDK it is required.
if target.contains("arm") || target.contains("thumb") {
cmd.args
.push("/D_ARM_WINAPI_PARTITION_DESKTOP_SDK_AVAILABLE=1".into());
if self.cuda {
Copy link
Member

Choose a reason for hiding this comment

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

Are changes like this necessary? This PR feels a bit overreaching in terms of changing everything it finds?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't too sure about this define, so I added it when compiling with nvcc as well. We can just simplify it to a -D option instead and it will define it for both nvcc & non-nvcc versions?

src/lib.rs Outdated
if self.cuda {
cmd.args.push("-m64".into());
}
cmd.push_cc_arg("-m64".into());
Copy link
Member

Choose a reason for hiding this comment

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

I'm not really sure what's going on here, how come the flag is pushed twice?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I wasn't too sure about if the nvcc compiler passed through the -m32 and -m64 options, so I added it for both. I think it does though, so I'll modify these lines to just add the options onto the command args directly, as both msvc and nvcc support these options.

Also, for context, the nvcc compiler only supports 32/64 bit cross-compilation, and it's phasing out 32 bit compilation altogether as well it seems. I'm not sure what to do about cross-compilation & CUDA btw -- should it be better supported/disallowed entirely?

@alexcrichton
Copy link
Member

Hm I was sort of hoping that everything that was /foo could be changed to -foo, but this seems like it's sort of just a smattering of some one way and some another way...

@trolleyman
Copy link
Contributor Author

Ah, ok - should I try and remove all of the /opt options?

@alexcrichton
Copy link
Member

I think that should work yeah, and I think it's probably better than sprinkling if cuda everywhere

@trolleyman
Copy link
Contributor Author

Ok, removed all /- options everywhere, and simplified command_add_output_file. I've tested that -Foout.obj is the same as -Fo out.obj when compiling assembly.

Removed the edits that are mentioned in #426 (comment) as cross-compilation is not supported with nvcc, so it's probably better not to even pretend that we support it.

Simplified the change in #426 (comment)

@alexcrichton
Copy link
Member

Thanks @trolleyman!

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.

None yet

2 participants