Repository: systemml Updated Branches: refs/heads/master fe9b023c7 -> f7bc20266
[MINOR] Added max_pool_backward tests in nn library - These tests compare the output of CP operators with that of GPU operators (i.e. CuDNN). Project: http://git-wip-us.apache.org/repos/asf/systemml/repo Commit: http://git-wip-us.apache.org/repos/asf/systemml/commit/f7bc2026 Tree: http://git-wip-us.apache.org/repos/asf/systemml/tree/f7bc2026 Diff: http://git-wip-us.apache.org/repos/asf/systemml/diff/f7bc2026 Branch: refs/heads/master Commit: f7bc20266a42929913565d4d80dd07f3a5dbe7de Parents: fe9b023 Author: Niketan Pansare <[email protected]> Authored: Thu Nov 16 14:43:14 2017 -0800 Committer: Niketan Pansare <[email protected]> Committed: Thu Nov 16 14:43:14 2017 -0800 ---------------------------------------------------------------------- .../test/compare_backends/gen_maxpool_bwd.dml | 28 +++++++++++ scripts/nn/test/compare_backends/run_tests.sh | 9 ++-- .../nn/test/compare_backends/test_maxpool.sh | 2 +- .../test/compare_backends/test_maxpool_bwd.dml | 26 +++++++++++ .../test/compare_backends/test_maxpool_bwd.sh | 49 ++++++++++++++++++++ 5 files changed, 109 insertions(+), 5 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/systemml/blob/f7bc2026/scripts/nn/test/compare_backends/gen_maxpool_bwd.dml ---------------------------------------------------------------------- diff --git a/scripts/nn/test/compare_backends/gen_maxpool_bwd.dml b/scripts/nn/test/compare_backends/gen_maxpool_bwd.dml new file mode 100644 index 0000000..90a3a38 --- /dev/null +++ b/scripts/nn/test/compare_backends/gen_maxpool_bwd.dml @@ -0,0 +1,28 @@ +#------------------------------------------------------------- +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +#------------------------------------------------------------- + +Hout = floor(($H + 2 * $pad - $pool) / $stride) + 1 +Wout = floor(($W + 2 * $pad - $pool) / $stride) + 1 + +X = rand(rows=$N, cols=$C*$H*$W, sparsity=$sp, min=-0.5, max=1) +dout = rand(rows=$N, cols=$C*Hout*Wout, sparsity=$sp, min=-0.5, max=1) +write(X, "input.mtx", format="binary") +write(dout, "dout.mtx", format="binary") http://git-wip-us.apache.org/repos/asf/systemml/blob/f7bc2026/scripts/nn/test/compare_backends/run_tests.sh ---------------------------------------------------------------------- diff --git a/scripts/nn/test/compare_backends/run_tests.sh b/scripts/nn/test/compare_backends/run_tests.sh index bf417ea..b8f9981 100644 --- a/scripts/nn/test/compare_backends/run_tests.sh +++ b/scripts/nn/test/compare_backends/run_tests.sh @@ -21,7 +21,8 @@ #------------------------------------------------------------- # Additional tests to compare the accuracy of different convolution related operators with CuDNN -./test_conv2d_bwd_filter.sh -./test_conv2d_bwd_data.sh -./test_conv2d.sh -./test_maxpool.sh \ No newline at end of file +#./test_conv2d_bwd_filter.sh +#./test_conv2d_bwd_data.sh +#./test_conv2d.sh +./test_maxpool.sh +./test_maxpool_bwd.sh http://git-wip-us.apache.org/repos/asf/systemml/blob/f7bc2026/scripts/nn/test/compare_backends/test_maxpool.sh ---------------------------------------------------------------------- diff --git a/scripts/nn/test/compare_backends/test_maxpool.sh b/scripts/nn/test/compare_backends/test_maxpool.sh index 9d7da4a..5ddddcb 100644 --- a/scripts/nn/test/compare_backends/test_maxpool.sh +++ b/scripts/nn/test/compare_backends/test_maxpool.sh @@ -40,7 +40,7 @@ do # Running a test in GPU mode $SPARK_HOME/bin/spark-submit --jars $jars SystemML.jar -f test_maxpool.dml -stats -gpu force -nvargs stride=$stride pad=$pad out=out_gpu.csv N=$N C=$C H=$H W=$W pool=3 # Comparing the CPU vs GPU results to make sure they are the same - $SPARK_HOME/bin/spark-submit SystemML.jar -f compare.dml -args out_cp.csv out_gpu.csv "maxpool:stride="$stride",pad="$pad + $SPARK_HOME/bin/spark-submit SystemML.jar -f compare.dml -args out_cp.csv out_gpu.csv "maxpool:sparsity="$sparsity",stride="$stride",pad="$pad rm -rf out_cp.csv out_gpu.csv out_cp.csv.mtd out_gpu.csv.mtd done done http://git-wip-us.apache.org/repos/asf/systemml/blob/f7bc2026/scripts/nn/test/compare_backends/test_maxpool_bwd.dml ---------------------------------------------------------------------- diff --git a/scripts/nn/test/compare_backends/test_maxpool_bwd.dml b/scripts/nn/test/compare_backends/test_maxpool_bwd.dml new file mode 100644 index 0000000..215912f --- /dev/null +++ b/scripts/nn/test/compare_backends/test_maxpool_bwd.dml @@ -0,0 +1,26 @@ +#------------------------------------------------------------- +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +#------------------------------------------------------------- + +X = read("input.mtx") +X = max(X, 0) +dout = read("dout.mtx") +out = max_pool_backward(X, dout, input_shape=[$N,$C,$H,$W], pool_size=[$pool,$pool], stride=[$stride,$stride], padding=[$pad,$pad]) +write(out, $out, format="csv") http://git-wip-us.apache.org/repos/asf/systemml/blob/f7bc2026/scripts/nn/test/compare_backends/test_maxpool_bwd.sh ---------------------------------------------------------------------- diff --git a/scripts/nn/test/compare_backends/test_maxpool_bwd.sh b/scripts/nn/test/compare_backends/test_maxpool_bwd.sh new file mode 100644 index 0000000..2682977 --- /dev/null +++ b/scripts/nn/test/compare_backends/test_maxpool_bwd.sh @@ -0,0 +1,49 @@ +#!/usr/bin/bash +#------------------------------------------------------------- +# +# Licensed to the Apache Software Foundation (ASF) under one +# or more contributor license agreements. See the NOTICE file +# distributed with this work for additional information +# regarding copyright ownership. The ASF licenses this file +# to you under the Apache License, Version 2.0 (the +# "License"); you may not use this file except in compliance +# with the License. You may obtain a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, +# software distributed under the License is distributed on an +# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +# KIND, either express or implied. See the License for the +# specific language governing permissions and limitations +# under the License. +# +#------------------------------------------------------------- + +jars='systemml-*-extra.jar' + +# N = Number of images, C = number of channels, H = height, W = width +N=5 +C=3 +H=28 +W=28 +for sparsity in 0.1 0.2 0.5 0.6 0.9 +do + # Generating the data + + for stride in 1 2 3 + do + for pad in 0 1 2 + do + $SPARK_HOME/bin/spark-submit SystemML.jar -f gen_maxpool_bwd.dml -nvargs sp=$sparsity N=$N C=$C H=$H W=$W pool=3 stride=$stride pad=$pad + # Running a test in CPU mode + $SPARK_HOME/bin/spark-submit SystemML.jar -f test_maxpool_bwd.dml -nvargs stride=$stride pad=$pad out=out_cp.csv N=$N C=$C H=$H W=$W pool=3 + # Running a test in GPU mode + $SPARK_HOME/bin/spark-submit --jars $jars SystemML.jar -f test_maxpool_bwd.dml -stats -gpu force -nvargs stride=$stride pad=$pad out=out_gpu.csv N=$N C=$C H=$H W=$W pool=3 + # Comparing the CPU vs GPU results to make sure they are the same + $SPARK_HOME/bin/spark-submit SystemML.jar -f compare.dml -args out_cp.csv out_gpu.csv "maxpool_bwd:sparsity="$sparsity",stride="$stride",pad="$pad + rm -rf out_cp.csv out_gpu.csv out_cp.csv.mtd out_gpu.csv.mtd + done + done + rm -rf input.mtx input.mtx.mtd +done
