<?xml version="1.0" encoding="UTF-8"?>
<rss xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" xmlns:taxo="http://purl.org/rss/1.0/modules/taxonomy/" version="2.0">
  <channel>
    <title>topic How do I specify a stride between elements when computing a 3D DCT in terms of 1D DCTs? in Intel® oneAPI Math Kernel Library</title>
    <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/How-do-I-specify-a-stride-between-elements-when-computing-a-3D/m-p/924402#M13268</link>
    <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am working on software for acoustics simulation, which requires 3D Discrete Cosine Transforms to be performed. FFTW3 provides the fftwf_plan_r2r_3d function to create plans for just this purpose:&lt;/P&gt;
&lt;P&gt;[cpp]&lt;BR /&gt;fftwf_plan plan = fftwf_plan_r2r_3d(Nx, Ny, Nz, gInData, gOutData, FFTW_REDFT10, FFTW_REDFT10, FFTW_REDFT10, FFTW_PRESERVE_INPUT);&lt;BR /&gt;fftwf_execute(plan);&lt;BR /&gt;[/cpp]&lt;/P&gt;
&lt;P&gt;However, MKL does not support 3D DCTs. So I tried to implement the 3D DCT in terms of multiple 1D DCTs. For some of these 1D DCTs, I need to specify strides between consecutive elements. Again, FFTW3 allows this via the function fftwf_plan_many_r2r, which also doesn't seem to be supported in MKL (the returned plans from MKL's FFTW3 wrappers are always NULL).&lt;/P&gt;
&lt;P&gt;[cpp]&lt;BR /&gt;fftwf_r2r_kind kind = FFTW_REDFT10;&lt;BR /&gt;fftwf_plan planX = fftwf_plan_many_r2r(1, &amp;amp;Nx, 1, gInData, NULL, Ny*Nz, 1, gOutData, NULL, Ny*Nz, 1, &amp;amp;kind, FFTW_PRESERVE_INPUT);&lt;BR /&gt;fftwf_plan planY = fftwf_plan_many_r2r(1, &amp;amp;Ny, 1, gInData, NULL, Nz, 1, gOutData, NULL, Nz, 1, &amp;amp;kind, FFTW_PRESERVE_INPUT);&lt;BR /&gt;fftwf_plan planZ = fftwf_plan_many_r2r(1, &amp;amp;Nz, 1, gInData, NULL, 1, 1, gOutData, NULL, 1, 1, &amp;amp;kind, FFTW_PRESERVE_INPUT);&lt;BR /&gt;&lt;BR /&gt;for (int x = 0; x &amp;lt; Nx; x++)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; for (int y = 0; y &amp;lt; Ny; y++)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fftwf_execute_r2r(planZ, &amp;amp;gInData[x*Ny*Nz + y*Nz], &amp;amp;gOutData[x*Ny*Nz + y*Nz]);&lt;BR /&gt;&lt;BR /&gt;for (int x = 0; x &amp;lt; Nx; x++)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; for (int z = 0; z &amp;lt; Nz; z++)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fftwf_execute_r2r(planY, &amp;amp;gOutData[x*Ny*Nz + z], &amp;amp;gInData[x*Ny*Nz + z]);&lt;BR /&gt;&lt;BR /&gt;for (int y = 0; y &amp;lt; Ny; y++)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; for (int z = 0; z &amp;lt; Nz; z++)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fftwf_execute_r2r(planX, &amp;amp;gInData[y*Nz + z], &amp;amp;gOutData[y*Nz + z]);&lt;BR /&gt;[/cpp]&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I next tried the raw Trigonometric Transforms functions, s_init_trig_transform and the like. These don't seem to offer any way of setting a stride between elements. Since s_commit_trig_transform returns a DFTI_DESCRIPTOR_HANDLE, I tried using DftiSetValue to specify a stride on the descriptor, followed by a call to DftiCommitDescriptor.&lt;/P&gt;
&lt;P&gt;[cpp]&lt;/P&gt;
&lt;P&gt;int tt_type = MKL_STAGGERED_COSINE_TRANSFORM;&lt;BR /&gt; int ir;&lt;BR /&gt; DFTI_DESCRIPTOR_HANDLE dftiX, dftiY, dftiZ;&lt;/P&gt;
&lt;P&gt;int iparX[128];&lt;BR /&gt; float* sparX = new float[3*Nx/2 + 2];&lt;BR /&gt; s_init_trig_transform(&amp;amp;Nx, &amp;amp;tt_type, iparX, sparX, &amp;amp;ir);&lt;BR /&gt; s_commit_trig_transform(gInData, &amp;amp;dftiX, iparX, sparX, &amp;amp;ir);&lt;BR /&gt; int xStride[2] = {0, Ny*Nz};&lt;BR /&gt; DftiSetValue(dftiX, DFTI_INPUT_STRIDES, xStride);&lt;BR /&gt; DftiSetValue(dftiX, DFTI_OUTPUT_STRIDES, xStride);&lt;BR /&gt; DftiCommitDescriptor(dftiX);&lt;/P&gt;
&lt;P&gt;int iparY[128];&lt;BR /&gt; float* sparY = new float[3*Ny/2 + 2];&lt;BR /&gt; s_init_trig_transform(&amp;amp;Ny, &amp;amp;tt_type, iparY, sparY, &amp;amp;ir);&lt;BR /&gt; s_commit_trig_transform(gInData, &amp;amp;dftiY, iparY, sparY, &amp;amp;ir);&lt;BR /&gt; int yStride[2] = {0, Nz};&lt;BR /&gt; DftiSetValue(dftiY, DFTI_INPUT_STRIDES, yStride);&lt;BR /&gt; DftiSetValue(dftiY, DFTI_OUTPUT_STRIDES, yStride);&lt;BR /&gt; DftiCommitDescriptor(dftiY);&lt;/P&gt;
&lt;P&gt;int iparZ[128];&lt;BR /&gt; float* sparZ = new float[3*Nz/2 + 2];&lt;BR /&gt; s_init_trig_transform(&amp;amp;Nz, &amp;amp;tt_type, iparZ, sparZ, &amp;amp;ir);&lt;BR /&gt; s_commit_trig_transform(gInData, &amp;amp;dftiZ, iparZ, sparZ, &amp;amp;ir);&lt;/P&gt;
&lt;P&gt;iparX[6] = 0;&lt;BR /&gt; iparY[6] = 0;&lt;BR /&gt; iparZ[6] = 0;&lt;/P&gt;
&lt;P&gt;iparX[10] = 1;&lt;BR /&gt; iparY[10] = 1;&lt;BR /&gt; iparZ[10] = 1;&lt;/P&gt;
&lt;P&gt;iparX[14] = Nx;&lt;BR /&gt; iparY[14] = Ny;&lt;BR /&gt; iparZ[14] = Nz;&lt;/P&gt;
&lt;P&gt;memcpy(gOutData, gInData, Nx*Ny*Nz*sizeof(float));&lt;/P&gt;
&lt;P&gt;for (int x = 0; x &amp;lt; Nx; x++)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; for (int y = 0; y &amp;lt; Ny; y++)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; s_backward_trig_transform(&amp;amp;gOutData[x*Ny*Nz + y*Nz], &amp;amp;dftiZ, iparZ, sparZ, &amp;amp;ir);&lt;/P&gt;
&lt;P&gt;for (int x = 0; x &amp;lt; Nx; x++)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; for (int z = 0; z &amp;lt; Nz; z++)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; s_backward_trig_transform(&amp;amp;gOutData[x*Ny*Nz + z], &amp;amp;dftiY, iparY, sparY, &amp;amp;ir);&lt;/P&gt;
&lt;P&gt;for (int y = 0; y &amp;lt; Ny; y++)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; for (int z = 0; z &amp;lt; Nz; z++)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; s_backward_trig_transform(&amp;amp;gOutData[y*Nz + z], &amp;amp;dftiX, iparX, sparX, &amp;amp;ir);&lt;/P&gt;
&lt;P&gt;[/cpp]&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, this does not produce correct results (i.e., the results don't match at all with the FFTW 3D DCT or the FFTW multiple-1D-DCT results). I am using MKL 10.3 Update 9 on Windows (32-bit).&lt;/P&gt;
&lt;P&gt;Have I missed something here? Is there a way to either a) specify strides for 1D DCTs, or b) perform 3D DCTs using MKL? In the absence of a way to use MKL to compute 3D DCTs, I will be forced to switch away from using MKL.&lt;/P&gt;
&lt;P&gt;Thanks,&lt;BR /&gt;Lakulish Antani.&amp;nbsp;&lt;/P&gt;</description>
    <pubDate>Sun, 14 Oct 2012 06:04:01 GMT</pubDate>
    <dc:creator>Lakulish_A_</dc:creator>
    <dc:date>2012-10-14T06:04:01Z</dc:date>
    <item>
      <title>How do I specify a stride between elements when computing a 3D DCT in terms of 1D DCTs?</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/How-do-I-specify-a-stride-between-elements-when-computing-a-3D/m-p/924402#M13268</link>
      <description>&lt;P&gt;Hi,&lt;/P&gt;
