-
Notifications
You must be signed in to change notification settings - Fork 3k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
93759d6
commit abe101d
Showing
6 changed files
with
298 additions
and
60 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,26 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Copyright (c) 2023 NVIDIA Corporation. | ||
// Licensed under the MIT License. | ||
|
||
#include "core/providers/cuda/cuda_provider_options.h" | ||
#include "core/providers/common.h" | ||
|
||
#include "test/providers/compare_provider_test_utils.h" | ||
#include "test/common/cuda_op_test_utils.h" | ||
|
||
#include "gtest/gtest.h" | ||
|
||
#define MAKE_PROVIDERS_EPS(eps) \ | ||
std::vector<std::shared_ptr<IExecutionProvider>> execution_providers; \ | ||
OrtCUDAProviderOptionsV2 nhwc = { \ | ||
.prefer_nhwc = true}; \ | ||
execution_providers.push_back(CudaExecutionProviderWithOptions(&nhwc)); \ | ||
\ | ||
double error_tolerance = eps; \ | ||
OrtCUDAProviderOptionsV2 nchw = { \ | ||
.prefer_nhwc = false}; \ | ||
auto source_ep = CudaExecutionProviderWithOptions(&nchw); \ | ||
auto test = op.get_test(); \ | ||
test->CompareEPs(std::move(source_ep), execution_providers, error_tolerance); | ||
|
||
#define MAKE_PROVIDERS() MAKE_PROVIDERS_EPS(1e-3) |
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,68 @@ | ||
// Copyright (c) Microsoft Corporation. All rights reserved. | ||
// Copyright (c) 2023 NVIDIA Corporation. | ||
// Licensed under the MIT License. | ||
|
||
#include "nhwc_cuda_helper.h" | ||
|
||
namespace onnxruntime { | ||
namespace test { | ||
|
||
template <typename T> | ||
struct BatchNormOp { | ||
const std::vector<int64_t> input_dims; | ||
|
||
std::unique_ptr<CompareOpTester> get_test() { | ||
// create rand inputs | ||
RandomValueGenerator random{}; | ||
|
||
auto test = std::make_unique<CompareOpTester>("BatchNormalization", 14); | ||
std::vector<T> input_data = random.Uniform<T>(input_dims, 0.0f, 0.3f); | ||
auto channels = input_dims[1]; | ||
test->AddInput<T>("X", input_dims, input_data); | ||
|
||
std::vector<int64_t> bias_dims{channels}; | ||
std::vector<T> bias_data = random.Uniform<T>(bias_dims, 0.2f, 1.0f); | ||
test->AddInput<T>("B", bias_dims, bias_data); | ||
// we simply gonna reuse the bias data here. | ||
test->AddInput<T>("scale", bias_dims, bias_data); | ||
|
||
std::vector<int64_t> mean{channels}; | ||
std::vector<T> mean_data = random.Uniform<T>(mean, 0.7f, 0.8f); | ||
test->AddInput<T>("input_mean", bias_dims, bias_data); | ||
std::vector<int64_t> var{channels}; | ||
std::vector<T> var_data = random.Uniform<T>(var, 0.0f, 0.1f); | ||
test->AddInput<T>("input_var", bias_dims, bias_data); | ||
|
||
std::vector<T> output_data = FillZeros<T>(input_dims); | ||
test->AddOutput<T>("Y", input_dims, output_data); | ||
return test; | ||
} | ||
}; | ||
|
||
TEST(CudaNhwcTest, BatchNormNhwcBias) { | ||
{ | ||
auto op = BatchNormOp<float>{ | ||
.input_dims = {4, 16, 64, 64}, | ||
}; | ||
|
||
MAKE_PROVIDERS() | ||
} | ||
{ | ||
auto op = BatchNormOp<MLFloat16>{ | ||
.input_dims = {4, 16, 64, 64}, | ||
}; | ||
|
||
MAKE_PROVIDERS_EPS(1e-2) | ||
} | ||
} | ||
|
||
// TEST(CudaNhwcTest, InstancehNormNhwc) { | ||
// auto op = InsanceNormOp<MLFloat16>{ | ||
// .input_dims = {4, 16, 64, 64}, | ||
// }; | ||
|
||
// MAKE_PROVIDERS() | ||
// } | ||
|
||
} // namespace test | ||
} // namespace onnxruntime |
Oops, something went wrong.