convolve with valid option

[Old posts from the commercial version of ArrayFire] Discussion of ArrayFire using CUDA or OpenCL.

Moderator: pavanky

convolve with valid option

Postby sapjunior » Thu Nov 28, 2013 2:06 pm


Now, I'm working on machine learning application which use convolve function with 'valid' option but arrayfire doesn't support it. So i'm doing full convolution and cut down area I want and I experience slow problem when I doing this (This is only test code)
Code: Select all
        array T =randu(5,5,50000)*100;
   array U =randu(4,4,50000)*100;
   array K = array(8,8,50000);
   array O = constant(0,2,2,50000);
   timer start1 = timer::start();

       //If I do 50000*3 with only 1 gfor loop will got error
   for(int i=0;i<30;i++){
      gfor(array j,50000){
   printf("Convolve elapsed seconds: %g\n", timer::stop(start1));

   timer start2 = timer::start();

   //Cut area I want Very Slow here

   printf("Cut area elapsed seconds: %g\n", timer::stop(start2));

Output: Convolve elapsed seconds : 0.250
Cut area elapsed seconds : 1.81

Any suggestion ,please?
Posts: 7
Joined: Fri Aug 16, 2013 6:00 am

Re: convolve with valid option

Postby shehzan » Mon Dec 02, 2013 10:55 am


I would suggest you to use timeit() to time this function. Timer runs the code once and gives the time for that run. Timeit() runs the function multiple times and returns an average. This isn't a problem when you are running a program with a lot of GPU code. But when you run a standalone with just one or a few GPU functions on the same variables, JIT comes into play and the variables may not be evaluated until later on. Hence I suggest you to use timeit.
You can read more about it:
Please see any of the examples listed on the above page to see the usage.

If you are using timer start and stop, please use af::sync() and eval(). As ArrayFire uses JIT compilation, not all statements are executed immediately. There are executed on a need-by-need basis.
User avatar
Posts: 121
Joined: Tue Feb 12, 2013 7:20 pm

Return to [archive-commercial] Programming & Development with ArrayFire