Skip to content

Commit

Permalink
Add tests for ast_openmp and ast_cpp_hip
Browse files Browse the repository at this point in the history
  • Loading branch information
certik committed Jul 31, 2020
1 parent 3868f32 commit 775e95d
Show file tree
Hide file tree
Showing 6 changed files with 83 additions and 0 deletions.
10 changes: 10 additions & 0 deletions run_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ def main():
ast = test.get("ast", False)
ast_f90 = test.get("ast_f90", False)
ast_cpp = test.get("ast_cpp", False)
ast_cpp_hip = test.get("ast_cpp_hip", False)
ast_openmp = test.get("ast_openmp", False)
asr = test.get("asr", False)
llvm = test.get("llvm", False)
bin_ = test.get("bin", False)
Expand All @@ -64,6 +66,14 @@ def main():
run_test("ast_cpp", "cpptranslate --show-ast-cpp {infile}",
filename, update_reference)

if ast_cpp_hip:
run_test("ast_cpp_hip", "cpptranslate --show-ast-cpp-hip {infile}",
filename, update_reference)

if ast_openmp:
run_test("ast_openmp", "cpptranslate --show-ast-openmp {infile}",
filename, update_reference)

if asr:
run_test("asr", "lfortran --show-asr {infile} -o {outfile}",
filename, update_reference)
Expand Down
13 changes: 13 additions & 0 deletions tests/reference/ast_cpp_hip-subroutine4-918a576.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"basename": "ast_cpp_hip-subroutine4-918a576",
"cmd": "cpptranslate --show-ast-cpp-hip {infile}",
"infile": "tests/subroutine4.f90",
"infile_hash": "06ca8a1c322b25fe9280c43f558f6fa92e1a4843b6f6b77e206fdf4e",
"outfile": null,
"outfile_hash": null,
"stdout": "ast_cpp_hip-subroutine4-918a576.stdout",
"stdout_hash": "a6cc3f90c3064b7e0fd74db7867cdb22291414e18ed43fe44c463b6b",
"stderr": null,
"stderr_hash": null,
"returncode": 0
}
30 changes: 30 additions & 0 deletions tests/reference/ast_cpp_hip-subroutine4-918a576.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#define blocksize 128

//Pass by value variables found in the loop body: scalar
//Pass by reference variables found in the loop body: b a c
__global__ void Tempkernelname(int N, float scalar, float *b, float *a, float *c){
int i = blockIDx.x*blockDim.x+threadIdx.x;
if (i >= N) return;
c[i] = (a[i]) + ((scalar)*(b[i]));
}

void triad(float *a, size_t a_size, float *b, size_t b_size, float scalar,
float *c, size_t c_size)
{
size_t N;
size_t i;
N = a_size;
int gridsize = (N + blocksize - 1)/blocksize;
float *b_d;
hipMalloc(&b_d, N*sizeof(float));
hipMemcpy(b_d, b, N*sizeof(float), hipMemcpyHostToDevice);
float *a_d;
hipMalloc(&a_d, N*sizeof(float));
hipMemcpy(a_d, a, N*sizeof(float), hipMemcpyHostToDevice);
float *c_d;
hipMalloc(&c_d, N*sizeof(float));
hipMemcpy(c_d, c, N*sizeof(float), hipMemcpyHostToDevice);
hipLaunchKernelGGL(Tempkernelname, dim3(gridsize), dim3(blocksize), 0, 0, N, scalar, b_d, a_d, c_d);

}

13 changes: 13 additions & 0 deletions tests/reference/ast_openmp-subroutine4-0411983.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
{
"basename": "ast_openmp-subroutine4-0411983",
"cmd": "cpptranslate --show-ast-openmp {infile}",
"infile": "tests/subroutine4.f90",
"infile_hash": "06ca8a1c322b25fe9280c43f558f6fa92e1a4843b6f6b77e206fdf4e",
"outfile": null,
"outfile_hash": null,
"stdout": "ast_openmp-subroutine4-0411983.stdout",
"stdout_hash": "2ba13829eb08486a48eae11b2da02196deecbc68ae4c8c53c6c633bc",
"stderr": null,
"stderr_hash": null,
"returncode": 0
}
15 changes: 15 additions & 0 deletions tests/reference/ast_openmp-subroutine4-0411983.stdout
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
subroutine triad(a, b, scalar, c)
real, intent(in) :: a(:)
real, intent(in) :: b(:)
real, intent(in) :: scalar
real, intent(out) :: c(:)
integer :: N
integer :: i
N = size(a)
!$OMP PARALLEL DO
do i = 1:N
c(i) = (a(i)) + ((scalar)*(b(i)))
end do
!$OMP END PARALLEL DO
end subroutine triad

2 changes: 2 additions & 0 deletions tests/tests.toml
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,8 @@ filename = "subroutine4.f90"
ast = true
ast_f90 = true
ast_cpp = true
ast_cpp_hip = true
ast_openmp = true
asr = true

[[test]]
Expand Down

0 comments on commit 775e95d

Please sign in to comment.