-
Notifications
You must be signed in to change notification settings - Fork 117
[test] Add benchmark measuring CUDA kernel launch latency #646
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
vkarak
merged 9 commits into
reframe-hpc:master
from
teojgo:regression_test/kernel_latency
Jan 18, 2019
Merged
Changes from all commits
Commits
Show all changes
9 commits
Select commit
Hold shift + click to select a range
ab50a5e
Create kernel launch latency benchmark
8c05ee2
Fix code style
d71a060
Add required ReFrame version
52a1b9b
Merge branch 'master' into regression_test/kernel_latency
2b98fdf
Address PR comments
9ab91c6
Fix formatting problem
1b239fb
Fix kesch numbers
0b7e28b
Merge branch 'master' into regression_test/kernel_latency
42c8e33
Make test flexible and support multiple gpus
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
84 changes: 84 additions & 0 deletions
84
cscs-checks/microbenchmarks/kernel_latency/kernel_latency.py
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,84 @@ | ||
| import reframe as rfm | ||
| import reframe.utility.sanity as sn | ||
|
|
||
|
|
||
| @rfm.required_version('>=2.16-dev0') | ||
| @rfm.parameterized_test(['sync'], ['async']) | ||
| class KernelLatencyTest(rfm.RegressionTest): | ||
| def __init__(self, kernel_version): | ||
| super().__init__() | ||
| self.sourcepath = 'kernel_latency.cu' | ||
| self.build_system = 'SingleSource' | ||
| self.valid_systems = ['daint:gpu', 'dom:gpu', 'kesch:cn'] | ||
| self.valid_prog_environs = ['PrgEnv-cray', 'PrgEnv-pgi'] | ||
| self.num_tasks = 0 | ||
| self.num_tasks_per_node = 1 | ||
|
|
||
| if self.current_system.name in {'dom', 'daint'}: | ||
| self.num_gpus_per_node = 1 | ||
| gpu_arch = '60' | ||
| self.modules = ['craype-accel-nvidia60'] | ||
| self.valid_prog_environs += ['PrgEnv-gnu'] | ||
| else: | ||
| self.num_gpus_per_node = 16 | ||
| self.modules = ['craype-accel-nvidia35'] | ||
| gpu_arch = '37' | ||
|
|
||
| self.build_system.cxxflags = ['-arch=compute_%s' % gpu_arch, | ||
| '-code=sm_%s' % gpu_arch, '-std=c++11'] | ||
|
|
||
| if kernel_version == 'sync': | ||
| self.build_system.cppflags = ['-D SYNCKERNEL=1'] | ||
| else: | ||
| self.build_system.cppflags = ['-D SYNCKERNEL=0'] | ||
|
|
||
| self.sanity_patterns = sn.all([ | ||
| sn.assert_eq( | ||
| sn.count(sn.findall(r'\[\S+\] Found \d+ gpu\(s\)', | ||
| self.stdout)), | ||
| self.num_tasks_assigned), | ||
| sn.assert_eq( | ||
| sn.count(sn.findall(r'\[\S+\] \[gpu \d+\] Kernel launch ' | ||
| r'latency: \S+ us', self.stdout)), | ||
| self.num_tasks_assigned * self.num_gpus_per_node) | ||
| ]) | ||
|
|
||
| self.perf_patterns = { | ||
| 'latency': sn.max(sn.extractall( | ||
| r'\[\S+\] \[gpu \d+\] Kernel launch latency: ' | ||
| r'(?P<latency>\S+) us', self.stdout, 'latency', float)) | ||
| } | ||
| self.sys_reference = { | ||
| 'sync': { | ||
| 'dom:gpu': { | ||
| 'latency': (6.6, None, 0.10, 's') | ||
| }, | ||
| 'daint:gpu': { | ||
| 'latency': (6.6, None, 0.10, 'us') | ||
| }, | ||
| 'kesch:cn': { | ||
| 'latency': (12.0, None, 0.10, 'us') | ||
| }, | ||
| }, | ||
| 'async': { | ||
| 'dom:gpu': { | ||
| 'latency': (2.2, None, 0.10, 'us') | ||
| }, | ||
| 'daint:gpu': { | ||
| 'latency': (2.2, None, 0.10, 's') | ||
| }, | ||
| 'kesch:cn': { | ||
| 'latency': (5.7, None, 0.10, 'us') | ||
| }, | ||
| }, | ||
| } | ||
|
|
||
| self.reference = self.sys_reference[kernel_version] | ||
|
|
||
| self.maintainers = ['TM'] | ||
| self.tags = {'benchmark', 'diagnostic'} | ||
|
|
||
| @property | ||
| @sn.sanity_function | ||
| def num_tasks_assigned(self): | ||
| return self.job.num_tasks |
59 changes: 59 additions & 0 deletions
59
cscs-checks/microbenchmarks/kernel_latency/src/kernel_latency.cu
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,59 @@ | ||
| #include <iostream> | ||
| #include <chrono> | ||
| #include <ratio> | ||
| #include <unistd.h> | ||
| #include <cuda.h> | ||
|
|
||
| __global__ void null_kernel() { | ||
| }; | ||
|
|
||
| int main(int argc, char* argv[]) { | ||
|
|
||
| char hostname[256]; | ||
| hostname[255]='\0'; | ||
| gethostname(hostname, 255); | ||
|
|
||
| cudaError_t error; | ||
| int gpu_count = 0; | ||
|
|
||
| error = cudaGetDeviceCount(&gpu_count); | ||
|
|
||
| if (error == cudaSuccess) { | ||
| if (gpu_count <= 0) { | ||
| std::cout << "[" << hostname << "] " << "Could not find any gpu\n"; | ||
| return 1; | ||
| } | ||
| std::cout << "[" << hostname << "] " << "Found " << gpu_count << " gpu(s)\n"; | ||
| } | ||
| else{ | ||
| std::cout << "[" << hostname << "] " << "Error getting gpu count, exiting...\n"; | ||
| return 1; | ||
| } | ||
|
|
||
| for (int i = 0; i < gpu_count; i++) { | ||
|
|
||
| cudaSetDevice(i); | ||
| // Single kernel launch to initialize cuda runtime | ||
| null_kernel<<<1, 1>>>(); | ||
|
|
||
| auto t_start = std::chrono::system_clock::now(); | ||
| const int kernel_count = 1000; | ||
|
|
||
| for (int i = 0; i < kernel_count; ++i) { | ||
| null_kernel<<<1, 1>>>(); | ||
| #if SYNCKERNEL == 1 | ||
| cudaDeviceSynchronize(); | ||
| #endif | ||
| } | ||
|
|
||
| #if SYNCKERNEL != 1 | ||
| cudaDeviceSynchronize(); | ||
| #endif | ||
|
|
||
| auto t_end = std::chrono::system_clock::now(); | ||
| std::cout << "[" << hostname << "] " << "[gpu " << i << "] " << "Kernel launch latency: " << std::chrono::duration_cast<std::chrono::duration<double, std::micro>>(t_end - t_start).count() / kernel_count << " us\n"; | ||
| } | ||
|
|
||
| return 0; | ||
| } | ||
|
|
||
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.