Open
Conversation
sanjibansg
reviewed
Mar 21, 2026
Member
sanjibansg
left a comment
There was a problem hiding this comment.
Hi @harz05,
Thanks for the PR. A question regarding the onnx file for testing.
Comment on lines
+2
to
+6
| """Generate BatchNorm.onnx and print reference output values for BatchNorm.ref.hxx. | ||
|
|
||
| Model: nn.BatchNorm2d(2) in eval mode, input shape (1, 2, 2, 2). | ||
| """ | ||
|
|
Member
There was a problem hiding this comment.
How will this file be executed? Also, since you provide the .onnx file anyway, how will this script be useful?
Author
There was a problem hiding this comment.
Thank you for reviewing,
this file is standalone and I included it for reproducibility so that the model and ref values can be regenerated and verified independently. python3 BatchNormModelGenerator.py executes the file and we get the .onnx along with the ref values.
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
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Closes #4
This implements the 3 GPU/Alpaka methods for
ROperator_BatchNormalizationand adds a test in the Alpaka CUDA test suite.ROperator_BatchNormalization.hxxGenerate_GPU_Kernel_ALPAKA: elementwise kernel struct.Initialize()already pre-expands per-channel scale/bias/mean tensors to the full[N,C,H,W]shape and folds1/sqrt(var + eps)into scale, so the per-element formula reduces toy[i] = (x[i] - mean[i]) * scale[i] + bias[i]. Kernel pattern is same like other operatorsGenerate_GPU_Kernel_Definitions_ALPAKA: declares the kernel instance used at launch.Generate_GPU_ALPAKA: sets up work division via alpaka::getValidWorkDiv and dispatches the kernel with alpaka::exec. Uses thedeviceBuf_<name>buffers for all weight tensors consistent with howRModel_ALPAKA.cxxallocates them.Files for testing:
BatchNormModelGenerator.py: createsBatchNorm.onnxfromnn.BatchNorm2d(2)in eval mode with fixed weights. Input shape(1, 2, 2, 2), scale[1, 2], bias[0, 0.5], running mean[0.5, 3], running var[1, 4]. Also prints the reference floats used in the.ref.hxx.input_models/BatchNorm.onnx: the exported ONNX model (opset 13).input_models/references/BatchNorm.ref.hxx: 8 reference output values computed by PyTorch.TestCustomModelsFromONNXForAlpakaCuda.cxx: addedSofieAlpakaTest.BatchNormwhich loads the model on GPU, runs inference, and checks each output element against the reference within tolerance.Testing:
Tested on Google Colab (NVIDIA T4, CUDA 12.x). New test passes and all 26 tests in the suite pass with no regressions.