Brook Code Leaks memory?

Discussion created by entity279 on Nov 22, 2008
Latest reply on Nov 27, 2008 by entity279

Ok, I have built my rather big app - an lvq classifier algorithm, it uses a small brook+ function (for now) which calls on two kernels. Problem is the whole project crashes if I run it outside the IDE (in release OR debug mode) and it only works in debug mode within the IDE (VS 2005).

The brook code itself is tested and works perfectly in debug or release mode while ofcourse, when commenting the brook call in the big project, it also works.

The crash is related with corrupted heap (invalid heap pointer). Now, I've been doing step by step debug in order to double check all memory allocations and free()s and I've came to this loop:


 for (i=0;i

     for (j=0;j    {

    //obtin fiecare codebook cevtor in parte

     if (tmp_vector==NULL)
          printf("\nEroare neasteptata!!");


     if (cur_dist     {


     Well, nothing is allocated here and this is still in a .cpp file. The brook+ call is ofcourse dist_wrapper(). image, Tmp_vector are float *, each of 784 elements. Both are already allocated

- tmp_vector's adress is received through getVect() call

- image is a parameter of the enclosing function , coming from an already allocated, big, float ** structure.

      All the other dist_wrapper parameters are integeres.


     Before I get to this loop, tot mem usage of the app is around 192,320 KB. Ofcourse, while looping, the usage shouldn't increase, right? Now the thing is, once per 4-6 calls  (should be more than 6 calls, actually) of distance_wrapper memory usage increases by 4KB. And the loop is run 50 times, but the enclosing function is run 60,000 times.  Now for example, after 23,488 runs of the enclosing function i have 690,044 KB mem used. Ok, so let's see distance_wrapper:


void dist_wrapper(float *img1, float *img2, const int height, const int                                       width, float *distance)
  uint img_lenght = height * width, k = 0, j = 0, i = 0;
  float result;

  ::brook::stream res(::brook::getStreamType(( float *)0), img_lenght,-1), sample2(::brook::getStreamType(( float *)0), img_lenght,-1), sample1(::brook::getStreamType(( float *)0), img_lenght,-1);
  ::brook::stream dist(::brook::getStreamType(( float *)0), 1,-1);

  streamRead(sample1, img1); //mem usage increases sometimes by 4Kb here
  streamRead(sample2, img2);
  construct(sample1, sample2, res);
  distance1(res, dist);
  streamWrite(dist, &result);

  *distance = result;

 -img_lenght is, as i said, 784

 -construct does a simple computation: (input1-input2)*(input1-input2)

 -distance1 is a reduce kernel, summs all 784 floats in input

 -the memory usage increases after the first streamRead



1. I would appreciate any suggestion why this is happening, or a solution to this (ofcourse )

2. I assumed the problem is brook related, but it might be my own code there somewhere (although I am writing this post being convinced that it isn't). Also I am not familiar at all  with the way Visual studio handles debugging, and i think it also might be a VS issue/"feature". I am therefore sorry if my problem isn't brook related

3. Thank you for the time you took reading this