-
Notifications
You must be signed in to change notification settings - Fork 50
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #197 from KernelTuner/openacc
Merging OpenACC tuning support, and fixing Issue #193 in the process.
- Loading branch information
Showing
18 changed files
with
1,209 additions
and
269 deletions.
There are no files selected for viewing
This file contains 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 |
---|---|---|
|
@@ -33,3 +33,6 @@ temp_*.* | |
.DS_Store | ||
.AppleDouble | ||
.LSOverride | ||
|
||
.vscode | ||
.idea |
This file contains 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,67 @@ | ||
#!/usr/bin/env python | ||
"""This is a simple example for tuning C++ OpenACC code with the kernel tuner""" | ||
|
||
from kernel_tuner import tune_kernel | ||
from kernel_tuner.utils.directives import ( | ||
extract_directive_signature, | ||
extract_directive_code, | ||
extract_preprocessor, | ||
generate_directive_function, | ||
extract_directive_data, | ||
allocate_signature_memory, | ||
) | ||
from collections import OrderedDict | ||
|
||
code = """ | ||
#include <stdlib.h> | ||
#define VECTOR_SIZE 65536 | ||
int main(void) { | ||
int size = VECTOR_SIZE; | ||
float * a = (float *) malloc(VECTOR_SIZE * sizeof(float)); | ||
float * b = (float *) malloc(VECTOR_SIZE * sizeof(float)); | ||
float * c = (float *) malloc(VECTOR_SIZE * sizeof(float)); | ||
#pragma tuner start vector_add a(float*:VECTOR_SIZE) b(float*:VECTOR_SIZE) c(float*:VECTOR_SIZE) size(int:VECTOR_SIZE) | ||
#pragma acc parallel num_gangs(ngangs) vector_length(nthreads) | ||
#pragma acc loop | ||
for ( int i = 0; i < size; i++ ) { | ||
c[i] = a[i] + b[i]; | ||
} | ||
#pragma tuner stop | ||
free(a); | ||
free(b); | ||
free(c); | ||
} | ||
""" | ||
|
||
# Extract tunable directive and generate kernel_string | ||
preprocessor = extract_preprocessor(code) | ||
signature = extract_directive_signature(code) | ||
body = extract_directive_code(code) | ||
kernel_string = generate_directive_function( | ||
preprocessor, signature["vector_add"], body["vector_add"] | ||
) | ||
|
||
# Allocate memory on the host | ||
data = extract_directive_data(code) | ||
args = allocate_signature_memory(data["vector_add"], preprocessor) | ||
|
||
tune_params = OrderedDict() | ||
tune_params["ngangs"] = [2**i for i in range(0, 15)] | ||
tune_params["nthreads"] = [2**i for i in range(0, 11)] | ||
|
||
answer = [None, None, args[0] + args[1], None] | ||
|
||
tune_kernel( | ||
"vector_add", | ||
kernel_string, | ||
0, | ||
args, | ||
tune_params, | ||
answer=answer, | ||
compiler_options=["-fast", "-acc=gpu"], | ||
compiler="nvc++", | ||
) |
This file contains 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 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 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 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 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,62 @@ | ||
#!/usr/bin/env python | ||
"""This is a simple example for tuning Fortran OpenACC code with the kernel tuner""" | ||
|
||
from kernel_tuner import tune_kernel | ||
from kernel_tuner.utils.directives import ( | ||
extract_directive_signature, | ||
extract_directive_code, | ||
extract_preprocessor, | ||
generate_directive_function, | ||
extract_directive_data, | ||
allocate_signature_memory, | ||
) | ||
from collections import OrderedDict | ||
|
||
code = """ | ||
#define VECTOR_SIZE 65536 | ||
subroutine vector_add(A, B, C, n) | ||
use iso_c_binding | ||
real (c_float), intent(out), dimension(VECTOR_SIZE) :: C | ||
real (c_float), intent(in), dimension(VECTOR_SIZE) :: A, B | ||
integer (c_int), intent(in) :: n | ||
!$tuner start vector_add A(float*:VECTOR_SIZE) B(float*:VECTOR_SIZE) C(float*:VECTOR_SIZE) n(int:VECTOR_SIZE) | ||
!$acc parallel loop num_gangs(ngangs) vector_length(vlength) | ||
do i = 1, n | ||
C(i) = A(i) + B(i) | ||
end do | ||
!$acc end parallel loop | ||
!$tuner stop | ||
end subroutine vector_add | ||
""" | ||
|
||
# Extract tunable directive and generate kernel_string | ||
preprocessor = extract_preprocessor(code) | ||
signature = extract_directive_signature(code) | ||
body = extract_directive_code(code) | ||
kernel_string = generate_directive_function( | ||
preprocessor, signature["vector_add"], body["vector_add"] | ||
) | ||
|
||
# Allocate memory on the host | ||
data = extract_directive_data(code) | ||
args = allocate_signature_memory(data["vector_add"], preprocessor) | ||
|
||
tune_params = OrderedDict() | ||
tune_params["ngangs"] = [2**i for i in range(0, 15)] | ||
tune_params["vlength"] = [2**i for i in range(0, 11)] | ||
|
||
answer = [None, None, args[0] + args[1], None] | ||
|
||
tune_kernel( | ||
"vector_add", | ||
kernel_string, | ||
0, | ||
args, | ||
tune_params, | ||
answer=answer, | ||
compiler_options=["-fast", "-acc=gpu"], | ||
compiler="nvfortran", | ||
) |
This file contains 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
Oops, something went wrong.