Skip to content

Commit

Permalink
Merge pull request #236 from kokkos/gligoric/pass-stmt
Browse files Browse the repository at this point in the history
Add support for the pass statement in trivial cases (empty body) (closes #236)
  • Loading branch information
NaderAlAwar authored Jan 7, 2024
2 parents 2e0b664 + 2353e9f commit f36cbe9
Show file tree
Hide file tree
Showing 3 changed files with 19 additions and 4 deletions.
14 changes: 11 additions & 3 deletions pk
Original file line number Diff line number Diff line change
Expand Up @@ -48,14 +48,21 @@ function pk_docker_pull() {

function _pk_cmd() {
local -r name="${1}"
[ $# -lt 1 ] && return 1
shift 1

[ -z "${name}" ] && \
{ echo "no name provided"; return 1; }

( cd "${CHOME}/pykokkos"
export PYTHONPATH=pykokkos:$PYTHONPATH
python "${name}" )
python "${name}" "$@" )
}

function pk_example() {
local -r name="${1}"
[ $# -lt 1 ] && return 1
shift 1

[ -z "${name}" ] && \
{ echo "no name provided (e.g., examples/kokkos-tutorials/workload/01.py)"; return 1; }
Expand All @@ -67,11 +74,12 @@ function pk_example() {
--volume $(pwd):"${CHOME}/pykokkos" \
--user pk:$(id -g) \
"${PROJECT}" \
"${CHOME}/pykokkos/pk" "_pk_cmd" "${name}"
"${CHOME}/pykokkos/pk" "_pk_cmd" "${name}" \
"$@"
}

function pk_tests() {
pk_example "runtests.py"
pk_example "runtests.py" "$@"
}

"$@"
2 changes: 1 addition & 1 deletion pykokkos/core/cppast/serializer.py
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ def serialize_DeclStmt(self, node: DeclStmt) -> str:
return self.serialize(node.decl) + ";"

def serialize_EmptyStmt(self, node: EmptyStmt) -> str:
return ""
return "{}"

def serialize_ForStmt(self, node: ForStmt) -> str:
init: str = self.serialize(node.init)
Expand Down
7 changes: 7 additions & 0 deletions tests/test_AST_translator.py
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,10 @@ def while_stmt(self, tid: int, acc: pk.Acc[pk.double]) -> None:
acc += self.i_2
x += 1

@pk.workunit
def pass_stmt(self, tid: int) -> None:
pass

@pk.workunit
def call(self, tid: int, acc: pk.Acc[pk.double]) -> None:
pk.printf("Testing printf: %d\n", self.i_1)
Expand Down Expand Up @@ -269,6 +273,9 @@ def test_while_stmt(self):

self.assertEqual(expected_result, result)

def test_pass(self):
pk.parallel_for(self.range_policy, self.functor.pass_stmt)

def test_call(self):
expected_result: int = self.threads * abs(- self.i_1)
result: int = pk.parallel_reduce(self.range_policy, self.functor.call)
Expand Down

0 comments on commit f36cbe9

Please sign in to comment.