Skip to content

Commit

Permalink
test: test suite for testing CUDA code generation
Browse files Browse the repository at this point in the history
  • Loading branch information
magnatelee committed Dec 18, 2018
1 parent 0b2e28f commit 3e1e640
Show file tree
Hide file tree
Showing 2 changed files with 136 additions and 3 deletions.
18 changes: 15 additions & 3 deletions language/test.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ def __init__(self):
self.passed = 0
self.failed = 0

def get_test_specs(legion_dir, use_run, use_spy, use_prof, use_hdf5, use_openmp, use_python, short, extra_flags):
def get_test_specs(legion_dir, use_run, use_spy, use_prof, use_hdf5, use_openmp, use_cuda, use_python, short, extra_flags):
base = [
# FIXME: Move this flag into a per-test parameter so we don't use it everywhere.
# Don't include backtraces on those expected to fail
Expand Down Expand Up @@ -328,6 +328,11 @@ def get_test_specs(legion_dir, use_run, use_spy, use_prof, use_hdf5, use_openmp,
(os.path.join('tests', 'openmp', 'run_pass'),
)),
]
cuda = [
('run_pass', (test_run_pass, ([] + extra_flags, {})),
(os.path.join('tests', 'cuda', 'run_pass'),
)),
]
py_env = {
'PYTHONPATH': ':'.join(
os.environ.get('PYTHONPATH', '').split(':') + [
Expand Down Expand Up @@ -357,11 +362,13 @@ def get_test_specs(legion_dir, use_run, use_spy, use_prof, use_hdf5, use_openmp,
result.extend(hdf5)
if use_openmp:
result.extend(openmp)
if use_cuda:
result.extend(cuda)
if use_python:
result.extend(python)
return result

def run_all_tests(thread_count, debug, run, spy, prof, hdf5, openmp, python, extra_flags, verbose, quiet,
def run_all_tests(thread_count, debug, run, spy, prof, hdf5, openmp, cuda, python, extra_flags, verbose, quiet,
only_patterns, skip_patterns, timelimit, short):
thread_pool = multiprocessing.Pool(thread_count)
results = []
Expand All @@ -371,7 +378,7 @@ def run_all_tests(thread_count, debug, run, spy, prof, hdf5, openmp, python, ext
py_exe_path = detect_python_interpreter()

# Run tests asynchronously.
tests = get_test_specs(legion_dir, run, spy, prof, hdf5, openmp, python, short, extra_flags)
tests = get_test_specs(legion_dir, run, spy, prof, hdf5, openmp, cuda, python, short, extra_flags)
for test_name, test_fn, test_dirs in tests:
test_paths = []
for test_dir in test_dirs:
Expand Down Expand Up @@ -504,6 +511,10 @@ def test_driver(argv):
action='store_true',
help='run OpenMP tests',
dest='openmp')
parser.add_argument('--cuda',
action='store_true',
help='run CUDA tests',
dest='cuda')
parser.add_argument('--python',
action='store_true',
help='run Python tests',
Expand Down Expand Up @@ -550,6 +561,7 @@ def test_driver(argv):
args.prof,
args.hdf5,
args.openmp,
args.cuda,
args.python,
args.extra_flags,
args.verbose,
Expand Down
121 changes: 121 additions & 0 deletions language/tests/cuda/run_pass/region_reduce.rg
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
-- Copyright 2018 Stanford University, NVIDIA Corporation
--
-- Licensed under the Apache License, Version 2.0 (the "License");
-- you may not use this file except in compliance with the License.
-- You may obtain a copy of the License at
--
-- http://www.apache.org/licenses/LICENSE-2.0
--
-- Unless required by applicable law or agreed to in writing, software
-- distributed under the License is distributed on an "AS IS" BASIS,
-- WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-- See the License for the specific language governing permissions and
-- limitations under the License.

-- runs-with:
-- [["-fcuda", "1", "-ll:gpu", "1" ]]

import "regent"

local function generate_fs(type)
local fs
fspace fs
{
input : type,
output_add : type,
output_mul : type,
}
return fs
end

local function generate_init(type)
local tsk
task tsk(r : region(ispace(int1d), type))
where
reads writes(r)
do
for e in r do
e.input = 2
e.output_add = 0
e.output_mul = 1
end
end
return tsk
end

local function generate_red(type)
local tsk
__demand(__cuda)
task tsk(is : ispace(int1d),
size : int,
rep : int,
r : region(ispace(int1d), type))
where
reads(r.input), reads writes(r.{output_add, output_mul})
do
for p in is do
var target = [int](p) / rep
var v = r[target].input
r[target].output_add += v
r[target].output_mul *= v
end
end
return tsk
end

local function generate_check(type)
local tsk
task tsk(r : region(ispace(int1d), type),
rep : int)
where
reads(r.{output_add, output_mul})
do
var p = 1
for i = 0, rep do p *= 2 end
for e in r do
regentlib.assert(e.output_add == rep * 2, "test failed")
regentlib.assert(e.output_mul == p, "test failed")
end
end
return tsk
end

local types = terralib.newlist({
float, double
})

local fs_types = types:map(generate_fs)
local init_tasks = fs_types:map(generate_init)
local red_tasks = fs_types:map(generate_red)
local check_tasks = fs_types:map(generate_check)

local test_tasks = terralib.newlist()
local function generate_test(idx)
local tsk
local fs = fs_types[idx]
local init_task = init_tasks[idx]
local red_task = red_tasks[idx]
local check_task = check_tasks[idx]
task tsk(size : int, rep : int)
var is = ispace(int1d, size * rep)
var r = region(ispace(int1d, size), fs)

init_task(r)
red_task(is, size, rep, r)
check_task(r, rep)
end
return tsk
end
for idx = 1, #types do
test_tasks:insert(generate_test(idx))
end

task toplevel()
[test_tasks:map(function(test_task)
return rquote
[test_task](100, 5)
end
end)]
end

regentlib.start(toplevel)

0 comments on commit 3e1e640

Please sign in to comment.