0

I'm developing an application in c++/opencl. My development environment includes VS12 and CodeXL. My code compiles and runs in general, as well as compiling under CodeXL's kernel analyzer. However, attempting to use CodeXL in debugging mode always causes a crash. This means I can keep writing, but without kernel debugging.

From successive break points, I believe I've narrowed the culprit down to this nested for/while.

// init flows on bush
nextArc = NUM_ARCS;
for(i = 0; i < NUM_NODES; i++) {
  nextArc = nextMinArc[i];
  while(nextArc < NUM_ARCS) {
    flow[nextArc] += demand[i];
    nextArc = nextMinArc[head[nextArc]-1];
  }
}

This code is found in the auxiliary kernel function below. The full kernel source may be found at https://gist.github.com/dprentiss/10982016.

Is there something I'm missing about loop structures in kernels? Any clue why it runs but can't be debugged with CodeXL?

I would also like to point out that this is my first time working in c/c++/opencl. Your general comments are appreciated in so much as they are constructive. I'm sure I've committed many C sins.

void initNetwork(const uint sinkNode,
                 uint *topoOrder,
                 constant uint *tail,
                 constant uint *head,
                 constant uint *pointer,
                 float *demand,
                 uint *nextMinArc,
                 uint *nextMaxArc,
                 float *minCost,
                 float *maxCost,
                 float *cost,
                 constant float *fftt,
                 constant float *cap,
                 float *flow)
{
  uint i;
  uint place;
  uint queue;
  uint arc;
  float costCand;
  uint nextArc;

  // set topological order of nodes
  for(i = 0; i < NUM_NODES; ++i) {
    topoOrder[i] = 0;
  }
  topoOrder[0] = sinkNode;
  queue = 1;
  for(place = 0; place < NUM_NODES; ++place) {
    for(i=0; i < NUM_ARCS; ++i) {
      if (head[i] == topoOrder[place] && !isInNodeArray(topoOrder, tail[i])) {
        topoOrder[queue] = tail[i];
        ++queue;
      }
    }
  }

  // init cost
  for(i = 0; i < NUM_ARCS; ++i) {
    cost[i] = FLOAT_MAX;
  }

  // init minimum paths
  for(i = 0; i < NUM_NODES; i++) {
    minCost[i] = FLOAT_MAX;
  }
  minCost[sinkNode-1] = 0;
  nextMinArc[sinkNode-1] = NUM_ARCS;
  for(i = 0; i < NUM_NODES; i++) {
    arc = pointer[topoOrder[i]-1]-1;
    while(head[arc] == topoOrder[i]) {
      costCand = fftt[arc] + minCost[head[arc]-1];
      if(costCand < minCost[tail[arc]-1]) {
        minCost[tail[arc]-1] = costCand;
        nextMinArc[tail[arc]-1] = arc;
      }
      ++arc;
    }
  }

  // init maximum paths
  for(i = 0; i < NUM_NODES; i++) {
    maxCost[i] = minCost[i];
  }

  // init flows on bush
  nextArc = NUM_ARCS;
  for(i = 0; i < NUM_NODES; i++) {
    nextArc = nextMinArc[i];
    while(nextArc < NUM_ARCS) {
      flow[nextArc] += demand[i];
      nextArc = nextMinArc[head[nextArc]-1];
    }
  }

  // init costs on bush
  for(arc = 0; arc < NUM_ARCS; ++arc) {
    if(minCost[head[arc]-1] < minCost[tail[arc]-1]) {
      cost[arc] = setCost(arc, fftt, flow, cap);
    }
  }

  updateCost(minCost, maxCost, cost, flow, sinkNode, pointer, tail, head, topoOrder, nextMinArc, nextMaxArc);
}

Again, the entire kernel may be found here: https://gist.github.com/dprentiss/10982016

4
  • CodeXL is quite buggy, my apps always crash on it, but they run OK without it. CodeXL expects a "normal" SDK configuration, which might not always be the case (dynamic library, etc..). nVIDIA has the same problems as well. For example their debugger use to crash on UserEvents.
    – DarkZeros
    Apr 17, 2014 at 13:34
  • Is it ever possible that head[nextArc] == 0? If so the last line in your loop has a problem...
    – twalberg
    Apr 17, 2014 at 14:05
  • I didn't see your code, but yes there are XL crashes in connection with VS, there are lot of fixes recently w.r.t VS. Use the recent one if you are using the old XL
    – Meluha
    Apr 18, 2014 at 4:27
  • Thanks for the suggestion @twalberg. I checked the possible values and head[nextArc] > 0 for all possible values of nextArc. If not, it would not compile anywhere. Apr 18, 2014 at 16:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Browse other questions tagged or ask your own question.