Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 12 additions & 0 deletions onnxruntime/core/providers/cuda/nn/instance_norm.cc
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,12 @@ Status InstanceNorm<T>::ComputeInternal(OpKernelContext* p_op_kernel_context) co
const TensorShape& x_shape = X->Shape();
Tensor* Y = p_op_kernel_context->Output(0, x_shape);

// Empty inputs are valid in ONNX and should produce empty outputs.
// Early return avoids stats_count == 0 in the N != 1 path.
if (x_shape.Size() == 0) {
return Status::OK();
}

auto* y_data = reinterpret_cast<CudaT*>(Y->MutableData<T>());
const auto* x_data = reinterpret_cast<const CudaT*>(X->Data<T>());
const auto* scale_data = reinterpret_cast<const CudaT*>(scale->Data<T>());
Expand Down Expand Up @@ -174,6 +180,12 @@ Status InstanceNorm<MLFloat16>::ComputeInternal(OpKernelContext* p_op_kernel_con
const TensorShape& x_shape = X->Shape();
Tensor* Y = p_op_kernel_context->Output(0, x_shape);

// Empty inputs are valid in ONNX and should produce empty outputs.
// Early return avoids stats_count == 0 in the N != 1 path.
if (x_shape.Size() == 0) {
return Status::OK();
}

auto* y_data = reinterpret_cast<CudaT*>(Y->MutableData<MLFloat16>());
const auto* x_data = reinterpret_cast<const CudaT*>(X->Data<MLFloat16>());
const auto* scale_data = reinterpret_cast<const CudaT*>(scale->Data<MLFloat16>());
Expand Down
39 changes: 39 additions & 0 deletions onnxruntime/test/providers/cpu/nn/instance_norm_op_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -224,6 +224,45 @@
}

#endif

#ifdef USE_CUDA
TEST(InstanceNormalizationOpTest, InstanceNormEmptyChannel_Cuda) {
if (!HasCudaEnvironment(0)) {

Check failure on line 230 in onnxruntime/test/providers/cpu/nn/instance_norm_op_test.cc

View workflow job for this annotation

GitHub Actions / Windows GPU TensorRT CI Pipeline

'HasCudaEnvironment': identifier not found

Check failure on line 230 in onnxruntime/test/providers/cpu/nn/instance_norm_op_test.cc

View workflow job for this annotation

GitHub Actions / Windows GPU CUDA CI Pipeline

'HasCudaEnvironment': identifier not found
GTEST_SKIP() << "CUDA not available";
}

OpTester test("InstanceNormalization");
test.AddAttribute("epsilon", 0.3F);

test.AddInput<float>("input", {2, 0, 4, 4}, {});
test.AddInput<float>("scale", {0}, {});
test.AddInput<float>("B", {0}, {});
test.AddOutput<float>("Y", {2, 0, 4, 4}, {});

std::vector<std::unique_ptr<IExecutionProvider>> cuda_only_ep;
cuda_only_ep.push_back(DefaultCudaExecutionProvider());
test.Run(OpTester::ExpectResult::kExpectSuccess, "", {}, nullptr, &cuda_only_ep);
}

TEST(InstanceNormalizationOpTest, InstanceNormEmptyBatch_Cuda) {
if (!HasCudaEnvironment(0)) {

Check failure on line 248 in onnxruntime/test/providers/cpu/nn/instance_norm_op_test.cc

View workflow job for this annotation

GitHub Actions / Windows GPU TensorRT CI Pipeline

'HasCudaEnvironment': identifier not found

Check failure on line 248 in onnxruntime/test/providers/cpu/nn/instance_norm_op_test.cc

View workflow job for this annotation

GitHub Actions / Windows GPU CUDA CI Pipeline

'HasCudaEnvironment': identifier not found
GTEST_SKIP() << "CUDA not available";
}

OpTester test("InstanceNormalization");
test.AddAttribute("epsilon", 0.3F);

test.AddInput<float>("input", {0, 3, 4, 4}, {});
test.AddInput<float>("scale", {3}, {1.0f, 1.0f, 1.0f});
test.AddInput<float>("B", {3}, {0.0f, 0.0f, 0.0f});
test.AddOutput<float>("Y", {0, 3, 4, 4}, {});

std::vector<std::unique_ptr<IExecutionProvider>> cuda_only_ep;
cuda_only_ep.push_back(DefaultCudaExecutionProvider());
test.Run(OpTester::ExpectResult::kExpectSuccess, "", {}, nullptr, &cuda_only_ep);
}
#endif

TEST(InstanceNormalizationOpTest, InstanceNorm_2) {
OpTester test("InstanceNormalization");
test.AddAttribute("epsilon", 0.3F);
Expand Down
Loading