-
Notifications
You must be signed in to change notification settings - Fork 3.9k
ResizeGrad CUDA/ROCM kernel implementation #17772
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
11 commits
Select commit
Hold shift + click to select a range
5b7d4df
ResizeGrad CUDA kernel implementation
baijumeswani c772047
Register rocm kernels and address other pipeline failures
baijumeswani 7978819
Merge branch 'main' of https://github.com/microsoft/onnxruntime into …
baijumeswani b1bc9a5
Address pull request review comments
baijumeswani e2e1b88
Use cuda only
baijumeswani 9ba2021
Address pipeline failure
baijumeswani 581f9cd
typo
baijumeswani 95930ef
Merge branch 'main' of https://github.com/microsoft/onnxruntime into …
baijumeswani b3589c8
Enable rocm ep for gradient checker test
baijumeswani 048caee
Fix rocm error later
baijumeswani 046449f
Merge branch 'main' of https://github.com/microsoft/onnxruntime into …
baijumeswani File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
227 changes: 227 additions & 0 deletions
227
orttraining/orttraining/test/training_ops/cuda/resize_grad_test.cc
This file contains hidden or 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,227 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| #include "test/providers/compare_provider_test_utils.h" | ||
| #include "test/providers/provider_test_utils.h" | ||
| #include "test/util/include/default_providers.h" | ||
|
|
||
| namespace onnxruntime::test { | ||
|
|
||
| #if defined(USE_CUDA) || defined(USE_ROCM) | ||
|
|
||
| namespace { | ||
|
|
||
| void AddResizeGradAttributes(OpTester& test, const std::string& coordinate_transformation_mode) { | ||
| test.AddAttribute<std::string>("mode", "linear"); | ||
| test.AddAttribute<std::string>("coordinate_transformation_mode", coordinate_transformation_mode); | ||
| } | ||
|
|
||
| } // namespace | ||
|
|
||
| TEST(ResizeGradTest, ResizeGradWithSizes) { | ||
| std::vector<std::unique_ptr<IExecutionProvider>> providers; | ||
| #ifdef USE_CUDA | ||
| providers.emplace_back(DefaultCudaExecutionProvider()); | ||
| #elif USE_ROCM | ||
| providers.emplace_back(DefaultRocmExecutionProvider()); | ||
| #endif | ||
|
|
||
| OpTester test("ResizeGrad", 1, onnxruntime::kMSDomain); | ||
|
|
||
| AddResizeGradAttributes(test, "half_pixel"); | ||
|
|
||
| std::vector<float> dY(128, 1.0f); | ||
| std::vector<int64_t> dY_shape = {1, 2, 8, 8}; | ||
|
|
||
| std::vector<float> X(32, 1.0f); | ||
| std::vector<int64_t> X_shape = {1, 2, 4, 4}; | ||
|
|
||
| std::vector<float> dX(32, 4.0f); | ||
| std::vector<int64_t> dX_shape = X_shape; | ||
|
|
||
| test.AddInput<float>("dY", dY_shape, dY); | ||
| test.AddInput<float>("X", X_shape, X); | ||
|
|
||
| test.AddOutput<float>("dX", dX_shape, dX); | ||
|
|
||
| test.Run(OpTester::ExpectResult::kExpectSuccess, "", {}, nullptr, &providers); | ||
| } | ||
|
|
||
| TEST(ResizeGradTest, ResizeGradWithSizesHalf) { | ||
| std::vector<std::unique_ptr<IExecutionProvider>> providers; | ||
| #ifdef USE_CUDA | ||
| providers.emplace_back(DefaultCudaExecutionProvider()); | ||
| #elif USE_ROCM | ||
| providers.emplace_back(DefaultRocmExecutionProvider()); | ||
| #endif | ||
|
|
||
| OpTester test("ResizeGrad", 1, onnxruntime::kMSDomain); | ||
|
|
||
| AddResizeGradAttributes(test, "half_pixel"); | ||
|
|
||
| std::vector<float> dY(128, 1.0f); | ||
| std::vector<MLFloat16> dY_half(dY.size()); | ||
| ConvertFloatToMLFloat16(dY.data(), dY_half.data(), static_cast<int>(dY.size())); | ||
| std::vector<int64_t> dY_shape = {1, 2, 8, 8}; | ||
|
|
||
| std::vector<float> X(32, 1.0f); | ||
| std::vector<MLFloat16> X_half(X.size()); | ||
| ConvertFloatToMLFloat16(X.data(), X_half.data(), static_cast<int>(X.size())); | ||
| std::vector<int64_t> X_shape = {1, 2, 4, 4}; | ||
|
|
||
| std::vector<float> dX(32, 4.0f); | ||
| std::vector<MLFloat16> dX_half(dX.size()); | ||
| ConvertFloatToMLFloat16(dX.data(), dX_half.data(), static_cast<int>(dX.size())); | ||
| std::vector<int64_t> dX_shape = X_shape; | ||
|
|
||
| test.AddInput<MLFloat16>("dY", dY_shape, dY_half); | ||
| test.AddInput<MLFloat16>("X", X_shape, X_half); | ||
|
|
||
| test.AddOutput<MLFloat16>("dX", dX_shape, dX_half); | ||
|
|
||
| test.Run(OpTester::ExpectResult::kExpectSuccess, "", {}, nullptr, &providers); | ||
| } | ||
|
|
||
| TEST(ResizeGradTest, ResizeGradWithSizesAndAlignCorners) { | ||
| std::vector<std::unique_ptr<IExecutionProvider>> providers; | ||
| #ifdef USE_CUDA | ||
| providers.emplace_back(DefaultCudaExecutionProvider()); | ||
| #elif USE_ROCM | ||
| providers.emplace_back(DefaultRocmExecutionProvider()); | ||
| #endif | ||
|
|
||
| OpTester test("ResizeGrad", 1, onnxruntime::kMSDomain); | ||
|
|
||
| AddResizeGradAttributes(test, "align_corners"); | ||
|
|
||
| std::vector<float> dY(128, 1.0f); | ||
| std::vector<int64_t> dY_shape = {1, 2, 8, 8}; | ||
|
|
||
| std::vector<float> X(32, 1.0f); | ||
| std::vector<int64_t> X_shape = {1, 2, 4, 4}; | ||
|
|
||
| std::vector<float> dX({2.9388f, 3.9184f, 3.9184f, 2.9388f, 3.9184f, 5.2245f, 5.2245f, 3.9184f, | ||
| 3.9184f, 5.2245f, 5.2245f, 3.9184f, 2.9388f, 3.9184f, 3.9184f, 2.9388f, | ||
| 2.9388f, 3.9184f, 3.9184f, 2.9388f, 3.9184f, 5.2245f, 5.2245f, 3.9184f, | ||
| 3.9184f, 5.2245f, 5.2245f, 3.9184f, 2.9388f, 3.9184f, 3.9184f, 2.9388f}); | ||
| std::vector<int64_t> dX_shape = X_shape; | ||
|
|
||
| test.AddInput<float>("dY", dY_shape, dY); | ||
| test.AddInput<float>("X", X_shape, X); | ||
|
|
||
| test.AddOutput<float>("dX", dX_shape, dX); | ||
|
|
||
| test.Run(OpTester::ExpectResult::kExpectSuccess, "", {}, nullptr, &providers); | ||
| } | ||
|
|
||
| TEST(ResizeGradTest, ResizeGradWithScales) { | ||
| std::vector<std::unique_ptr<IExecutionProvider>> providers; | ||
| #ifdef USE_CUDA | ||
| providers.emplace_back(DefaultCudaExecutionProvider()); | ||
| #elif USE_ROCM | ||
| providers.emplace_back(DefaultRocmExecutionProvider()); | ||
| #endif | ||
|
|
||
| OpTester test("ResizeGrad", 1, onnxruntime::kMSDomain); | ||
|
|
||
| AddResizeGradAttributes(test, "half_pixel"); | ||
|
|
||
| std::vector<float> dY(72, 1.0f); | ||
| std::vector<int64_t> dY_shape = {1, 2, 6, 6}; | ||
|
|
||
| std::vector<float> X(32, 1.0f); | ||
| std::vector<int64_t> X_shape = {1, 2, 4, 4}; | ||
|
|
||
| std::vector<float> dX({2.7128f, 2.9550f, 2.7612f, 1.4533f, 2.9550f, 3.2189f, 3.0078f, 1.5830f, | ||
| 2.7612f, 3.0078f, 2.8106f, 1.4792f, 1.4533f, 1.5830f, 1.4792f, 0.7785f, | ||
| 2.7128f, 2.9550f, 2.7612f, 1.4533f, 2.9550f, 3.2189f, 3.0078f, 1.5830f, | ||
| 2.7612f, 3.0078f, 2.8106f, 1.4792f, 1.4533f, 1.5830f, 1.4792f, 0.7785f}); | ||
| std::vector<int64_t> dX_shape = X_shape; | ||
|
|
||
| test.AddInput<float>("dY", dY_shape, dY); | ||
| test.AddInput<float>("X", X_shape, X); | ||
| test.AddInput<float>("", {0}, {}); | ||
| test.AddInput<float>("scales", {4}, {1.0f, 1.0f, 1.7f, 1.7f}); | ||
|
|
||
| test.AddOutput<float>("dX", dX_shape, dX); | ||
|
|
||
| test.Run(OpTester::ExpectResult::kExpectSuccess, "", {}, nullptr, &providers); | ||
| } | ||
|
|
||
| TEST(ResizeGradTest, ResizeGradWithScalesHalf) { | ||
| std::vector<std::unique_ptr<IExecutionProvider>> providers; | ||
| #ifdef USE_CUDA | ||
| providers.emplace_back(DefaultCudaExecutionProvider()); | ||
| #elif USE_ROCM | ||
| providers.emplace_back(DefaultRocmExecutionProvider()); | ||
| #endif | ||
|
|
||
| OpTester test("ResizeGrad", 1, onnxruntime::kMSDomain); | ||
|
|
||
| AddResizeGradAttributes(test, "half_pixel"); | ||
|
|
||
| std::vector<float> dY(72, 1.0f); | ||
| std::vector<MLFloat16> dY_half(dY.size()); | ||
| ConvertFloatToMLFloat16(dY.data(), dY_half.data(), static_cast<int>(dY.size())); | ||
| std::vector<int64_t> dY_shape = {1, 2, 6, 6}; | ||
|
|
||
| std::vector<float> X(32, 1.0f); | ||
| std::vector<MLFloat16> X_half(X.size()); | ||
| ConvertFloatToMLFloat16(X.data(), X_half.data(), static_cast<int>(X.size())); | ||
| std::vector<int64_t> X_shape = {1, 2, 4, 4}; | ||
|
|
||
| std::vector<float> dX({2.7128f, 2.9550f, 2.7612f, 1.4533f, 2.9550f, 3.2189f, 3.0078f, 1.5830f, | ||
| 2.7612f, 3.0078f, 2.8106f, 1.4792f, 1.4533f, 1.5830f, 1.4792f, 0.7785f, | ||
| 2.7128f, 2.9550f, 2.7612f, 1.4533f, 2.9550f, 3.2189f, 3.0078f, 1.5830f, | ||
| 2.7612f, 3.0078f, 2.8106f, 1.4792f, 1.4533f, 1.5830f, 1.4792f, 0.7785f}); | ||
| std::vector<MLFloat16> dX_half(dX.size()); | ||
| ConvertFloatToMLFloat16(dX.data(), dX_half.data(), static_cast<int>(dX.size())); | ||
| std::vector<int64_t> dX_shape = X_shape; | ||
|
|
||
| test.AddInput<MLFloat16>("dY", dY_shape, dY_half); | ||
| test.AddInput<MLFloat16>("X", X_shape, X_half); | ||
| test.AddInput<float>("", {0}, {}); | ||
| test.AddInput<float>("scales", {4}, {1.0f, 1.0f, 1.7f, 1.7f}); | ||
|
|
||
| test.AddOutput<MLFloat16>("dX", dX_shape, dX_half); | ||
|
|
||
| test.Run(OpTester::ExpectResult::kExpectSuccess, "", {}, nullptr, &providers); | ||
| } | ||
|
|
||
| TEST(ResizeGradTest, ResizeGradWithScalesAndAlignCorners) { | ||
| std::vector<std::unique_ptr<IExecutionProvider>> providers; | ||
| #ifdef USE_CUDA | ||
| providers.emplace_back(DefaultCudaExecutionProvider()); | ||
| #elif USE_ROCM | ||
| providers.emplace_back(DefaultRocmExecutionProvider()); | ||
| #endif | ||
|
|
||
| OpTester test("ResizeGrad", 1, onnxruntime::kMSDomain); | ||
|
|
||
| AddResizeGradAttributes(test, "align_corners"); | ||
|
|
||
| std::vector<float> dY(72, 1.0f); | ||
| std::vector<int64_t> dY_shape = {1, 2, 6, 6}; | ||
|
|
||
| std::vector<float> X(32, 1.0f); | ||
| std::vector<int64_t> X_shape = {1, 2, 4, 4}; | ||
|
|
||
| std::vector<float> dX({1.9600f, 2.2400f, 2.2400f, 1.9600f, 2.2400f, 2.5600f, 2.5600f, 2.2400f, | ||
| 2.2400f, 2.5600f, 2.5600f, 2.2400f, 1.9600f, 2.2400f, 2.2400f, 1.9600f, | ||
| 1.9600f, 2.2400f, 2.2400f, 1.9600f, 2.2400f, 2.5600f, 2.5600f, 2.2400f, | ||
| 2.2400f, 2.5600f, 2.5600f, 2.2400f, 1.9600f, 2.2400f, 2.2400f, 1.9600f}); | ||
| std::vector<int64_t> dX_shape = X_shape; | ||
|
|
||
| test.AddInput<float>("dY", dY_shape, dY); | ||
| test.AddInput<float>("X", X_shape, X); | ||
| test.AddInput<float>("", {0}, {}); | ||
| test.AddInput<float>("scales", {4}, {1.0f, 1.0f, 1.7f, 1.7f}); | ||
|
|
||
| test.AddOutput<float>("dX", dX_shape, dX); | ||
|
|
||
| test.Run(OpTester::ExpectResult::kExpectSuccess, "", {}, nullptr, &providers); | ||
| } | ||
|
|
||
| #endif // defined(USE_CUDA) || defined(USE_ROCM) | ||
|
|
||
| } // namespace onnxruntime::test |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.