Skip to content

Commit

Permalink
Merge pull request #89 from intel/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
chuckyount authored Mar 8, 2018
2 parents 4df70ad + 309b38c commit 1ffd414
Show file tree
Hide file tree
Showing 34 changed files with 1,428 additions and 404 deletions.
24 changes: 24 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -193,6 +193,26 @@ py-yc-api-and-cxx-yk-api-test:
$(YK_MAKE) py-yc-api-test
$(YK_MAKE) cxx-yk-api-test

# Run C++ compiler API test with exception, then run C++ kernel API test with exception.
cxx-yc-api-and-cxx-yk-api-test-with-exception:
$(YK_MAKE) cxx-yc-api-test-with-exception
$(YK_MAKE) cxx-yk-api-test-with-exception

# Run python compiler API test with exception, then run python kernel API test with exception.
py-yc-api-and-py-yk-api-test-with-exception:
$(YK_MAKE) py-yc-api-test-with-exception
$(YK_MAKE) py-yk-api-test-with-exception

# Run C++ compiler API test with exception, then run python kernel API test with exception.
cxx-yc-api-and-py-yk-api-test-with-exception:
$(YK_MAKE) cxx-yc-api-test-with-exception
$(YK_MAKE) py-yk-api-test-with-exception

# Run python compiler API test with exception, then run C++ kernel API test with exception.
py-yc-api-and-cxx-yk-api-test-with-exception:
$(YK_MAKE) py-yc-api-test-with-exception
$(YK_MAKE) cxx-yk-api-test-with-exception

api-tests:
$(MAKE) yc-and-cxx-yk-api-test
$(MAKE) yc-and-py-yk-api-test
Expand All @@ -202,6 +222,10 @@ api-tests:
$(MAKE) stencil=test py-yc-api-and-py-yk-api-test
$(MAKE) stencil=test cxx-yc-api-and-py-yk-api-test
$(MAKE) stencil=test py-yc-api-and-cxx-yk-api-test
$(MAKE) stencil=test cxx-yc-api-and-cxx-yk-api-test-with-exception
$(MAKE) stencil=test py-yc-api-and-py-yk-api-test-with-exception
$(MAKE) stencil=test cxx-yc-api-and-py-yk-api-test-with-exception
$(MAKE) stencil=test py-yc-api-and-cxx-yk-api-test-with-exception

######## Misc targets

Expand Down
130 changes: 130 additions & 0 deletions bin/yask_compiler_api_exception_test.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,130 @@
#!/usr/bin/env python

##############################################################################
## YASK: Yet Another Stencil Kernel
## Copyright (c) 2014-2018, Intel Corporation
##
## Permission is hereby granted, free of charge, to any person obtaining a copy
## of this software and associated documentation files (the "Software"), to
## deal in the Software without restriction, including without limitation the
## rights to use, copy, modify, merge, publish, distribute, sublicense, and/or
## sell copies of the Software, and to permit persons to whom the Software is
## furnished to do so, subject to the following conditions:
##
## * The above copyright notice and this permission notice shall be included in
## all copies or substantial portions of the Software.
##
## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
## FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
## IN THE SOFTWARE.
##############################################################################

## Test the YASK stencil compiler API for Python.

import yask_compiler

if __name__ == "__main__":

# Counter for exception test
num_exception = 0;

# Compiler 'bootstrap' factories.
cfac = yask_compiler.yc_factory()
ofac = yask_compiler.yask_output_factory()
nfac = yask_compiler.yc_node_factory()

# Create a new stencil solution.
soln = cfac.new_solution("api_py_test")
do = ofac.new_string_output()
soln.set_debug_output(do)

# Define the problem dimensions.
t = nfac.new_step_index("t");
x = nfac.new_domain_index("x");
y = nfac.new_domain_index("y");
z = nfac.new_domain_index("z");

# Create a grid var.
g1 = soln.new_grid("test_grid", [t, x, y, z])

# Create an expression for the new value.
# This will average some of the neighboring points around the
# current stencil application point in the current timestep.
n0 = g1.new_relative_grid_point([0, 0, 0, 0]) # center-point at this timestep.

# Exception test
print("Exception Test: Call 'new_relative_grid_point' with wrong argument.")
try:
n1 = nfac.new_add_node(n0, g1.new_relative_grid_point([0, -1, 0, 0, 1])) # left.
except RuntimeError as e:
print ("YASK throws an exception.")
print (format(e))
print ("Exception Test: Catch exception correctly.")
num_exception = num_exception + 1

n1 = nfac.new_add_node(n0, g1.new_relative_grid_point([0, -1, 0, 0])) # left.
n1 = nfac.new_add_node(n1, g1.new_relative_grid_point([0, 1, 0, 0])) # right.
n1 = nfac.new_add_node(n1, g1.new_relative_grid_point([0, 0, -1, 0])) # above.
n1 = nfac.new_add_node(n1, g1.new_relative_grid_point([0, 0, 1, 0])) # below.
n1 = nfac.new_add_node(n1, g1.new_relative_grid_point([0, 0, 0, -1])) # in front.
n1 = nfac.new_add_node(n1, g1.new_relative_grid_point([0, 0, 0, 1])) # behind.
n2 = nfac.new_divide_node(n1, nfac.new_const_number_node(7)) # div by 7.

# Create an equation to define the value at the next timestep.
n3 = g1.new_relative_grid_point([1, 0, 0, 0]) # center-point at next timestep.
n4 = nfac.new_equation_node(n3, n2) # equate to expr n2.
print("Equation before formatting: " + n4.format_simple())
print("Solution '" + soln.get_name() + "' contains " +
str(soln.get_num_grids()) + " grid(s), and " +
str(soln.get_num_equations()) + " equation(s).")
for grid in soln.get_grids() :
print("Grid " + grid.get_name() +
" has the following dim(s): " +
repr(grid.get_dim_names()));

# Number of bytes in each FP value.
soln.set_element_bytes(4)

# Exception test
print("Exception Test: Call 'new_file_output' with read-only file name.")
try:
dot_file = ofac.new_file_output("yc-api-test-with-exception-py-readonly")
except RuntimeError as e:
print ("YASK throws an exception.")
print (format(e))
print ("Exception Test: Catch exception correctly.")
num_exception = num_exception + 1

# Generate DOT output.
dot_file = ofac.new_file_output("yc-api-test-with-exception-py.dot")
soln.format("dot", dot_file)
print("DOT-format written to '" + dot_file.get_filename() + "'.")

# Generate YASK output.
yask_file = ofac.new_file_output("yc-api-test-with-exception-py.hpp")
soln.format("avx", yask_file)
print("YASK-format written to '" + yask_file.get_filename() + "'.")

# Exception test
try:
soln.format("wrong_format", dot_file)
except RuntimeError as e:
print ("YASK throws an exception.")
print (format(e))
print ("Exception Test: Catch exception correctly.")
num_exception = num_exception + 1

print("Equation after formatting: " + soln.get_equation(0).format_simple())

print("Debug output captured:\n" + do.get_string())

# Check whether program handles exceptions or not.
if num_exception != 3:
print("There is a problem in exception test.")
exit(1)
else:
print("End of YASK compiler API test with exception.")
Loading

0 comments on commit 1ffd414

Please sign in to comment.