-
-
Notifications
You must be signed in to change notification settings - Fork 121
Add safe API for querying CUDA function attributes #479
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
Merged
Merged
Changes from 1 commit
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,74 @@ | ||
| use cudarc::{ | ||
| driver::{CudaContext, DriverError}, | ||
| nvrtc::Ptx, | ||
| }; | ||
|
|
||
| fn main() -> Result<(), DriverError> { | ||
| let ctx = CudaContext::new(0)?; | ||
|
|
||
| println!("Device: {}", ctx.name()?); | ||
| println!(); | ||
|
|
||
| // Load the module with the sin_kernel | ||
| let module = ctx.load_module(Ptx::from_file("./examples/sin.ptx"))?; | ||
| let sin_kernel = module.load_function("sin_kernel")?; | ||
|
|
||
| // Query function attributes | ||
| println!("=== Function Attributes for 'sin_kernel' ==="); | ||
| println!(); | ||
|
|
||
| println!("Resource Usage:"); | ||
| println!(" Registers per thread: {}", sin_kernel.num_regs()?); | ||
| println!( | ||
| " Static shared memory: {} bytes", | ||
| sin_kernel.shared_size_bytes()? | ||
| ); | ||
| println!( | ||
| " Constant memory: {} bytes", | ||
| sin_kernel.const_size_bytes()? | ||
| ); | ||
| println!( | ||
| " Local memory per thread: {} bytes", | ||
| sin_kernel.local_size_bytes()? | ||
| ); | ||
| println!(); | ||
|
|
||
| println!("Limits:"); | ||
| println!( | ||
| " Max threads per block: {}", | ||
| sin_kernel.max_threads_per_block()? | ||
| ); | ||
| println!(); | ||
|
|
||
| println!("Compilation Info:"); | ||
| let ptx_ver = sin_kernel.ptx_version()?; | ||
| let bin_ver = sin_kernel.binary_version()?; | ||
| println!( | ||
| " PTX version: {}.{}", | ||
| ptx_ver / 10, | ||
| ptx_ver % 10 | ||
| ); | ||
| println!( | ||
| " Binary version: {}.{}", | ||
| bin_ver / 10, | ||
| bin_ver % 10 | ||
| ); | ||
| println!(); | ||
|
|
||
| // Use occupancy API to get optimal launch configuration | ||
| extern "C" fn no_dynamic_smem(_block_size: std::ffi::c_int) -> usize { | ||
| 0 | ||
| } | ||
| let (min_grid_size, block_size) = | ||
| sin_kernel.occupancy_max_potential_block_size(no_dynamic_smem, 0, 0, None)?; | ||
|
|
||
| println!("=== Optimal Launch Configuration (sin_kernel) ==="); | ||
| println!(" Suggested block size: {}", block_size); | ||
| println!(" Min grid size: {}", min_grid_size); | ||
| println!( | ||
| " Total threads per grid: {}", | ||
| min_grid_size * block_size | ||
| ); | ||
|
|
||
| Ok(()) | ||
| } |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.