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

Reduce BLAS threads while parallelizing over GEMM #580

Closed
wants to merge 1 commit into from
Closed
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
16 changes: 16 additions & 0 deletions src/impl/conv_im2col.jl
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ function conv_im2col!(
N = channels_out(cdims)
K = prod(kernel_size(cdims))*channels_in(cdims)

# Set BLAS threads to 1 since we are threading over BLAS calls
old_threads = BLAS.get_num_threads()
BLAS.set_num_threads(1)

parts = Iterators.partition(axes(x, 5), ceil(Int, size(x, 5) / ntasks))

@sync for (task_n, part) in enumerate(parts)
Expand All @@ -61,6 +65,10 @@ function conv_im2col!(
end
end
end

# Restore BLAS threads
BLAS.set_num_threads(old_threads)

return y
end

Expand Down Expand Up @@ -150,6 +158,10 @@ function ∇conv_data_im2col!(
N = prod(kernel_size(cdims))*channels_in(cdims)
K = channels_out(cdims)

# Set BLAS threads to 1 since we are threading over BLAS calls
old_threads = BLAS.get_num_threads()
BLAS.set_num_threads(1)

parts = Iterators.partition(axes(dx, 5), ceil(Int, size(dx, 5) / ntasks))

@sync for (task_n, part) in enumerate(parts)
Expand All @@ -166,6 +178,10 @@ function ∇conv_data_im2col!(
end
end
end

# Restore BLAS threads
BLAS.set_num_threads(old_threads)

return dx
end

Expand Down
Loading