## 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__": print("YASK compiler API test...") # 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"); # Example index expression. e0 = x + 3; print("Simple index expression: " + e0.format_simple());
from devito.tools import ctypes_pointer def exit(emsg): """ Handle fatal errors. """ raise InvalidOperator("YASK Error [%s]. Exiting..." % emsg) log("Backend initialization...") try: import yask_compiler as yc # YASK compiler factories cfac = yc.yc_factory() nfac = yc.yc_node_factory() ofac = yc.yask_output_factory() except ImportError: exit("Python YASK compiler bindings") try: # Set directories for generated code path = os.environ['YASK_HOME'] except KeyError: exit("Missing YASK_HOME") # YASK conventions namespace = OrderedDict() namespace['jit-yc-hook'] = lambda i, j: 'devito_%s_yc_hook%d' % (i, j) namespace['jit-yk-hook'] = lambda i, j: 'devito_%s_yk_hook%d' % (i, j) namespace['jit-yc-soln'] = lambda i, j: 'devito_%s_yc_soln%d' % (i, j) namespace['jit-yk-soln'] = lambda i, j: 'devito_%s_yk_soln%d' % (i, j)