&lt;P&gt;I am working on software for acoustics simulation, which requires 3D Discrete Cosine Transforms to be performed. FFTW3 provides the fftwf_plan_r2r_3d function to create plans for just this purpose:&lt;/P&gt;
&lt;P&gt;[cpp]&lt;BR /&gt;fftwf_plan plan = fftwf_plan_r2r_3d(Nx, Ny, Nz, gInData, gOutData, FFTW_REDFT10, FFTW_REDFT10, FFTW_REDFT10, FFTW_PRESERVE_INPUT);&lt;BR /&gt;fftwf_execute(plan);&lt;BR /&gt;[/cpp]&lt;/P&gt;
&lt;P&gt;However, MKL does not support 3D DCTs. So I tried to implement the 3D DCT in terms of multiple 1D DCTs. For some of these 1D DCTs, I need to specify strides between consecutive elements. Again, FFTW3 allows this via the function fftwf_plan_many_r2r, which also doesn't seem to be supported in MKL (the returned plans from MKL's FFTW3 wrappers are always NULL).&lt;/P&gt;
&lt;P&gt;[cpp]&lt;BR /&gt;fftwf_r2r_kind kind = FFTW_REDFT10;&lt;BR /&gt;fftwf_plan planX = fftwf_plan_many_r2r(1, &amp;amp;Nx, 1, gInData, NULL, Ny*Nz, 1, gOutData, NULL, Ny*Nz, 1, &amp;amp;kind, FFTW_PRESERVE_INPUT);&lt;BR /&gt;fftwf_plan planY = fftwf_plan_many_r2r(1, &amp;amp;Ny, 1, gInData, NULL, Nz, 1, gOutData, NULL, Nz, 1, &amp;amp;kind, FFTW_PRESERVE_INPUT);&lt;BR /&gt;fftwf_plan planZ = fftwf_plan_many_r2r(1, &amp;amp;Nz, 1, gInData, NULL, 1, 1, gOutData, NULL, 1, 1, &amp;amp;kind, FFTW_PRESERVE_INPUT);&lt;BR /&gt;&lt;BR /&gt;for (int x = 0; x &amp;lt; Nx; x++)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; for (int y = 0; y &amp;lt; Ny; y++)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fftwf_execute_r2r(planZ, &amp;amp;gInData[x*Ny*Nz + y*Nz], &amp;amp;gOutData[x*Ny*Nz + y*Nz]);&lt;BR /&gt;&lt;BR /&gt;for (int x = 0; x &amp;lt; Nx; x++)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; for (int z = 0; z &amp;lt; Nz; z++)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fftwf_execute_r2r(planY, &amp;amp;gOutData[x*Ny*Nz + z], &amp;amp;gInData[x*Ny*Nz + z]);&lt;BR /&gt;&lt;BR /&gt;for (int y = 0; y &amp;lt; Ny; y++)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; for (int z = 0; z &amp;lt; Nz; z++)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; fftwf_execute_r2r(planX, &amp;amp;gInData[y*Nz + z], &amp;amp;gOutData[y*Nz + z]);&lt;BR /&gt;[/cpp]&amp;nbsp;&lt;/P&gt;
&lt;P&gt;I next tried the raw Trigonometric Transforms functions, s_init_trig_transform and the like. These don't seem to offer any way of setting a stride between elements. Since s_commit_trig_transform returns a DFTI_DESCRIPTOR_HANDLE, I tried using DftiSetValue to specify a stride on the descriptor, followed by a call to DftiCommitDescriptor.&lt;/P&gt;
&lt;P&gt;[cpp]&lt;/P&gt;
&lt;P&gt;int tt_type = MKL_STAGGERED_COSINE_TRANSFORM;&lt;BR /&gt; int ir;&lt;BR /&gt; DFTI_DESCRIPTOR_HANDLE dftiX, dftiY, dftiZ;&lt;/P&gt;
&lt;P&gt;int iparX[128];&lt;BR /&gt; float* sparX = new float[3*Nx/2 + 2];&lt;BR /&gt; s_init_trig_transform(&amp;amp;Nx, &amp;amp;tt_type, iparX, sparX, &amp;amp;ir);&lt;BR /&gt; s_commit_trig_transform(gInData, &amp;amp;dftiX, iparX, sparX, &amp;amp;ir);&lt;BR /&gt; int xStride[2] = {0, Ny*Nz};&lt;BR /&gt; DftiSetValue(dftiX, DFTI_INPUT_STRIDES, xStride);&lt;BR /&gt; DftiSetValue(dftiX, DFTI_OUTPUT_STRIDES, xStride);&lt;BR /&gt; DftiCommitDescriptor(dftiX);&lt;/P&gt;
&lt;P&gt;int iparY[128];&lt;BR /&gt; float* sparY = new float[3*Ny/2 + 2];&lt;BR /&gt; s_init_trig_transform(&amp;amp;Ny, &amp;amp;tt_type, iparY, sparY, &amp;amp;ir);&lt;BR /&gt; s_commit_trig_transform(gInData, &amp;amp;dftiY, iparY, sparY, &amp;amp;ir);&lt;BR /&gt; int yStride[2] = {0, Nz};&lt;BR /&gt; DftiSetValue(dftiY, DFTI_INPUT_STRIDES, yStride);&lt;BR /&gt; DftiSetValue(dftiY, DFTI_OUTPUT_STRIDES, yStride);&lt;BR /&gt; DftiCommitDescriptor(dftiY);&lt;/P&gt;
&lt;P&gt;int iparZ[128];&lt;BR /&gt; float* sparZ = new float[3*Nz/2 + 2];&lt;BR /&gt; s_init_trig_transform(&amp;amp;Nz, &amp;amp;tt_type, iparZ, sparZ, &amp;amp;ir);&lt;BR /&gt; s_commit_trig_transform(gInData, &amp;amp;dftiZ, iparZ, sparZ, &amp;amp;ir);&lt;/P&gt;
&lt;P&gt;iparX[6] = 0;&lt;BR /&gt; iparY[6] = 0;&lt;BR /&gt; iparZ[6] = 0;&lt;/P&gt;
&lt;P&gt;iparX[10] = 1;&lt;BR /&gt; iparY[10] = 1;&lt;BR /&gt; iparZ[10] = 1;&lt;/P&gt;
&lt;P&gt;iparX[14] = Nx;&lt;BR /&gt; iparY[14] = Ny;&lt;BR /&gt; iparZ[14] = Nz;&lt;/P&gt;
&lt;P&gt;memcpy(gOutData, gInData, Nx*Ny*Nz*sizeof(float));&lt;/P&gt;
&lt;P&gt;for (int x = 0; x &amp;lt; Nx; x++)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; for (int y = 0; y &amp;lt; Ny; y++)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; s_backward_trig_transform(&amp;amp;gOutData[x*Ny*Nz + y*Nz], &amp;amp;dftiZ, iparZ, sparZ, &amp;amp;ir);&lt;/P&gt;
&lt;P&gt;for (int x = 0; x &amp;lt; Nx; x++)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; for (int z = 0; z &amp;lt; Nz; z++)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; s_backward_trig_transform(&amp;amp;gOutData[x*Ny*Nz + z], &amp;amp;dftiY, iparY, sparY, &amp;amp;ir);&lt;/P&gt;
&lt;P&gt;for (int y = 0; y &amp;lt; Ny; y++)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; for (int z = 0; z &amp;lt; Nz; z++)&lt;BR /&gt;&amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; s_backward_trig_transform(&amp;amp;gOutData[y*Nz + z], &amp;amp;dftiX, iparX, sparX, &amp;amp;ir);&lt;/P&gt;
&lt;P&gt;[/cpp]&amp;nbsp;&lt;/P&gt;
&lt;P&gt;However, this does not produce correct results (i.e., the results don't match at all with the FFTW 3D DCT or the FFTW multiple-1D-DCT results). I am using MKL 10.3 Update 9 on Windows (32-bit).&lt;/P&gt;
&lt;P&gt;Have I missed something here? Is there a way to either a) specify strides for 1D DCTs, or b) perform 3D DCTs using MKL? In the absence of a way to use MKL to compute 3D DCTs, I will be forced to switch away from using MKL.&lt;/P&gt;
&lt;P&gt;Thanks,&lt;BR /&gt;Lakulish Antani.&amp;nbsp;&lt;/P&gt;</description>
      <pubDate>Sun, 14 Oct 2012 06:04:01 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/How-do-I-specify-a-stride-between-elements-when-computing-a-3D/m-p/924402#M13268</guid>
      <dc:creator>Lakulish_A_</dc:creator>
      <dc:date>2012-10-14T06:04:01Z</dc:date>
    </item>
    <item>
      <title>Hi Lakulish,</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/How-do-I-specify-a-stride-between-elements-when-computing-a-3D/m-p/924403#M13269</link>
      <description>Hi Lakulish,

