Skip to content

Commit

Permalink
[kernels] boolean scalar equality operators
Browse files Browse the repository at this point in the history
EwBinarySca was missing the implementation for boolean equality
operators, meaning that simple equality checks for control flow using
booleans was not working.

Adds a testcase.

Previous error:
RewriteToCallKernelOpPass failed with the following message [ no kernel
for operation `ewEq` available for the required input types `(i1, i1)`
and output types `(i1)`

A = rand(1,1, 0.0, 1.0, 1.0, -1);
x = as.scalar<f64>(A[0,0]);

terminate = false;
while (terminate == false) {
    if (x > 0.5) {
        terminate = true;
    }
    x = x + 0.5;
}
print("done.");
  • Loading branch information
philipportner committed Nov 12, 2024
1 parent abc6c38 commit 287f4c5
Show file tree
Hide file tree
Showing 5 changed files with 16 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/runtime/local/kernels/BinaryOpCode.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,6 +165,7 @@ static constexpr bool supportsBinaryOp = false;

// Concise specification of which binary operations should be supported on
// which value types.
SUPPORT_EQUALITY(bool)
SUPPORT_NUMERIC_FP(double)
SUPPORT_NUMERIC_FP(float)
SUPPORT_NUMERIC_INT(int64_t)
Expand Down
1 change: 1 addition & 0 deletions src/runtime/local/kernels/kernels.json
Original file line number Diff line number Diff line change
Expand Up @@ -2158,6 +2158,7 @@
["int64_t", "int64_t", "int64_t"],
["uint64_t", "uint64_t", "uint64_t"],
["uint32_t", "uint32_t", "uint32_t"],
["bool", "bool", "bool"],
["size_t", "size_t", "size_t"],
["const char *", "const char *", "const char *"],
["int64_t", "const char *", "const char *"]
Expand Down
4 changes: 2 additions & 2 deletions test/api/cli/controlflow/ControlFlowTest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,7 +51,7 @@ const std::string dirPath = "test/api/cli/controlflow/";

MAKE_TEST_CASE("if", 8)
MAKE_TEST_CASE("for", 23)
MAKE_TEST_CASE("while", 16)
MAKE_TEST_CASE("while", 17)
MAKE_TEST_CASE("nested", 26)

MAKE_FAILURE_TEST_CASE("stop", 2)
Expand All @@ -70,4 +70,4 @@ TEST_CASE("loop-with-many-iterations_variadic-op", TAG_CONTROLFLOW) {
exp << "Frame(1x1, [col_0:int64_t])" << std::endl << i << std::endl;
compareDaphneToStr(exp.str(), dirPath + "for_manyiterations_2.daphne");
compareDaphneToStr(exp.str(), dirPath + "while_manyiterations_2.daphne");
}
}
11 changes: 11 additions & 0 deletions test/api/cli/controlflow/while_17.daphne
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
A = rand(1,1, 0.0, 1.0, 1.0, -1);
x = as.scalar<f64>(A[0,0]);

terminate = false;
while (terminate == false) {
if (x > 0.5) {
terminate = true;
}
x = x + 0.5;
}
print("done.");
1 change: 1 addition & 0 deletions test/api/cli/controlflow/while_17.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
done.

0 comments on commit 287f4c5

Please sign in to comment.