"Programming XC..:", Parallel Replication Example

Technical questions regarding the XTC tools and programming with XMOS.
FBergemann
Member
Posts: 8
Joined: Sun Aug 14, 2011 10:19 am

"Programming XC..:", Parallel Replication Example

Post by FBergemann »

Hi,
i wonder how it works to have all #4 cores operating on the same XS1_PORT_1A 1-bit port?
As it is incomplete in the document i used this one for tests:

Code: Select all

#include <stdio.h>
#include <platform.h>

port p[4] = {
	on stdcore [0] : XS1_PORT_1A,
	on stdcore [1] : XS1_PORT_1A,
	on stdcore [2] : XS1_PORT_1A,
	on stdcore [3] : XS1_PORT_1A
};

void node ( chanend input, chanend output, port p, int n)
{
	for (int i = 0; i<10; ++i) {
		int val;
		if (n == 0) {
			// source & drain of data
			val = i;
			output <: val;
			printf("%d: generate %d\n", n, val);
			input :> val;
			printf("%d: consume %d\n", n, val);
		}
		else {
			input :> val;
			// printf("%d: rcv %d\n", n, val);
			val = val*2;
			// printf("%d: snd %d\n", n, val);
			output <: val;
		}
	}
}

int main ( void ) {
	chan c [4];
	par ( int i=0; i <4; i ++) {
		on stdcore [i] : node(c[i], c[(i+1)%4], p[i], i);
	}
	return 0;
}
best regards,
Frank


User avatar
rp181
Respected Member
Posts: 395
Joined: Tue May 18, 2010 12:25 am

Post by rp181 »

Each core has that port. A core is exactly the same as the other, including physical pins. Therefore,

on stdcore[0] = port p = xxx;
on stdcore[1] = port p = xxx;

are 2 different HW pins.

i.e, the port names are respective to the core.
FBergemann
Member
Posts: 8
Joined: Sun Aug 14, 2011 10:19 am

Post by FBergemann »

- thanks.
Actually i could drop the ports, they are not used in my example :-)
So it's the channels itself, which serve for the connection between the cores.
Btw, what happens, if - for whatever reason - i use #2 channels for communication?
How is it mapped to the crossbar between the cores?

Code: Select all

#include <stdio.h>
#include <platform.h>

void node ( chanend input1, chanend output1, chanend input2, chanend output2, int n)
{
	for (int i = 0; i<10; ++i) {
		int val1;
		char val2;
		if (n == 0) {
			// source & drain of data
			val1 = i;
			printf("%d: generate %d\n", n, val1);
			output1 <: val1;

			val2 = 'a' + i;
			printf("%d: generate %c\n", i, val2);
			output2 <: val2;

			input1 :> val1;
			printf("%d: consume %d\n", n, val1);
			input2 :> val2;
			printf("%d: consume %c\n", n, val2);
		}
		else {
			input1 :> val1;
			// printf("%d: rcv %d\n", n, val);
			val1 = val1*2;
			// printf("%d: snd %d\n", n, val);
			output1 <: val1;

			input2 :> val2;
			val2 = val2 + 1;
			output2 <: val2;
		}
	}
}

int main ( void ) {
	chan c[8];
	par ( int i=0; i <4; i ++) {
		on stdcore [i] : node(c[i], c[(i+1)%4], c[i+4], c[((i+1)%4)+4], i);
	}
	return 0;
}
rgds,
Frank
User avatar
rp181
Respected Member
Posts: 395
Joined: Tue May 18, 2010 12:25 am

Post by rp181 »

Someone correct my if I'm wrong...

As far as I understand it, normal channels are created and destroyed when you use them. So, in your example with 2 nodes, there will only be 1 channel max at a given time. If you used streaming channels, the channels would stay open. I don't understand what you mean by crossbar. If you are on the G4 processor, then you can only have 3 streaming channels, as 4 channels can be open at a time (again, not 100% sure).
MaxFlashrom
Experienced Member
Posts: 82
Joined: Fri Nov 05, 2010 2:59 pm

Post by MaxFlashrom »

A channel connection is established between two channel ends. When you write "chan c" in XC it actually allocates a pair of joined channel ends. When you call functions in a par or on different cores, passing a shared chan to the respective chanend parameter on each function, what actually happens is that each function is given one of the two chanends that was allocated by the chan declaration. Chanends are allocated locally on each core. Each chanend ID is labelled with its core ID and has a destination chanend bound to it. If this destination chanend has a different core ID to the source chanend then a route is established via the processor switch to another core, possibly via an XLink when an out is performed to the chanend. When an END token is sent over the channel, the resources enabling the route in the switch are freed.

You can read about this in the XS1 System specification and the XS1 Architecture documents.
Max.