Skip to content

Commit

Permalink
Merge pull request #109 from intel/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
chuckyount authored Apr 28, 2018
2 parents e912981 + 6d2cd4f commit 47d1115
Show file tree
Hide file tree
Showing 49 changed files with 6,274 additions and 4,684 deletions.
47 changes: 18 additions & 29 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -138,6 +138,9 @@ compiler-api:
kernel-api:
$(YK_MAKE) api

py-kernel-api:
$(YK_MAKE) py-api

api:
$(YC_MAKE) $@
$(YK_MAKE) $@
Expand Down Expand Up @@ -193,39 +196,21 @@ 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
# Run 8 out of 9 combos of (built-in, C++, Python)^2
# API tests. The 9th one is built-in with built-in,
# which is tested more extensively in the kernel tests.
# When the built-in stencil examples aren't being used,
# "stencil=test" in the commands below is simply used to
# create file names.
combo-api-tests:
$(MAKE) stencil=iso3dfd yc-and-cxx-yk-api-test
$(MAKE) stencil=iso3dfd yc-and-py-yk-api-test
$(MAKE) stencil=test cxx-yc-api-and-yk-test
$(MAKE) stencil=test py-yc-api-and-yk-test
$(MAKE) stencil=test cxx-yc-api-and-cxx-yk-api-test
$(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 All @@ -245,10 +230,14 @@ tuple-test: $(TUPLE_TEST_EXEC)
@echo '*** Running the C++ YASK tuple test...'
$(RUN_PREFIX) $<

all-tests: compiler
api-tests: compiler-api
$(MAKE) combo-api-tests
$(YK_MAKE) $@

all-tests: compiler-api
$(MAKE) tuple-test
$(MAKE) combo-api-tests
$(YK_MAKE) $@
$(MAKE) api-tests

docs: api-docs

Expand Down
17 changes: 15 additions & 2 deletions bin/gen_loops.pl
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,9 @@ sub stepVar {
sub alignVar {
return inVar("align", @_);
}
sub alignOfsVar {
return inVar("align_ofs", @_);
}
sub groupSizeVar {
return inVar("group_size", @_);
}
Expand Down Expand Up @@ -201,18 +204,28 @@ ($$$)
my $evar = endVar($dim);
my $svar = stepVar($dim);
my $avar = alignVar($dim);
my $aovar = alignOfsVar($dim);
my $aavar = adjAlignVar($dim);
my $abvar = alignBeginVar($dim);
my $nvar = numItersVar($dim);
my $ntvar = numGroupsVar($dim);
my $tsvar = groupSizeVar($dim);
my $ntivar = numFullGroupItersVar($dim);

# Example alignment:
# bvar = 20.
# svar = 8.
# avar = 4.
# aovar = 15.
# Then,
# aavar = min(4, 8) = 4.
# abvar = round_down_flr(20 - 15, 4) + 15 = 4 + 15 = 19.

push @$code,
" // Alignment must be less than or equal to step size.",
" const $itype $aavar = std::min($avar, $svar);",
" // Aligned beginning point. May be at or before $bvar.",
" const $itype $abvar = yask::round_down_flr($bvar, $aavar);",
" // Aligned beginning point such that ($bvar - $svar) < $abvar <= $bvar.",
" const $itype $abvar = yask::round_down_flr($bvar - $aovar, $aavar) + $aovar;",
" // Number of iterations to get from $abvar to (but not including) $evar, stepping by $svar.".
" This value is rounded up because the last iteration may cover fewer than $svar steps.",
" const $itype $nvar = yask::ceil_idiv_flr($evar - $abvar, $svar);";
Expand Down
248 changes: 248 additions & 0 deletions bin/gen_nodes.pl
Original file line number Diff line number Diff line change
@@ -0,0 +1,248 @@
#! /usr/bin/env perl
#-*-Perl-*- This line forces emacs to use Perl mode.

# This utility is used to generate some API code for the compiler.
# The code generated may require additional editing, so it is only
# used for one-time generation.

use strict;
use File::Basename;
use File::Path;
use lib dirname($0)."/lib";
use lib dirname($0)."/../lib";

use File::Which;
use Text::ParseWords;
use FileHandle;
use CmdLine;

$| = 1; # autoflush.

# num to num.
my %nops = ("add" => "+",
"subtract" => "-",
"multiply" => "*",
"divide" => "/");
my %bnops = ("negate" => "-");

# num to bool.
my %nbops = ("equals" => "==",
"not_equals" => "!=",
"less_than" => "<",
"greater_than" => ">",
"not_less_than" => ">=",
"not_greater_than" => "<=");

# bool to bool.
my %bbops = ("and" => "&&",
"or" => "||");
my %ubops = ("not" => "!");

# decls.
for my $node (sort keys %nbops,
sort keys %bbops,
sort keys %ubops) {
my $n2 = "yc_${node}_node";
print
" class $n2;\n".
" /// Shared pointer to \\ref $n2\n".
" typedef std::shared_ptr<$n2> ${n2}_ptr;\n\n";
}

# swig decls.
for my $node (sort keys %nbops,
sort keys %bbops,
sort keys %ubops) {
my $n2 = "yc_${node}_node";
print "\%shared_ptr(yask::$n2)\n";
}

# binary ops.
for my $node (sort keys %bbops) {
my $n2 = "yc_${node}_node";
my $oper = $bbops{$node};

print <<"END";
/// Create a boolean $node node.
/**
\@returns Pointer to new \\ref $n2 object.
*/
virtual ${n2}_ptr
new_${node}_node(yc_bool_node_ptr lhs /**< [in] Expression before '$oper' sign. */,
yc_bool_node_ptr rhs /**< [in] Expression after '$oper' sign. */ );
END
}

# comparison ops.
for my $node (sort keys %nbops) {
my $n2 = "yc_${node}_node";
my $oper = $nbops{$node};

print <<"END";
/// Create a numerical-comparison '$node' node.
/**
\@returns Pointer to new \\ref $n2 object.
*/
virtual ${n2}_ptr
new_${node}_node(yc_number_node_ptr lhs /**< [in] Expression before '$oper' sign. */,
yc_number_node_ptr rhs /**< [in] Expression after '$oper' sign. */ );
END
}

# binary ops.
for my $node (sort keys %bbops) {
my $n2 = "yc_${node}_node";
my $oper = $bbops{$node};

print <<"END";
/// A boolean '$node' operator.
/** Example: used to implement `a $oper b`.
Created via yc_node_factory::new_${node}_node().
*/
class $n2 : public virtual yc_bool_node {
public:
/// Get the left-hand-side operand.
/** \@returns Expression node on left-hand-side of '$oper' sign. */
virtual yc_bool_node_ptr
get_lhs() =0;
/// Get the right-hand-size operand.
/** \@returns Expression node on right-hand-side of '$oper' sign. */
virtual yc_bool_node_ptr
get_rhs() =0;
};
END
}

# comparison ops.
for my $node (sort keys %nbops) {
my $n2 = "yc_${node}_node";
my $oper = $nbops{$node};

print <<"END";
/// A numerical-comparison '$node' operator.
/** Example: used to implement `a $oper b`.
Created via yc_node_factory::new_${node}_node().
*/
class $n2 : public virtual yc_bool_node {
public:
/// Get the left-hand-side operand.
/** \@returns Expression node on left-hand-side of '$oper' sign. */
virtual yc_bool_node_ptr
get_lhs() =0;
/// Get the right-hand-size operand.
/** \@returns Expression node on right-hand-side of '$oper' sign. */
virtual yc_bool_node_ptr
get_rhs() =0;
};
END
}

# binary ops.
for my $node (sort keys %bbops) {
my $n2 = "yc_${node}_node";
my $oper = $bbops{$node};
my $n3 = $node;
$n3 =~ s/([a-z]+)/\u\L$1/g;
$n3 =~ s/_//g;
$n3 .= 'Expr';

print <<"END";
${n2}_ptr
yc_node_factory::new_${node}_node(yc_bool_node_ptr lhs,
yc_bool_node_ptr rhs) {
auto lp = dynamic_pointer_cast<BoolExpr>(lhs);
assert(lp);
auto rp = dynamic_pointer_cast<BoolExpr>(rhs);
assert(rp);
return make_shared<$n3>(lp, rp);
}
END
}

# comparison ops.
for my $node (sort keys %nbops) {
my $n2 = "yc_${node}_node";
my $oper = $nbops{$node};
my $n3 = $node;
$n3 =~ s/([a-z]+)/\u\L$1/g;
$n3 =~ s/_//g;
$n3 .= 'Expr';

print <<"END";
${n2}_ptr
yc_node_factory::new_${node}_node(yc_number_node_ptr lhs,
yc_number_node_ptr rhs) {
auto lp = dynamic_pointer_cast<NumExpr>(lhs);
assert(lp);
auto rp = dynamic_pointer_cast<NumExpr>(rhs);
assert(rp);
return make_shared<$n3>(lp, rp);
}
END
}

# binary num ops.
for my $node (sort keys %nops) {
my $n2 = "yc_${node}_node";
my $n2p = $n2.'_ptr';
my $oper = $nops{$node};
print "$n2p operator$oper(yc_number_node_ptr lhs, yc_number_node_ptr rhs);\n";
print "$n2p operator$oper(double lhs, yc_number_node_ptr rhs);\n";
print "$n2p operator$oper(yc_number_node_ptr lhs, double);\n";
}

# binary num ops.
for my $node (sort keys %nops) {
my $n2 = "yc_${node}_node";
my $n2p = $n2.'_ptr';
my $oper = $nops{$node};
my $n3 = $node;
$n3 =~ s/([a-z]+)/\u\L$1/g;
$n3 =~ s/_//g;
$n3 .= 'Expr';

print <<"END";
$n2p operator$oper(yc_number_node_ptr lhs, yc_number_node_ptr rhs) {
auto lp = dynamic_pointer_cast<NumExpr>(lhs);
assert(lp);
auto rp = dynamic_pointer_cast<NumExpr>(rhs);
assert(rp);
return make_shared<$n3>(lp, rp);
}
$n2p operator$oper(double lhs, yc_number_node_ptr rhs) {
return operator$oper(constNum(lhs), rhs);
}
$n2p operator$oper(yc_number_node_ptr lhs, double rhs) {
return operator$oper(lhs, constNum(rhs));
}
END
}

# binary num ops.
for my $node (sort keys %nops) {
my $n2 = "yc_${node}_node";
my $n2p = $n2.'_ptr';
my $oper = $nops{$node};
my $n3 = $node;
$n3 =~ s/([a-z]+)/\u\L$1/g;
$n3 =~ s/_//g;
$n3 .= 'Expr';

print <<"END";
%extend yask::yc_number_node {
yask::yc_number_node_ptr __${node}__(yask::yc_number_node* rhs) {
auto lp = \$self->clone_ast();
auto rp = rhs->clone_ast();
return yask::operator$oper(lp, rp);
}
};
END
}
4 changes: 0 additions & 4 deletions bin/yask_compiler_api_exception_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -118,10 +118,6 @@
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.")
Expand Down
Loading

0 comments on commit 47d1115

Please sign in to comment.