Skip to content

perf: reduce redundant CUDA initialization and synchronization - #190

Merged
kilinchange merged 3 commits into
masterfrom
remove_fill
Aug 13, 2026
Merged

perf: reduce redundant CUDA initialization and synchronization#190
kilinchange merged 3 commits into
masterfrom
remove_fill

Conversation

@chen2021673

@chen2021673 chen2021673 commented Jul 15, 2026

Copy link
Copy Markdown
Contributor

Summary

  • defer loss host synchronization until after backward in GPT-2, Llama3, MNIST, and pipeline training
  • skip zero initialization where CUDA kernels or cuBLAS fully overwrite output tensors
  • add numerical CPU and CUDA coverage for the affected operators

Test

image image

Comment thread tests/autograd/test_autograd_linear_forward.cc Outdated
Comment thread tests/autograd/test_autograd_normalization_backward.cc Outdated
Comment thread tests/autograd/test_autograd_reduction_backward.cc Outdated
Comment thread example/gpt2/main.cc
Comment thread tests/common/test_utils.h
- defer loss host synchronization until after backward across training paths
- skip zero fills when CUDA kernels or cuBLAS fully overwrite outputs
- retain and document initialization required by partial-write paths
- add CPU and CUDA numerical tests for affected operators
Comment thread tests/common/test_utils.h Outdated
// such as reductions, normalization, softmax, and loss calculations. The tolerance is not relative.
// This overload checks the element count and flat order, but not the tensor shape.
inline void ExpectTensorNear(const std::shared_ptr<Tensor> &tensor, const std::vector<float> &expected,
float tolerance) {

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

建议函数参数名也跟 gtest 对齐,tolerance 改成 abs_error,能更直观地看出表示的是绝对误差。下面的 Near 函数同理。

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

已修改为参数名对齐。另外ExpectTensorEqual改成ExpectTensorFloatEqual,因为功能上对齐的其实是gtest EXPECT_FLOAT_EQ

- rename the FP32 equality helper to ExpectTensorFloatEqual
- align assertion parameters with GoogleTest naming
- strengthen LayerNorm numerical coverage
@kilinchange
kilinchange merged commit 32e94e6 into master Aug 13, 2026
2 checks passed
@kilinchange
kilinchange deleted the remove_fill branch August 13, 2026 02:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants