Turn on suggestions

Auto-suggest helps you quickly narrow down your search results by suggesting possible matches as you type.

Showing results for

- Intel Community
- Software
- Software Development SDKs and Libraries
- Intel® oneAPI Math Kernel Library
- 1D convolution of a 3D array using Intel MKL

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Mute
- Printer Friendly Page

A2009

Beginner

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

12-12-2014
08:52 AM

143 Views

1D convolution of a 3D array using Intel MKL

I have a 3D array which is stored in a columnwise fashion.

for( int k = 0; k < nTop; k++ ) // Loop through the tops. for( int j = 0; j < nCol; j++ ) // Loop through the columns. for( int i = 0; i < nRow; i++ ) // Loop through the rows { ijk = i + nRow * j + nRow * nCol * k; my3Darray[ ijk ] = 1.0; }

I want to apply three different 1D kernels of size 2x1 across all the rows, all the columns, and all the tops of my 3D array separately and one after another.

To be able to use Intel MKL, I read the MKL documentation which describes creating a new convolution or correlation task descriptor for multidimensional case. I carefully read "Mathematical Notation and Definitions" that talks about the notations used for convolution. I also read the example file named vslsconv_2d_auto.c. I am lost in the implementation of 1D convolution to a 3D array.

The following code is my understanding from the documentation in a simple C code, which is the modified version of the example file vslsconv_2d_auto.c. In my code, I am trying to apply 1D convolution with kernel = [-1 1] on all the rows of the 3D array and get the convolved result which has the same size as the input. My array has a general size of nRow×nCol×nTop. In the example code below, I chose the size to be 3×4×5.

int main() { VSLConvTaskPtr task; int nRow = 3, nCol = 4, nTop = 5; double *x = new double[nRow*nCol*nTop]; int n1Ker = 2, n2Ker = 1; double *kernel = new double[ n1Ker*n2Ker ]; double *xConvolved = new double[(nRow+n1Ker)*(nCol+n2Ker)*nTop]; MKL_INT xshape[3] = {nRow, nCol, nTop}; MKL_INT convolved_shape[3] = {nRow, nCol, nTop}; MKL_INT kernel_shape[2]= {2,1}; MKL_INT rank=3; int status; for( int i = 0; i < nRow*nCol*nTop; i++ ) x[ i ] = 1; kernel[ 0 ] = -1; kernel[ 1 ] = 1; int mode = VSL_CONV_MODE_AUTO; /* Create task descriptor (create descriptor of problem) */ status = vsldConvNewTask(&task, mode, rank, xshape, kernel_shape, convolved_shape); if( status != VSL_STATUS_OK ){ printf("ERROR: creation of job failed, exit with %d\n", status); return 1;} /* Execute task (Calculate 2 dimension convolution of two arrays) */ status = vsldConvExec(task, x, NULL, kernel, NULL, xConvolved, NULL); if( status != VSL_STATUS_OK ){ printf("ERROR: job status bad, exit with %d\n", status); return 1;} /* Delete task object (delete descriptor of problem) */ status = vslConvDeleteTask(&task); if( status != VSL_STATUS_OK ){ printf("ERROR: failed to delete task object, exit with %d\n", status); return 1;} for( int i = 0; i < nRow*nCol*nTop; i++) printf("%f\n", xConvolved); delete[] x; delete[] xConvolved; delete[] kernel; return 0; }

After running the code, I get the following error:

**ERROR: job status bad, exit with -2312**

I would be thankful if my colleagues in the forum could let me know how I can fix this issue and help me find out how to correctly get 1D convolution of a 3D array on its rows, columns, or tops.

Link Copied

1 Reply

Dmitry_B_Intel

Employee

- Mark as New
- Bookmark
- Subscribe
- Mute
- Subscribe to RSS Feed
- Permalink
- Email to a Friend
- Report Inappropriate Content

12-15-2014
08:58 PM

143 Views

Hi,

When you do a rank=3 convolution on an array, that means all three shapes (x, y, and z) have rank=3. It is a error to give rank=2 kernel_shape to the task constructor, and this error cannot be reported by the constructor.

The shape of the output for convolution should span range [Rmin...Rmax], or [ 0..nRow-1+n1Ker-1, 0..nCol-1+n2Ker-1, ...], according to the "Mathematical Notation and Definitions" subsection of MKL Reference Manual. The definition of convolved_shape does not conform to this rule.

Thanks

Dima

Topic Options

- Subscribe to RSS Feed
- Mark Topic as New
- Mark Topic as Read
- Float this Topic for Current User
- Bookmark
- Subscribe
- Printer Friendly Page

For more complete information about compiler optimizations, see our Optimization Notice.