From: Sajjadul I. <saj...@st...> - 2013-03-16 01:23:10
|
Hi Thanks for the hint! I need to use the vectors build on the device to be usable across several function in the host. For example ////////////////////////////////////////////////////////////////////////////////////////////////// int main() { ......................... ......................... //allocate a host vector with a certain size //we are storing the 2D vector field, so each x-component //and y-component are stored in a linear manner //so the dimension DS is multiplied by 2 std::vector<cData> hvfield(DS * 2); //fill the cpu vector with the default values - 0.0f std::fill(hvfield.begin(),hvfield.end(),0.0f); //allocate the vector of same size on the device viennacl::vector<cData> dvfield(DS * 2); //copy the vector from the cpu to the gpu copy(hvfield.begin(),hvfield.end(),dvfield.begin()); viennacl::vector<cData> vxfield(PDS * 2); viennacl::vector<cData> vyfield(PDS * 2); .................................................................... .................................................................... } void display() { simulateFluids(); } void simulateFluids(.....) { //i need to use some vectors here that has been allocated in the main function } ////////////////////////////////////////////////////////////////////////////////////////////////// Now if i put the vector allocation at the global scope i get segmentation fault while running the program. OpenGL's callback display() function do the necessary calculation for the fluid simulation and i need to access the vectors i have allocated. Can they (the ones allocated on the device) be sent as reference in the function parameter ? I checked the tutorials and none of them matched my requirements. Any hint? Regards Sajjadul On Wed, Mar 13, 2013 at 4:50 PM, Karl Rupp <ru...@iu...> wrote: > Hi Sajjadul, > > just define a > viennacl::vector<float>(2*PDS)**; > or > viennacl::vector<double>(2***PDS); > and then fill it with the real part on locations [0],[2], etc. and the > imaginary part on locations [1],[3], etc. > This is pretty similar to what you actually do with cufft. > > The lack of complex_t in current OpenCL is one of the reasons why FFT in > ViennaCL is still experimental. Thus, you cannot properly define a float2 > on the CPU without running into compiler problems (nvcc can only do this > because they have control over the full compilation and thus can do any > non-standard-compliant stuff they want). > > Best regards, > Karli > > > > > > On 03/13/2013 09:43 AM, Sajjadul Islam wrote: > >> Hi forum, >> >> >> I am trying to port an existing CUDA application to OpenCL, and the >> process seems not to be so trivial while working with the custom data >> type and FFT. Below i am describing some custom data type that has been >> assigned in CUDA and my effort to convert them to opencl and also the >> issues that i am currently stuck with: >> >> >> *CUDA* >> * >> * >> * >> >> * >> // Vector data type used to velocity and force fields >> //typedef is a built-in vector types >> typedef float2 cData; >> >> >> //each of the allocation is of size 131584 >> cudaMalloc((void**)&vxfield, sizeof(cData) * PDS); >> cudaMalloc((void**)&vyfield, sizeof(cData) * PDS); >> >> >> ..............................**......... >> ..............................**........ >> >> // Create CUFFT transform plan configuration >> // create a simple plan for 2D transformation >> cufftPlan2d(&planr2c, DIM, DIM, CUFFT_R2C); >> cufftPlan2d(&planc2r, DIM, DIM, CUFFT_C2R); >> // TODO: update kernels to use the new unpadded memory layout for perf >> // rather than the old FFTW-compatible layout >> cufftSetCompatibilityMode(**planr2c, CUFFT_COMPATIBILITY_FFTW_** >> PADDING); >> cufftSetCompatibilityMode(**planc2r, CUFFT_COMPATIBILITY_FFTW_** >> PADDING); >> >> >> ..............................**. >> .............................. >> >> // Forward FFT >> cufftExecR2C(planr2c, (cufftReal*)vx, (cufftComplex*)vx); >> cufftExecR2C(planr2c, (cufftReal*)vy, (cufftComplex*)vy); >> >> ..............................**. >> .............................. >> >> // Inverse FFT >> cufftExecC2R(planc2r, (cufftComplex*)vx, (cufftReal*)vx); >> cufftExecC2R(planc2r, (cufftComplex*)vy, (cufftReal*)vy); >> >> >> >> *OpenCL* >> * >> >> * >> Even if i define custom data type for i am not sure if i can use it >> along with the ViennaCL as you currently are not supporting any type >> other than double / float. >> >> I need to send data to fft function that is of type cl_float2 as you can >> imagine from the above CUDA fft statements. >> >> Still i believe that there must be some way to get around this issue >> and i need you suggestion. >> >> >> I shall be eagerly waiting for your response over this issue. >> >> >> >> Regards >> Sajjad >> >> >> ------------------------------**------------------------------** >> ------------------ >> Everyone hates slow websites. So do we. >> Make your web apps faster with AppDynamics >> Download AppDynamics Lite for free today: >> http://p.sf.net/sfu/appdyn_**d2d_mar <http://p.sf.net/sfu/appdyn_d2d_mar> >> >> >> >> ______________________________**_________________ >> ViennaCL-support mailing list >> ViennaCL-support@lists.**sourceforge.net<Vie...@li...> >> https://lists.sourceforge.net/**lists/listinfo/viennacl-**support<https://lists.sourceforge.net/lists/listinfo/viennacl-support> >> >> > |