Repository: incubator-systemml Updated Branches: refs/heads/master abc9686fb -> b9814ccf0
[SYSTEMML-540] Additional tests to compare the accuracy of different convolution related operators with CuDNN Closes #477. Project: http://git-wip-us.apache.org/repos/asf/incubator-systemml/repo Commit: http://git-wip-us.apache.org/repos/asf/incubator-systemml/commit/b9814ccf Tree: http://git-wip-us.apache.org/repos/asf/incubator-systemml/tree/b9814ccf Diff: http://git-wip-us.apache.org/repos/asf/incubator-systemml/diff/b9814ccf Branch: refs/heads/master Commit: b9814ccf0c024828d3f9c3e92b505ffb73ad73a1 Parents: abc9686 Author: Niketan Pansare <[email protected]> Authored: Fri May 5 13:53:35 2017 -0800 Committer: Niketan Pansare <[email protected]> Committed: Fri May 5 14:53:35 2017 -0700 ---------------------------------------------------------------------- pom.xml | 1 + scripts/nn/test/compare_backends/README.md | 26 +++++++ scripts/nn/test/compare_backends/compare.dml | 36 ++++++++++ scripts/nn/test/compare_backends/gen_conv2d.dml | 25 +++++++ .../compare_backends/gen_conv2d_bwd_data.dml | 29 ++++++++ .../compare_backends/gen_conv2d_bwd_filter.dml | 30 ++++++++ .../nn/test/compare_backends/gen_maxpool.dml | 23 +++++++ scripts/nn/test/compare_backends/run_tests.sh | 27 ++++++++ .../nn/test/compare_backends/test_conv2d.dml | 25 +++++++ scripts/nn/test/compare_backends/test_conv2d.sh | 72 ++++++++++++++++++++ .../compare_backends/test_conv2d_bwd_data.dml | 25 +++++++ .../compare_backends/test_conv2d_bwd_data.sh | 72 ++++++++++++++++++++ .../compare_backends/test_conv2d_bwd_filter.dml | 25 +++++++ .../compare_backends/test_conv2d_bwd_filter.sh | 72 ++++++++++++++++++++ .../nn/test/compare_backends/test_maxpool.dml | 25 +++++++ .../nn/test/compare_backends/test_maxpool.sh | 68 ++++++++++++++++++ 16 files changed, 581 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/b9814ccf/pom.xml ---------------------------------------------------------------------- diff --git a/pom.xml b/pom.xml index 0b9e4ae..4cca9a0 100644 --- a/pom.xml +++ b/pom.xml @@ -100,6 +100,7 @@ <exclude>perftest</exclude> <exclude>staging/**/*</exclude> <exclude>staging</exclude> + <exclude>nn/test/**/*</exclude> <!-- <exclude>*.sh</exclude> --> <!-- applies to sparkDML.sh --> </excludes> <targetPath>scripts</targetPath> http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/b9814ccf/scripts/nn/test/compare_backends/README.md ---------------------------------------------------------------------- diff --git a/scripts/nn/test/compare_backends/README.md b/scripts/nn/test/compare_backends/README.md new file mode 100644 index 0000000..9a02286 --- /dev/null +++ b/scripts/nn/test/compare_backends/README.md @@ -0,0 +1,26 @@ +<!-- +{% comment %} +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. +{% endcomment %} +--> + +# Built-in functions Tests + +The scripts in this folder tests the convolutions and maxpooling built-in functions +by comparing the CPU implementation v/s GPU implementation. +These scripts allows the developer to test different CPU implementation (such +as sparse data and dense filter, dense data and sparse filter, etc) +with MKL, OpenBLAS and Java. \ No newline at end of file http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/b9814ccf/scripts/nn/test/compare_backends/compare.dml ---------------------------------------------------------------------- diff --git a/scripts/nn/test/compare_backends/compare.dml b/scripts/nn/test/compare_backends/compare.dml new file mode 100644 index 0000000..f87c472 --- /dev/null +++ b/scripts/nn/test/compare_backends/compare.dml @@ -0,0 +1,36 @@ +#------------------------------------------------------------- +# +# 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($1) +Y = read($2) +msg = ifdef($3, " ") +eps = 1e-3 +num_mismatch = sum(abs(X - Y) > eps) +if(num_mismatch > 0) { + print("---------------------------------------------------\nERROR: >>>>>>>>> The results don't match(num_mismatch:" + num_mismatch + "): " + msg + "\n---------------------------------------------------") + Z = abs(X - Y) > eps + print("X=" + toString(X*Z)) + print("Y=" + toString(Y*Z)) + +} +else { + print("The results match: " + msg) +} http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/b9814ccf/scripts/nn/test/compare_backends/gen_conv2d.dml ---------------------------------------------------------------------- diff --git a/scripts/nn/test/compare_backends/gen_conv2d.dml b/scripts/nn/test/compare_backends/gen_conv2d.dml new file mode 100644 index 0000000..d092f2b --- /dev/null +++ b/scripts/nn/test/compare_backends/gen_conv2d.dml @@ -0,0 +1,25 @@ +#------------------------------------------------------------- +# +# 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 = rand(rows=$N, cols=$C*$H*$W, sparsity=$sp, min=-0.5, max=1) +w = rand(rows=$F, cols=$C*$Hf*$Wf, sparsity=$sp, min=-0.5, max=1) +write(X, "input.mtx", format="binary") +write(w, "filter.mtx", format="binary") http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/b9814ccf/scripts/nn/test/compare_backends/gen_conv2d_bwd_data.dml ---------------------------------------------------------------------- diff --git a/scripts/nn/test/compare_backends/gen_conv2d_bwd_data.dml b/scripts/nn/test/compare_backends/gen_conv2d_bwd_data.dml new file mode 100644 index 0000000..20fb3c1 --- /dev/null +++ b/scripts/nn/test/compare_backends/gen_conv2d_bwd_data.dml @@ -0,0 +1,29 @@ +#------------------------------------------------------------- +# +# 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 - $Hf) / $stride) + 1 +Wout = floor(($W + 2 * $pad - $Wf) / $stride) + 1 + +w = rand(rows=$F, cols=$C*$Hf*$Wf, sparsity=$sp, min=-0.5, max=1) +dout = rand(rows=$N, cols=$F*Hout*Wout, sparsity=$sp, min=-0.5, max=1) + +write(w, "filter.mtx", format="binary") +write(dout, "dout.mtx", format="binary") http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/b9814ccf/scripts/nn/test/compare_backends/gen_conv2d_bwd_filter.dml ---------------------------------------------------------------------- diff --git a/scripts/nn/test/compare_backends/gen_conv2d_bwd_filter.dml b/scripts/nn/test/compare_backends/gen_conv2d_bwd_filter.dml new file mode 100644 index 0000000..83735c9 --- /dev/null +++ b/scripts/nn/test/compare_backends/gen_conv2d_bwd_filter.dml @@ -0,0 +1,30 @@ +#------------------------------------------------------------- +# +# 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 - $Hf) / $stride) + 1 +Wout = floor(($W + 2 * $pad - $Wf) / $stride) + 1 + +X = rand(rows=$N, cols=$C*$H*$W, sparsity=$sp, min=-0.5, max=1) +dout = rand(rows=$N, cols=$F*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/incubator-systemml/blob/b9814ccf/scripts/nn/test/compare_backends/gen_maxpool.dml ---------------------------------------------------------------------- diff --git a/scripts/nn/test/compare_backends/gen_maxpool.dml b/scripts/nn/test/compare_backends/gen_maxpool.dml new file mode 100644 index 0000000..73678fe --- /dev/null +++ b/scripts/nn/test/compare_backends/gen_maxpool.dml @@ -0,0 +1,23 @@ +#------------------------------------------------------------- +# +# 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 = rand(rows=$N, cols=$C*$H*$W, sparsity=$sp, min=-0.5, max=1) +write(X, "input.mtx", format="binary") http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/b9814ccf/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 new file mode 100644 index 0000000..bf417ea --- /dev/null +++ b/scripts/nn/test/compare_backends/run_tests.sh @@ -0,0 +1,27 @@ +#!/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. +# +#------------------------------------------------------------- + +# 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 http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/b9814ccf/scripts/nn/test/compare_backends/test_conv2d.dml ---------------------------------------------------------------------- diff --git a/scripts/nn/test/compare_backends/test_conv2d.dml b/scripts/nn/test/compare_backends/test_conv2d.dml new file mode 100644 index 0000000..b56a0ae --- /dev/null +++ b/scripts/nn/test/compare_backends/test_conv2d.dml @@ -0,0 +1,25 @@ +#------------------------------------------------------------- +# +# 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") +w = read("filter.mtx") +out = conv2d(X, w, input_shape=[$N,$C,$H,$W], filter_shape=[$F, $C, $Hf, $Wf], stride=[$stride,$stride], padding=[$pad,$pad]) +write(out, $out, format="csv") http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/b9814ccf/scripts/nn/test/compare_backends/test_conv2d.sh ---------------------------------------------------------------------- diff --git a/scripts/nn/test/compare_backends/test_conv2d.sh b/scripts/nn/test/compare_backends/test_conv2d.sh new file mode 100644 index 0000000..4c578a6 --- /dev/null +++ b/scripts/nn/test/compare_backends/test_conv2d.sh @@ -0,0 +1,72 @@ +#!/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='.' +os_suffix='linux-x86_64' +version='0.8.0' + +# Downloads the jcuda jars +for lib in jcuda jcublas jcufft jcusparse jcusolver jcurand jnvgraph jcudnn +do + file=$lib'-'$version'.jar' + if [ ! -f $file ]; then + url='https://search.maven.org/remotecontent?filepath=org/jcuda/'$lib'/'$version'/'$file + wget -O $file $url + fi + jars=$jars','$file + + file=$lib'-natives-'$version'-'$os_suffix'.jar' + if [ ! -f $file ]; then + url='https://search.maven.org/remotecontent?filepath=org/jcuda/'$lib'-natives/'$version'/'$file + wget -O $file $url + fi + jars=$jars','$file +done + +# N = Number of images, C = number of channels, H = height, W = width +# F = number of filters, Hf = filter height, Wf = filter width +N=5 +C=3 +H=28 +W=28 +F=32 +Hf=3 +Wf=3 +for sparsity in 0.1 0.2 0.5 0.6 0.9 +do + # Generating the data + $SPARK_HOME/bin/spark-submit SystemML.jar -f gen_conv2d.dml -nvargs sp=$sparsity N=$N C=$C H=$H W=$W F=$F Hf=$Hf Wf=$Wf + for stride in 1 2 3 + do + for pad in 0 1 2 + do + # Running a test in CPU mode + $SPARK_HOME/bin/spark-submit SystemML.jar -f test_conv2d.dml -nvargs stride=$stride pad=$pad out=out_cp.csv N=$N C=$C H=$H W=$W F=$F Hf=$Hf Wf=$Wf + # Running a test in GPU mode + $SPARK_HOME/bin/spark-submit --jars $jars SystemML.jar -f test_conv2d.dml -stats -gpu force -nvargs stride=$stride pad=$pad out=out_gpu.csv N=$N C=$C H=$H W=$W F=$F Hf=$Hf Wf=$Wf + # 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 "conv2d:stride="$stride",pad="$pad",sparsity="$sparsity + 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 http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/b9814ccf/scripts/nn/test/compare_backends/test_conv2d_bwd_data.dml ---------------------------------------------------------------------- diff --git a/scripts/nn/test/compare_backends/test_conv2d_bwd_data.dml b/scripts/nn/test/compare_backends/test_conv2d_bwd_data.dml new file mode 100644 index 0000000..5dcc629 --- /dev/null +++ b/scripts/nn/test/compare_backends/test_conv2d_bwd_data.dml @@ -0,0 +1,25 @@ +#------------------------------------------------------------- +# +# 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. +# +#------------------------------------------------------------- + +w = read("filter.mtx") +dout = read("dout.mtx") +out = conv2d_backward_data(w, dout, input_shape=[$N,$C,$H,$W], filter_shape=[$F, $C, $Hf, $Wf], stride=[$stride,$stride], padding=[$pad,$pad]) +write(out, $out, format="csv") http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/b9814ccf/scripts/nn/test/compare_backends/test_conv2d_bwd_data.sh ---------------------------------------------------------------------- diff --git a/scripts/nn/test/compare_backends/test_conv2d_bwd_data.sh b/scripts/nn/test/compare_backends/test_conv2d_bwd_data.sh new file mode 100644 index 0000000..da7b4f3 --- /dev/null +++ b/scripts/nn/test/compare_backends/test_conv2d_bwd_data.sh @@ -0,0 +1,72 @@ +#!/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='.' +os_suffix='linux-x86_64' +version='0.8.0' + +# Downloads the jcuda jars +for lib in jcuda jcublas jcufft jcusparse jcusolver jcurand jnvgraph jcudnn +do + file=$lib'-'$version'.jar' + if [ ! -f $file ]; then + url='https://search.maven.org/remotecontent?filepath=org/jcuda/'$lib'/'$version'/'$file + wget -O $file $url + fi + jars=$jars','$file + + file=$lib'-natives-'$version'-'$os_suffix'.jar' + if [ ! -f $file ]; then + url='https://search.maven.org/remotecontent?filepath=org/jcuda/'$lib'-natives/'$version'/'$file + wget -O $file $url + fi + jars=$jars','$file +done + +# N = Number of images, C = number of channels, H = height, W = width +# F = number of filters, Hf = filter height, Wf = filter width +N=5 +C=3 +H=28 +W=28 +F=32 +Hf=3 +Wf=3 +for sparsity in 0.1 0.2 0.5 0.6 0.9 +do + for stride in 1 2 3 + do + for pad in 0 1 2 + do + # Generating the data + $SPARK_HOME/bin/spark-submit SystemML.jar -f gen_conv2d_bwd_data.dml -nvargs sp=$sparsity N=$N C=$C H=$H W=$W F=$F Hf=$Hf Wf=$Wf stride=$stride pad=$pad + # Running a test in CPU mode + $SPARK_HOME/bin/spark-submit SystemML.jar -f test_conv2d_bwd_data.dml -nvargs stride=$stride pad=$pad out=out_cp.csv N=$N C=$C H=$H W=$W F=$F Hf=$Hf Wf=$Wf + # Running a test in GPU mode + $SPARK_HOME/bin/spark-submit --jars $jars SystemML.jar -f test_conv2d_bwd_data.dml -stats -gpu force -nvargs stride=$stride pad=$pad out=out_gpu.csv N=$N C=$C H=$H W=$W F=$F Hf=$Hf Wf=$Wf + # 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 "conv2d_backward_data:stride="$stride",pad="$pad",sparsity="$sparsity + 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 http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/b9814ccf/scripts/nn/test/compare_backends/test_conv2d_bwd_filter.dml ---------------------------------------------------------------------- diff --git a/scripts/nn/test/compare_backends/test_conv2d_bwd_filter.dml b/scripts/nn/test/compare_backends/test_conv2d_bwd_filter.dml new file mode 100644 index 0000000..c0237bd --- /dev/null +++ b/scripts/nn/test/compare_backends/test_conv2d_bwd_filter.dml @@ -0,0 +1,25 @@ +#------------------------------------------------------------- +# +# 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") +dout = read("dout.mtx") +out = conv2d_backward_filter(X, dout, input_shape=[$N,$C,$H,$W], filter_shape=[$F, $C, $Hf, $Wf], stride=[$stride,$stride], padding=[$pad,$pad]) +write(out, $out, format="csv") http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/b9814ccf/scripts/nn/test/compare_backends/test_conv2d_bwd_filter.sh ---------------------------------------------------------------------- diff --git a/scripts/nn/test/compare_backends/test_conv2d_bwd_filter.sh b/scripts/nn/test/compare_backends/test_conv2d_bwd_filter.sh new file mode 100644 index 0000000..f19fc73 --- /dev/null +++ b/scripts/nn/test/compare_backends/test_conv2d_bwd_filter.sh @@ -0,0 +1,72 @@ +#!/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='.' +os_suffix='linux-x86_64' +version='0.8.0' + +# Downloads the jcuda jars +for lib in jcuda jcublas jcufft jcusparse jcusolver jcurand jnvgraph jcudnn +do + file=$lib'-'$version'.jar' + if [ ! -f $file ]; then + url='https://search.maven.org/remotecontent?filepath=org/jcuda/'$lib'/'$version'/'$file + wget -O $file $url + fi + jars=$jars','$file + + file=$lib'-natives-'$version'-'$os_suffix'.jar' + if [ ! -f $file ]; then + url='https://search.maven.org/remotecontent?filepath=org/jcuda/'$lib'-natives/'$version'/'$file + wget -O $file $url + fi + jars=$jars','$file +done + +# N = Number of images, C = number of channels, H = height, W = width +# F = number of filters, Hf = filter height, Wf = filter width +N=5 +C=3 +H=28 +W=28 +F=32 +Hf=3 +Wf=3 +for sparsity in 0.1 0.2 0.5 0.6 0.9 +do + for stride in 1 2 3 + do + for pad in 0 1 2 + do + # Generating the data + $SPARK_HOME/bin/spark-submit SystemML.jar -f gen_conv2d_bwd_filter.dml -nvargs sp=$sparsity N=$N C=$C H=$H W=$W F=$F Hf=$Hf Wf=$Wf stride=$stride pad=$pad + # Running a test in CPU mode + $SPARK_HOME/bin/spark-submit SystemML.jar -f test_conv2d_bwd_filter.dml -nvargs stride=$stride pad=$pad out=out_cp.csv N=$N C=$C H=$H W=$W F=$F Hf=$Hf Wf=$Wf + # Running a test in GPU mode + $SPARK_HOME/bin/spark-submit --jars $jars SystemML.jar -f test_conv2d_bwd_filter.dml -stats -gpu force -nvargs stride=$stride pad=$pad out=out_gpu.csv N=$N C=$C H=$H W=$W F=$F Hf=$Hf Wf=$Wf + # 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 "conv2d_backward_filter:stride="$stride",pad="$pad",sparsity="$sparsity + 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 http://git-wip-us.apache.org/repos/asf/incubator-systemml/blob/b9814ccf/scripts/nn/test/compare_backends/test_maxpool.dml ---------------------------------------------------------------------- diff --git a/scripts/nn/test/compare_backends/test_maxpool.dml b/scripts/nn/test/compare_backends/test_maxpool.dml new file mode 100644 index 0000000..d9b7337 --- /dev/null +++ b/scripts/nn/test/compare_backends/test_maxpool.dml @@ -0,0 +1,25 @@ +#------------------------------------------------------------- +# +# 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) +out = max_pool(X, 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/incubator-systemml/blob/b9814ccf/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 new file mode 100644 index 0000000..e8575e3 --- /dev/null +++ b/scripts/nn/test/compare_backends/test_maxpool.sh @@ -0,0 +1,68 @@ +#!/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='.' +os_suffix='linux-x86_64' +version='0.8.0' + +# Downloads the jcuda jars +for lib in jcuda jcublas jcufft jcusparse jcusolver jcurand jnvgraph jcudnn +do + file=$lib'-'$version'.jar' + if [ ! -f $file ]; then + url='https://search.maven.org/remotecontent?filepath=org/jcuda/'$lib'/'$version'/'$file + wget -O $file $url + fi + jars=$jars','$file + + file=$lib'-natives-'$version'-'$os_suffix'.jar' + if [ ! -f $file ]; then + url='https://search.maven.org/remotecontent?filepath=org/jcuda/'$lib'-natives/'$version'/'$file + wget -O $file $url + fi + jars=$jars','$file +done + +# 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 + $SPARK_HOME/bin/spark-submit SystemML.jar -f gen_maxpool.dml -nvargs sp=$sparsity N=$N C=$C H=$H W=$W + for stride in 1 2 3 + do + for pad in 0 1 2 + do + # Running a test in CPU mode + $SPARK_HOME/bin/spark-submit SystemML.jar -f test_maxpool.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.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 + 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