Thank  you very much for very detailed description of the problem and the ways you have been trying to solve it. 

Unfortunately, MKL does not support non-unit stride DCTs. 

Thanks
Dima</description>
      <pubDate>Mon, 15 Oct 2012 07:16:59 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/How-do-I-specify-a-stride-between-elements-when-computing-a-3D/m-p/924403#M13269</guid>
      <dc:creator>Dmitry_B_Intel</dc:creator>
      <dc:date>2012-10-15T07:16:59Z</dc:date>
    </item>
    <item>
      <title>Hi Dmitry,</title>
      <link>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/How-do-I-specify-a-stride-between-elements-when-computing-a-3D/m-p/924404#M13270</link>
      <description>Hi Dmitry,

Thank you for your reply. It's unfortunate that MKL doesn't support non-unit-stride DCTs. Therefore, I would like to report a feature request to the MKL team, for a) non-unit-stride DCTs, and b) 3D DCTs. Let me know if this forum post suffices for this purpose, or if there's another place for me to report such a feature request.

Meanwhile, I will try implementing what I need in terms of non-unit-stride FFTs, which seem to support non-unit strides.

Thanks,
Lakulish.</description>
      <pubDate>Mon, 15 Oct 2012 17:36:12 GMT</pubDate>
      <guid>https://community.intel.com/t5/Intel-oneAPI-Math-Kernel-Library/How-do-I-specify-a-stride-between-elements-when-computing-a-3D/m-p/924404#M13270</guid>
      <dc:creator>Lakulish_A_</dc:creator>
      <dc:date>2012-10-15T17:36:12Z</dc:date>
    </item>
  </channel>
</rss>

