From 5dde8275ebf2c56d0984eea1d65031bdc05f9201 Mon Sep 17 00:00:00 2001 From: Maziar Entezar Date: Sun, 13 Oct 2019 11:25:24 +0200 Subject: [PATCH] fixes 'misaligned address' when using 'group' parameter in CNN layers. This fixes the error by aligning by the address to be multiple of m (32). Fixes also another bug of not correctly grouped if..else see: https://github.com/BVLC/caffe/issues/5729 --- src/caffe/layers/cudnn_conv_layer.cpp | 11 +++++++---- 1 file changed, 7 insertions(+), 4 deletions(-) diff --git a/src/caffe/layers/cudnn_conv_layer.cpp b/src/caffe/layers/cudnn_conv_layer.cpp index 1987fb096b0..859e76fd0c5 100644 --- a/src/caffe/layers/cudnn_conv_layer.cpp +++ b/src/caffe/layers/cudnn_conv_layer.cpp @@ -186,6 +186,8 @@ void CuDNNConvolutionLayer::Reshape( total_workspace_bwd_data); max_workspace = std::max(max_workspace, total_workspace_bwd_filter); // ensure all groups have enough workspace + size_t m=32; + max_workspace = (max_workspace + m-1) / m * m; //align address to be multiples of m size_t total_max_workspace = max_workspace * (this->group_ * CUDNN_STREAMS_PER_GROUP); @@ -217,10 +219,11 @@ void CuDNNConvolutionLayer::Reshape( workspaceData = NULL; workspaceSizeInBytes = 0; } - - // if we succeed in the allocation, set pointer aliases for workspaces - for (int g = 0; g < (this->group_ * CUDNN_STREAMS_PER_GROUP); g++) { - workspace[g] = reinterpret_cast(workspaceData) + g*max_workspace; + else { + // if we succeed in the allocation, set pointer aliases for workspaces + for (int g = 0; g < (this->group_ * CUDNN_STREAMS_PER_GROUP); g++) { + workspace[g] = reinterpret_cast(workspaceData) + g*max_workspace; + } } }