From cb18d3d996b9f775e01c38d3feb2734418237386 Mon Sep 17 00:00:00 2001 From: raver119 Date: Wed, 4 Dec 2019 09:11:37 +0300 Subject: [PATCH] allow MKL-DNN on non-AVX machines (#104) Signed-off-by: raver119 --- .../include/ops/declarable/platform/mkldnn/avgpooling2d.cpp | 4 ---- .../ops/declarable/platform/mkldnn/avgpooling2d_bp.cpp | 4 ---- .../include/ops/declarable/platform/mkldnn/avgpooling3d.cpp | 4 ---- .../ops/declarable/platform/mkldnn/avgpooling3d_bp.cpp | 4 ---- libnd4j/include/ops/declarable/platform/mkldnn/batchnorm.cpp | 4 ---- libnd4j/include/ops/declarable/platform/mkldnn/conv2d.cpp | 4 ---- libnd4j/include/ops/declarable/platform/mkldnn/conv3d.cpp | 4 ---- libnd4j/include/ops/declarable/platform/mkldnn/deconv2d.cpp | 4 ---- .../include/ops/declarable/platform/mkldnn/deconv2d_tf.cpp | 4 ---- libnd4j/include/ops/declarable/platform/mkldnn/deconv3d.cpp | 4 ---- libnd4j/include/ops/declarable/platform/mkldnn/lrn.cpp | 4 ---- libnd4j/include/ops/declarable/platform/mkldnn/lstmLayer.cpp | 5 ----- .../include/ops/declarable/platform/mkldnn/maxpooling2d.cpp | 4 ---- .../ops/declarable/platform/mkldnn/maxpooling2d_bp.cpp | 4 ---- .../include/ops/declarable/platform/mkldnn/maxpooling3d.cpp | 4 ---- .../ops/declarable/platform/mkldnn/maxpooling_3d_bp.cpp | 4 ---- 16 files changed, 65 deletions(-) diff --git a/libnd4j/include/ops/declarable/platform/mkldnn/avgpooling2d.cpp b/libnd4j/include/ops/declarable/platform/mkldnn/avgpooling2d.cpp index e70aff9d9..9a3b2916b 100644 --- a/libnd4j/include/ops/declarable/platform/mkldnn/avgpooling2d.cpp +++ b/libnd4j/include/ops/declarable/platform/mkldnn/avgpooling2d.cpp @@ -129,10 +129,6 @@ namespace nd4j { } PLATFORM_CHECK(avgpool2d) { - // we don't want to use mkldnn if cpu doesn't support avx/avx2 - if (::optimalLevel() < 2) - return false; - auto input = INPUT_VARIABLE(0); auto output = OUTPUT_VARIABLE(0); diff --git a/libnd4j/include/ops/declarable/platform/mkldnn/avgpooling2d_bp.cpp b/libnd4j/include/ops/declarable/platform/mkldnn/avgpooling2d_bp.cpp index ceef28d33..428bd6042 100644 --- a/libnd4j/include/ops/declarable/platform/mkldnn/avgpooling2d_bp.cpp +++ b/libnd4j/include/ops/declarable/platform/mkldnn/avgpooling2d_bp.cpp @@ -139,10 +139,6 @@ namespace nd4j { } PLATFORM_CHECK(avgpool2d_bp) { - // we don't want to use mkldnn if cpu doesn't support avx/avx2 - if (::optimalLevel() < 2) - return false; - auto input = INPUT_VARIABLE(0); auto output = OUTPUT_VARIABLE(0); diff --git a/libnd4j/include/ops/declarable/platform/mkldnn/avgpooling3d.cpp b/libnd4j/include/ops/declarable/platform/mkldnn/avgpooling3d.cpp index e42cb6a8e..22ace87de 100644 --- a/libnd4j/include/ops/declarable/platform/mkldnn/avgpooling3d.cpp +++ b/libnd4j/include/ops/declarable/platform/mkldnn/avgpooling3d.cpp @@ -131,10 +131,6 @@ namespace nd4j { } PLATFORM_CHECK(avgpool3dnew) { - // we don't want to use mkldnn if cpu doesn't support avx/avx2 - if (::optimalLevel() < 2) - return false; - auto input = INPUT_VARIABLE(0); auto output = OUTPUT_VARIABLE(0); diff --git a/libnd4j/include/ops/declarable/platform/mkldnn/avgpooling3d_bp.cpp b/libnd4j/include/ops/declarable/platform/mkldnn/avgpooling3d_bp.cpp index 370f2b3fd..0c52608a0 100644 --- a/libnd4j/include/ops/declarable/platform/mkldnn/avgpooling3d_bp.cpp +++ b/libnd4j/include/ops/declarable/platform/mkldnn/avgpooling3d_bp.cpp @@ -144,10 +144,6 @@ namespace nd4j { } PLATFORM_CHECK(avgpool3dnew_bp) { - // we don't want to use mkldnn if cpu doesn't support avx/avx2 - if (::optimalLevel() < 2) - return false; - auto input = INPUT_VARIABLE(0); auto output = OUTPUT_VARIABLE(0); diff --git a/libnd4j/include/ops/declarable/platform/mkldnn/batchnorm.cpp b/libnd4j/include/ops/declarable/platform/mkldnn/batchnorm.cpp index 23957aeb7..e66589b0a 100644 --- a/libnd4j/include/ops/declarable/platform/mkldnn/batchnorm.cpp +++ b/libnd4j/include/ops/declarable/platform/mkldnn/batchnorm.cpp @@ -736,10 +736,6 @@ PLATFORM_IMPL(batchnorm_bp) { ////////////////////////////////////////////////////////////////////////// PLATFORM_CHECK(batchnorm_bp) { - // we don't want to use mkldnn if cpu doesn't support avx/avx2 - // if (::optimalLevel() < 2) - // return false; - NDArray* input = INPUT_VARIABLE(0); // 2D:nc, 4D:nchw, 5D:ncdhw NDArray* mean = INPUT_VARIABLE(1); // [c] NDArray* variance = INPUT_VARIABLE(2); // [c] diff --git a/libnd4j/include/ops/declarable/platform/mkldnn/conv2d.cpp b/libnd4j/include/ops/declarable/platform/mkldnn/conv2d.cpp index 4531fda81..a01679740 100644 --- a/libnd4j/include/ops/declarable/platform/mkldnn/conv2d.cpp +++ b/libnd4j/include/ops/declarable/platform/mkldnn/conv2d.cpp @@ -329,10 +329,6 @@ PLATFORM_IMPL(conv2d_bp) { } PLATFORM_CHECK(conv2d_bp) { - // we don't want to use mkldnn if cpu doesn't support avx/avx2 - if (::optimalLevel() < 2) - return false; - auto input = INPUT_VARIABLE(0); // [bS, iH, iW, iC] (NHWC) or [bS, iC, iH, iW] (NCHW) auto weights = INPUT_VARIABLE(1); // [kH, kW, iC, oC] always auto bias = block.width() > 3 ? INPUT_VARIABLE(2) : nullptr; // [oC] diff --git a/libnd4j/include/ops/declarable/platform/mkldnn/conv3d.cpp b/libnd4j/include/ops/declarable/platform/mkldnn/conv3d.cpp index a5871fada..1e28e76a5 100644 --- a/libnd4j/include/ops/declarable/platform/mkldnn/conv3d.cpp +++ b/libnd4j/include/ops/declarable/platform/mkldnn/conv3d.cpp @@ -375,10 +375,6 @@ PLATFORM_IMPL(conv3dnew_bp) { } PLATFORM_CHECK(conv3dnew_bp) { - // we don't want to use mkldnn if cpu doesn't support avx/avx2 - if (::optimalLevel() < 2) - return false; - auto input = INPUT_VARIABLE( 0); // [bS, iD, iH, iW, iC] (NDHWC) or [bS, iC, iD, iH, iW] (NCDHW) auto weights = INPUT_VARIABLE( diff --git a/libnd4j/include/ops/declarable/platform/mkldnn/deconv2d.cpp b/libnd4j/include/ops/declarable/platform/mkldnn/deconv2d.cpp index 047549e40..ced37aea8 100644 --- a/libnd4j/include/ops/declarable/platform/mkldnn/deconv2d.cpp +++ b/libnd4j/include/ops/declarable/platform/mkldnn/deconv2d.cpp @@ -507,10 +507,6 @@ PLATFORM_IMPL(deconv2d_bp) { } PLATFORM_CHECK(deconv2d_bp) { - // we don't want to use mkldnn if cpu doesn't support avx/avx2 - // if (::optimalLevel() < 2) - // return false; - auto input = INPUT_VARIABLE(0); // [bS, iH, iW, iC] (NHWC) or [bS, iC, iH, iW] (NCDHW) auto weights = INPUT_VARIABLE(1); // [kH, kW, oC, iC] always auto bias = block.width() > 3 ? INPUT_VARIABLE(2) : nullptr; // [oC] diff --git a/libnd4j/include/ops/declarable/platform/mkldnn/deconv2d_tf.cpp b/libnd4j/include/ops/declarable/platform/mkldnn/deconv2d_tf.cpp index b0e27240f..fac53e877 100644 --- a/libnd4j/include/ops/declarable/platform/mkldnn/deconv2d_tf.cpp +++ b/libnd4j/include/ops/declarable/platform/mkldnn/deconv2d_tf.cpp @@ -223,10 +223,6 @@ PLATFORM_IMPL(deconv2d_tf) { } PLATFORM_CHECK(deconv2d_tf) { - // we don't want to use mkldnn if cpu doesn't support avx/avx2 - // if (::optimalLevel() < 2) - // return false; - auto weights = INPUT_VARIABLE(1); // [kH, kW, iC, oC] always auto gradO = INPUT_VARIABLE(2); // [bS, oH, oW, oC] (NHWC) or [bS, oC, oH, oW] (NCDHW), epsilon_next auto gradI = OUTPUT_VARIABLE(0); // [bS, iH, iW, iC] (NHWC) or [bS, iC, iH, iW] (NCDHW), gradI diff --git a/libnd4j/include/ops/declarable/platform/mkldnn/deconv3d.cpp b/libnd4j/include/ops/declarable/platform/mkldnn/deconv3d.cpp index 51e15349b..7259ea0db 100644 --- a/libnd4j/include/ops/declarable/platform/mkldnn/deconv3d.cpp +++ b/libnd4j/include/ops/declarable/platform/mkldnn/deconv3d.cpp @@ -525,10 +525,6 @@ PLATFORM_IMPL(deconv3d_bp) { PLATFORM_CHECK(deconv3d_bp) { - // we don't want to use mkldnn if cpu doesn't support avx/avx2 - // if (::optimalLevel() < 2) - // return false; - auto input = INPUT_VARIABLE(0); // [bS, iD, iH, iW, iC] (NHWC) or [bS, iD, iC, iH, iW] (NCDHW) auto weights = INPUT_VARIABLE(1); // [kD, kH, kW, oC, iC] always auto bias = block.width() > 3 ? INPUT_VARIABLE(2) : nullptr; // [oC] diff --git a/libnd4j/include/ops/declarable/platform/mkldnn/lrn.cpp b/libnd4j/include/ops/declarable/platform/mkldnn/lrn.cpp index 41efe6524..ecd8b4c1a 100644 --- a/libnd4j/include/ops/declarable/platform/mkldnn/lrn.cpp +++ b/libnd4j/include/ops/declarable/platform/mkldnn/lrn.cpp @@ -83,10 +83,6 @@ namespace nd4j { }; PLATFORM_CHECK(lrn) { - // we don't want to use mkldnn if cpu doesn't support avx/avx2 - if (::optimalLevel() < 2) - return false; - auto input = INPUT_VARIABLE(0); auto output = OUTPUT_VARIABLE(0); diff --git a/libnd4j/include/ops/declarable/platform/mkldnn/lstmLayer.cpp b/libnd4j/include/ops/declarable/platform/mkldnn/lstmLayer.cpp index 50a349cc9..7417653b3 100644 --- a/libnd4j/include/ops/declarable/platform/mkldnn/lstmLayer.cpp +++ b/libnd4j/include/ops/declarable/platform/mkldnn/lstmLayer.cpp @@ -494,11 +494,6 @@ PLATFORM_IMPL(lstmLayer) { } PLATFORM_CHECK(lstmLayer) { - // we don't want to use mkldnn if cpu doesn't support avx/avx2 - // if (::optimalLevel() < 2) { - // return false; - // } - const auto hasBiases = B_ARG(0); // indicates whether biases array is provided const auto hasInitH = B_ARG(2); // indicates whether initial output is provided const auto hasInitC = B_ARG(3); // indicates whether initial cell state is provided diff --git a/libnd4j/include/ops/declarable/platform/mkldnn/maxpooling2d.cpp b/libnd4j/include/ops/declarable/platform/mkldnn/maxpooling2d.cpp index 4204b93d0..03008fbc6 100644 --- a/libnd4j/include/ops/declarable/platform/mkldnn/maxpooling2d.cpp +++ b/libnd4j/include/ops/declarable/platform/mkldnn/maxpooling2d.cpp @@ -135,10 +135,6 @@ namespace nd4j { } PLATFORM_CHECK(maxpool2d) { - // we don't want to use mkldnn if cpu doesn't support avx/avx2 - if (::optimalLevel() < 2) - return false; - auto input = INPUT_VARIABLE(0); auto output = OUTPUT_VARIABLE(0); diff --git a/libnd4j/include/ops/declarable/platform/mkldnn/maxpooling2d_bp.cpp b/libnd4j/include/ops/declarable/platform/mkldnn/maxpooling2d_bp.cpp index 0c663a59c..e50bef362 100644 --- a/libnd4j/include/ops/declarable/platform/mkldnn/maxpooling2d_bp.cpp +++ b/libnd4j/include/ops/declarable/platform/mkldnn/maxpooling2d_bp.cpp @@ -164,10 +164,6 @@ namespace nd4j { } PLATFORM_CHECK(maxpool2d_bp) { - // we don't want to use mkldnn if cpu doesn't support avx/avx2 - if (::optimalLevel() < 2) - return false; - auto input = INPUT_VARIABLE(0); auto output = OUTPUT_VARIABLE(0); diff --git a/libnd4j/include/ops/declarable/platform/mkldnn/maxpooling3d.cpp b/libnd4j/include/ops/declarable/platform/mkldnn/maxpooling3d.cpp index 72fb79709..6f132bb56 100644 --- a/libnd4j/include/ops/declarable/platform/mkldnn/maxpooling3d.cpp +++ b/libnd4j/include/ops/declarable/platform/mkldnn/maxpooling3d.cpp @@ -141,10 +141,6 @@ namespace nd4j { } PLATFORM_CHECK(maxpool3dnew) { - // we don't want to use mkldnn if cpu doesn't support avx/avx2 - if (::optimalLevel() < 2) - return false; - auto input = INPUT_VARIABLE(0); auto output = OUTPUT_VARIABLE(0); diff --git a/libnd4j/include/ops/declarable/platform/mkldnn/maxpooling_3d_bp.cpp b/libnd4j/include/ops/declarable/platform/mkldnn/maxpooling_3d_bp.cpp index b4c9f1ad5..4f51d6633 100644 --- a/libnd4j/include/ops/declarable/platform/mkldnn/maxpooling_3d_bp.cpp +++ b/libnd4j/include/ops/declarable/platform/mkldnn/maxpooling_3d_bp.cpp @@ -171,10 +171,6 @@ namespace nd4j { } PLATFORM_CHECK(maxpool3dnew_bp) { - // we don't want to use mkldnn if cpu doesn't support avx/avx2 - if (::optimalLevel() < 2) - return false; - auto input = INPUT_VARIABLE(0); auto output = OUTPUT_VARIABLE(0);