Skip to content

perf: reduce redundant CUDA initialization and synchronization - #190

Open
chen2021673 wants to merge 2 commits into
masterfrom
remove_fill
Open

perf: reduce redundant CUDA initialization and synchronization#190
chen2021673 wants to merge 2 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
// 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 函数同理。

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