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

[CPU] Faster reduce kernel for SHM allreduce #4049

Merged
merged 1 commit into from
Jul 27, 2023
Merged
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
5 changes: 5 additions & 0 deletions csrc/cpu/comm/ccl.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
#include <fcntl.h>
#include <immintrin.h>
#include <math.h>
#include <omp.h>
#include <sys/mman.h>
#include <sys/stat.h>
#include <unistd.h>
Expand Down Expand Up @@ -188,6 +189,7 @@ void reduce_all_buffers(struct allreduce_workspace* workspace,
// num_elements must be divisible by 16 (caller check)
void reduce_bf16_buffers(int num_elements, int num_buffers, struct allreduce_workspace* workspace)
{
#pragma omp parallel for
for (int i = 0; i < num_elements * 2; i += VECTOR_LENGTH_IN_BYTES) {
auto inout_val = cvt_bf16_to_fp32(_mm256_loadu_si256((__m256i*)(workspace[0].buffer + i)));
switch (num_buffers) {
Expand All @@ -205,6 +207,7 @@ void reduce_bf16_buffers(int num_elements, int num_buffers, struct allreduce_wor

void reduce_2_bf16_buffers(int num_elements, void* in_out, void* in1)
{
#pragma omp parallel for
for (int i = 0; i < num_elements * 2; i += VECTOR_LENGTH_IN_BYTES) {
auto inout_val = cvt_bf16_to_fp32(_mm256_loadu_si256((__m256i*)((char*)in_out + i)));
auto in1_val = cvt_bf16_to_fp32(_mm256_loadu_si256((__m256i*)((char*)in1 + i)));
Expand All @@ -222,6 +225,7 @@ void reduce_2_bf16_buffers(int num_elements, void* in_out, void* in1)
// num_elements must be divisible by 16 (caller check)
void reduce_fp32_buffers(int num_elements, int num_buffers, struct allreduce_workspace* workspace)
{
#pragma omp parallel for
for (int i = 0; i < num_elements * 4; i += VECTOR_LENGTH_IN_BYTES) {
auto inout_val = _mm256_loadu_ps((float*)(workspace[0].buffer + i));
switch (num_buffers) {
Expand All @@ -239,6 +243,7 @@ void reduce_fp32_buffers(int num_elements, int num_buffers, struct allreduce_wor

void reduce_2_fp32_buffers(int num_elements, void* in_out, void* in1)
{
#pragma omp parallel for
for (int i = 0; i < num_elements * 4; i += VECTOR_LENGTH_IN_BYTES) {
auto inout_val = _mm256_loadu_ps((float*)((char*)in_out + i));
auto in1_val = _mm256_loadu_ps((float*)((char*)in1 + i));
Expand Down
3 changes: 3 additions & 0 deletions op_builder/cpu/comm.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,9 @@ def include_paths(self):
includes = ['csrc/cpu/includes']
return includes

def cxx_args(self):
return ['-O2', '-fopenmp']

def is_compatible(self, verbose=True):
# TODO: add soft compatibility check for private binary release.
# a soft check, as in we know it can be trivially changed.
Expand Down