Potential Interfaces Bug

Technical questions regarding the XTC tools and programming with XMOS.
User avatar
XenoPhoenix
Member
Posts: 13
Joined: Tue Mar 29, 2011 5:13 pm

Potential Interfaces Bug

Post by XenoPhoenix »

I've recently been playing around with the new interfaces added in the v13 tools release, and I really like them however I think I may have come across a bug with initialising and arrays of interfaces.

The following quick test code uses a querying thread and an array of interfaces to communicated with individual threads to query their local tile id.

Code: Select all

#include <xs1.h>
#include <print.h>
#include <platform.h>

#define NUM_CORES 3

interface IdQuery {
  int GetCoreId();
};

void CoreIdentifier(interface IdQuery server sv) {
  while (1) {
    select {
      case sv.GetCoreId() -> int coreId:
        coreId = get_local_tile_id();
      break;
    }
  }
}

void CoreQuerier(interface IdQuery client cl[nThreads], unsigned int nThreads) {
  for(int i = 0; i < nThreads; ++ i) {
    // [BREAKPOINT HERE]
    printintln(cl[nThreads].GetCoreId());
  }
}

int main() {
  interface IdQuery test[NUM_CORES];

  par {
    on tile[0]: CoreQuerier(test, NUM_CORES);

    par (int i = 0; i < NUM_CORES; ++i) {
      on tile[i]: CoreIdentifier(test[i]);
    }
  }

  return 0;
}
Now when debugging this code with a breakpoint placed when there "// [BREAKPOINT HERE]" comment is, I get the following inspection on the "cl" array of interfaces variable:

Image

It clearly shows that although I have declared and array of 3 interfaces, that the third element is simple the same as the second (indeed if you make the array larger, all elements past the second are equal to the second).

This is simply a small compact example, but this is currently blocking what I am working on (and I'd rather not re-write it all with channels, interfaces are rather nice). I may well have done something stupid but if I have it's not immediately apparent to me and I'd be very grateful if someone could have a look and confirm if this is a bug or something else.


User avatar
segher
XCore Expert
Posts: 844
Joined: Sun Jul 11, 2010 1:31 am

Post by segher »

You're accessing cl[nThreads] instead of cl; did the
compiler not warn about that?
User avatar
XenoPhoenix
Member
Posts: 13
Joined: Tue Mar 29, 2011 5:13 pm

Post by XenoPhoenix »

segher wrote:You're accessing cl[nThreads] instead of cl; did the
compiler not warn about that?


You're completely correct, and no the compiler didn't warn about this.
I doesn't affect the behaviour of this (potential) bug however, with that correction it now just shows the erroneous behaviour with the output rather than just the debugger :).
User avatar
davelacey
Experienced Member
Posts: 104
Joined: Fri Dec 11, 2009 8:29 pm

Post by davelacey »

Hi,
I can confirm this is a compiler bug. It affects the initialization of arrays of client interface ends that span multiple tiles. I have raised an internal ticket on this and we will fix it for the next bugfix release of the tools.

In the meantime, the only workaround I can think of is to use individual interface variables instead of an arrays (admittedly this is going to be clunky). You only need to do this for arrays of *client* interface ends, arrays of *server* interface ends are unaffected - as are arrays of client ends connected to the same tile.

Dave
User avatar
XenoPhoenix
Member
Posts: 13
Joined: Tue Mar 29, 2011 5:13 pm

Post by XenoPhoenix »

Hi Dave,

Thanks for confirming that for me. I have reverted to a channel based implementation for now as it was a fairly simple interface in this case and it involved less clunk than using invidual interface variables as you suggested. I'll revert back to the cleaner interface based solution when this bug has been fixed.
User avatar
davelacey
Experienced Member
Posts: 104
Joined: Fri Dec 11, 2009 8:29 pm

Post by davelacey »

This bug is now fixed in 13.0.2.

Dave
User avatar
XenoPhoenix
Member
Posts: 13
Joined: Tue Mar 29, 2011 5:13 pm

Post by XenoPhoenix »

Thanks for that Dave,

I'll have a play in the coming week and convert my code back to using interfaces.