         unsigned long long curr_pixels;
         size_t linear_idx_start;
         
-        unsigned long long buffer_pixels=buffer_length*image_size[0]*image_size[1];
+        unsigned long long buffer_pixels=buffer_length*pixels_per_slice;
         
         unsigned long long* offset_device=(unsigned long long*)malloc(deviceCount*sizeof(unsigned long long));
         unsigned long long* offset_host  =(unsigned long long*)malloc(deviceCount*sizeof(unsigned long long));

                    bytes_device[dev]=curr_pixels+buffer_pixels*!is_first_chunk+buffer_pixels*!is_last_chunk;
                }
                if(i==0){
                    // Precompute indices and needed bytes
                    for (dev = 0; dev < deviceCount; dev++){
                        cudaSetDevice(dev);
                        cudaMemcpyAsync(d_src[dev]+offset_device[dev], src+offset_host[dev]  , bytes_device[dev]*sizeof(float), cudaMemcpyHostToDevice,stream[dev*nStream_device+1]);

                            
                            cudaSetDevice(dev);
                            cudaStreamSynchronize(stream[(dev+1)*nStream_device+1]);
                            cudaMemcpyAsync(d_u[dev] +slices_per_split*pixels_per_slice+buffer_pixels, buffer_u , buffer_pixels*sizeof(float), cudaMemcpyHostToDevice,stream[(dev)*nStream_device+1]);
                            cudaStreamSynchronize(stream[(dev+1)*nStream_device+2]);
                            cudaMemcpyAsync(d_px[dev]+slices_per_split*pixels_per_slice+buffer_pixels, buffer_px, buffer_pixels*sizeof(float), cudaMemcpyHostToDevice,stream[(dev)*nStream_device+2]);
                            cudaStreamSynchronize(stream[(dev+1)*nStream_device+3]);
                            cudaMemcpyAsync(d_py[dev]+slices_per_split*pixels_per_slice+buffer_pixels, buffer_py, buffer_pixels*sizeof(float), cudaMemcpyHostToDevice,stream[(dev)*nStream_device+3]);
                            cudaStreamSynchronize(stream[(dev+1)*nStream_device+4]);
                            cudaMemcpyAsync(d_pz[dev]+slices_per_split*pixels_per_slice+buffer_pixels, buffer_pz, buffer_pixels*sizeof(float), cudaMemcpyHostToDevice,stream[(dev)*nStream_device+4]);
                            
                            
                        }
