Skip to content
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

Batchnorm tuning (re-entrant grid reduction) #1696

Closed
Closed
Show file tree
Hide file tree
Changes from all commits
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
2 changes: 2 additions & 0 deletions torch/csrc/jit/codegen/cuda/ir_interface_nodes.h
Original file line number Diff line number Diff line change
Expand Up @@ -468,7 +468,9 @@ class TORCH_CUDA_CU_API TensorView : public Val {
domain_ = td;
}

public:
void setComputeAt(unsigned int this_pos, bool decrease = false);


void setMaxProducer(unsigned int this_pos, bool decrease = false);

Expand Down
12 changes: 12 additions & 0 deletions torch/csrc/jit/codegen/cuda/runtime/welford.cu
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,12 @@ __inline__ __device__ void welfordCombine(
return;
}
TN ab_N = a_N + b_N;
#if 1
T b_N_div_ab_N = ((T)(nvfuser_index_t)(b_N)) / ((T)(nvfuser_index_t)(ab_N));
#else
// No perf change
T b_N_div_ab_N = a_N == b_N ? 0.5f : (((T)(nvfuser_index_t)(b_N)) / ((T)(nvfuser_index_t)(ab_N)));
#endif
T delta = b_avg - a_avg;
a_avg += delta * b_N_div_ab_N;
a_M2 += b_M2 + delta * delta * ((T)(nvfuser_index_t)(a_N)) * b_N_div_ab_N;
Expand Down Expand Up @@ -350,10 +355,17 @@ __device__ void gridWelford(
grid_sync::sync<X_BLOCK, Y_BLOCK, Z_BLOCK, PERSISTENT_REDUCTION>(
sync_flags[idx_in_grid_segment], grid_reduction_segment_size);
} else {
#if 0
grid_sync::sync<X_BLOCK, Y_BLOCK, Z_BLOCK>(
sync_flags[idx_in_grid_segment],
grid_reduction_segment_size,
n_entrances_);
#else
// Assumes separate sync flags are allocated for each call.
grid_sync::sync<X_BLOCK, Y_BLOCK, Z_BLOCK, PERSISTENT_REDUCTION>(
sync_flags[entrance_ind_ * grid_segment_size + idx_in_grid_segment],
grid_reduction_segment_size);
#endif
}

bool last_block =
Expand Down
Loading