Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions .github/workflows/cargo-publish-dry-run.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
on: [pull_request]

jobs:
cargo-publish-dry-run:
name: cargo-publish-dry-run

runs-on: ubuntu-latest

steps:
- uses: actions/checkout@v2
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
- uses: actions-rs/cargo@v1
with:
command: publish
args: --dry-run -F cuda-13000
4 changes: 2 additions & 2 deletions src/driver/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1161,7 +1161,7 @@ pub mod external_memory {
handle: sys::CUDA_EXTERNAL_MEMORY_HANDLE_DESC_st__bindgen_ty_1 { fd },
size,
flags: 0,
reserved: [0; _],
reserved: [0; 16],
Comment on lines 1163 to +1164

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

While hardcoding 16 fixes the build issue, it makes the code brittle. If the reserved field in CUDA_EXTERNAL_MEMORY_HANDLE_DESC ever changes size in a future CUDA version, this code will be incorrect. A more robust and idiomatic way to initialize the remaining fields is to use ..Default::default(). This will correctly zero-initialize flags and reserved and will adapt to future changes in the struct definition.

Suggested change
flags: 0,
reserved: [0; _],
reserved: [0; 16],
..Default::default()

};
sys::cuImportExternalMemory(external_memory.as_mut_ptr(), &handle_description).result()?;
Ok(external_memory.assume_init())
Expand Down Expand Up @@ -1227,7 +1227,7 @@ pub mod external_memory {
offset,
size,
flags: 0,
reserved: [0; _],
reserved: [0; 16],
Comment on lines 1229 to +1230

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Similar to the previous change, hardcoding 16 here is brittle. Using ..Default::default() is a more robust and idiomatic way to initialize the remaining fields of the struct to their default (zero) values.

Suggested change
flags: 0,
reserved: [0; _],
reserved: [0; 16],
..Default::default()

};
sys::cuExternalMemoryGetMappedBuffer(
device_ptr.as_mut_ptr(),
Expand Down
4 changes: 2 additions & 2 deletions src/runtime/result.rs
Original file line number Diff line number Diff line change
Expand Up @@ -944,7 +944,7 @@ pub mod external_memory {
size,
flags: 0,
#[cfg(feature = "cuda-13000")]
reserved: [0; _],
reserved: [0; 16],
Comment on lines 945 to +947

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Using ..Default::default() is more robust and idiomatic than manually zeroing fields. It will correctly initialize flags and, when the cuda-13000 feature is enabled, the reserved field. This also makes the code consistent with the import_external_memory_opaque_win32 function in this file.

Suggested change
flags: 0,
#[cfg(feature = "cuda-13000")]
reserved: [0; _],
reserved: [0; 16],
..Default::default()

};
sys::cudaImportExternalMemory(external_memory.as_mut_ptr(), &handle_description)
.result()?;
Expand Down Expand Up @@ -1013,7 +1013,7 @@ pub mod external_memory {
size,
flags: 0,
#[cfg(feature = "cuda-13000")]
reserved: [0; _],
reserved: [0; 16],
Comment on lines 1014 to +1016

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

high

Similar to the other changes, using ..Default::default() here is more robust. It will correctly zero-initialize flags and, when the cuda-13000 feature is enabled, the reserved field, adapting to any future changes in the struct definition.

Suggested change
flags: 0,
#[cfg(feature = "cuda-13000")]
reserved: [0; _],
reserved: [0; 16],
..Default::default()

};
sys::cudaExternalMemoryGetMappedBuffer(
device_ptr.as_mut_ptr(),
Expand Down
Loading