forked from daphne-eu/daphne
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[DAPHNE-daphne-eu#724] CUDNN unit test refactoring and cleanup
This commit moves catch2 tests of CUDNN based operations to the CUDA subdirectory to distinguish them better from the newly added tests for CPU DNN ops. Furthermore, before this change, it was either CPU or GPU test being executed in some mixed up tests like DNNPoolingTest. Fixes daphne-eu#724
- Loading branch information
1 parent
940cc90
commit 6da3edf
Showing
9 changed files
with
119 additions
and
303 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
/* | ||
* Copyright 2021 The DAPHNE Consortium | ||
* | ||
* Licensed 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. | ||
*/ | ||
|
||
|
||
#include "run_tests.h" | ||
|
||
#include "runtime/local/datagen/GenGivenVals.h" | ||
#include "runtime/local/kernels/CUDA/BatchNorm.h" | ||
|
||
template<class DT> | ||
void check(const DT* in, const DT* gamma, const DT* beta, const DT* ema_mean, const DT* ema_var, const DT* exp, | ||
DaphneContext* dctx) | ||
{ | ||
DT* res = nullptr; | ||
typename DT::VT epsilon = 1e-5; | ||
CUDA::BatchNorm::Forward<DT, DT>::apply(res, in, gamma, beta, ema_mean, ema_var, epsilon, dctx); | ||
CHECK(Approx(*(res->getValues())).epsilon(epsilon) == *(exp->getValues())); | ||
} | ||
|
||
TEMPLATE_PRODUCT_TEST_CASE("CUDA::NN::BatchNorm::Forward", TAG_DNN, (DenseMatrix), (float, double)) { // NOLINT(cert-err58-cpp) | ||
auto dctx = setupContextAndLogger(); | ||
using DT = TestType; | ||
|
||
auto input = genGivenVals<DT>(1, { -3, -2, -1, 0, 1, 2, 3, 4, 5}); | ||
auto gamma = genGivenVals<DT>(1, { 1 }); | ||
auto beta = genGivenVals<DT>(1, { 0 }); | ||
auto ema_mean = genGivenVals<DT>(1, { 0 }); | ||
auto ema_var = genGivenVals<DT>(1, { 1 }); | ||
|
||
auto result = genGivenVals<DT>(1, { -3, -2, -1, 0, 1, 2, 3, 4, 5}); | ||
|
||
check(input, gamma, beta, ema_mean, ema_var, result, dctx.get()); | ||
|
||
DataObjectFactory::destroy(input); | ||
DataObjectFactory::destroy(result); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright 2021 The DAPHNE Consortium | ||
* | ||
* Licensed 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. | ||
*/ | ||
|
||
|
||
#include "run_tests.h" | ||
|
||
#include "runtime/local/datagen/GenGivenVals.h" | ||
#include "runtime/local/kernels/CUDA/Convolution.h" | ||
|
||
template<class DT> | ||
void check(const DT* in, const DT* filter, const DT* exp, DaphneContext* dctx) { | ||
DT* res = nullptr; | ||
size_t out_h; | ||
size_t out_w; | ||
CUDA::Convolution::Forward<DT, DT>::apply(res, out_h, out_w, in, filter, nullptr, in->getNumRows(), 1, 3, 3, 2, 2, | ||
1, 1, 0, 0, dctx); | ||
CHECK(*res == *exp); | ||
} | ||
|
||
TEMPLATE_PRODUCT_TEST_CASE("CUDA::NN::Convolution::Forward", TAG_DNN, (DenseMatrix), (float, double)) { // NOLINT(cert-err58-cpp) | ||
auto dctx = setupContextAndLogger(); | ||
using DT = TestType; | ||
|
||
auto input = genGivenVals<DT>(1, { 1, 2, 3, 4, 5, 6, 7, 8, 9}); | ||
auto filter = genGivenVals<DT>(1, { 1, 0, 0, 1}); | ||
|
||
// expected output when used with settings filter 2x2, stride 1x1, padding 0x0 | ||
auto result = genGivenVals<DT>(1, { 6, 8, 12, 14 }); | ||
|
||
check(input, filter, result, dctx.get()); | ||
|
||
DataObjectFactory::destroy(filter); | ||
DataObjectFactory::destroy(input); | ||
DataObjectFactory::destroy(result); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.