-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Matthew Naylor
committed
Sep 2, 2018
1 parent
515642b
commit 3ee03f5
Showing
15 changed files
with
327 additions
and
4 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
File renamed without changes.
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#include <tinsel.h> | ||
#include <io.h> | ||
|
||
// Each thread sends a message to N random neighbours | ||
#define N 10 | ||
|
||
// Address construction | ||
uint32_t toAddr(uint32_t meshX, uint32_t meshY, | ||
uint32_t coreId, uint32_t threadId) | ||
{ | ||
uint32_t addr; | ||
addr = meshY; | ||
addr = (addr << TinselMeshXBits) | meshX; | ||
addr = (addr << TinselLogCoresPerBoard) | coreId; | ||
addr = (addr << TinselLogThreadsPerCore) | threadId; | ||
return addr; | ||
} | ||
|
||
// Address deconstruction | ||
void fromAddr(uint32_t addr, uint32_t* meshX, uint32_t* meshY, | ||
uint32_t* coreId, uint32_t* threadId) | ||
{ | ||
*threadId = addr & ((1 << TinselLogThreadsPerCore) - 1); | ||
addr >>= TinselLogThreadsPerCore; | ||
|
||
*coreId = addr & ((1 << TinselLogCoresPerBoard) - 1); | ||
addr >>= TinselLogCoresPerBoard; | ||
|
||
*meshX = addr & ((1 << TinselMeshXBits) - 1); | ||
addr >>= TinselMeshXBits; | ||
|
||
*meshY = addr; | ||
} | ||
|
||
uint32_t min(uint32_t a, uint32_t b) | ||
{ return a < b ? a : b; } | ||
|
||
// Psuedo random address | ||
uint32_t randAddr(uint32_t* state) | ||
{ | ||
*state = *state * 1103515245 + 12345; | ||
uint32_t mask = (1 << (TinselMeshXBits + TinselMeshYBits + | ||
TinselLogThreadsPerBoard)) - 1; | ||
uint32_t addr = *state & mask; | ||
|
||
uint32_t x, y, c, t; | ||
fromAddr(addr, &x, &y, &c, &t); | ||
return toAddr(min(x, TinselMeshXLen-1), | ||
min(y, TinselMeshYLen-1), c, t); | ||
} | ||
|
||
int main() | ||
{ | ||
// Get thread id | ||
uint32_t me = tinselId(); | ||
|
||
// Get host id | ||
uint32_t host = tinselHostId(); | ||
|
||
// Get pointers to mailbox message slots | ||
volatile int* msgOut = tinselSlot(0); | ||
volatile int* msgIn = tinselSlot(1); | ||
|
||
// Intiialise send slot | ||
msgOut[0] = me; | ||
|
||
// Allocate receive slot | ||
tinselAlloc(msgIn); | ||
|
||
// Set number of flits per message | ||
tinselSetLen(3); | ||
|
||
// Determine random neighbours | ||
uint32_t seed = me; | ||
uint32_t neighbours[N]; | ||
for (uint32_t i = 0; i < N; i++) | ||
neighbours[i] = randAddr(&seed); | ||
|
||
// Track number of messages sent & received | ||
uint32_t sent = 0; | ||
uint32_t received = 0; | ||
|
||
// Send messages | ||
while (1) { | ||
if (tinselCanSend()) { | ||
if (sent == N) { | ||
// Tell host we're done | ||
tinselSetLen(0); | ||
tinselSend(host, msgOut); | ||
sent++; | ||
} | ||
else if (sent < N) { | ||
tinselSend(neighbours[sent], msgOut); | ||
sent++; | ||
} | ||
} | ||
if (tinselCanRecv()) { | ||
tinselAlloc(tinselRecv()); | ||
received++; | ||
} | ||
} | ||
|
||
|
||
return 0; | ||
} |
File renamed without changes.
File renamed without changes.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
# Tinsel root | ||
TINSEL_ROOT=../.. | ||
|
||
ifndef QUARTUS_ROOTDIR | ||
$(error Please set QUARTUS_ROOTDIR) | ||
endif | ||
|
||
include $(TINSEL_ROOT)/globals.mk | ||
|
||
# RISC-V compiler flags | ||
CFLAGS = $(RV_CFLAGS) -O2 -I $(INC) | ||
LDFLAGS = -melf32lriscv -G 0 | ||
|
||
.PHONY: all | ||
all: code.v data.v run | ||
|
||
code.v: flood.elf | ||
checkelf.sh flood.elf | ||
$(RV_OBJCOPY) -O verilog --only-section=.text flood.elf code.v | ||
|
||
data.v: flood.elf | ||
$(RV_OBJCOPY) -O verilog --remove-section=.text \ | ||
--set-section-flags .bss=alloc,load,contents flood.elf data.v | ||
|
||
flood.elf: flood.c link.ld $(INC)/config.h $(INC)/tinsel.h entry.o | ||
$(RV_CC) $(CFLAGS) -Wall -c -o flood.o flood.c | ||
$(RV_LD) $(LDFLAGS) -T link.ld -o flood.elf entry.o flood.o | ||
|
||
entry.o: | ||
$(RV_CC) $(CFLAGS) -Wall -c -o entry.o entry.S | ||
|
||
link.ld: genld.sh | ||
./genld.sh > link.ld | ||
|
||
$(INC)/config.h: $(TINSEL_ROOT)/config.py | ||
make -C $(INC) | ||
|
||
$(HL)/%.o: | ||
make -C $(HL) | ||
|
||
run: run.cpp $(HL)/*.o | ||
g++ -O2 -I $(INC) -I $(HL) -o run run.cpp $(HL)/*.o \ | ||
-ljtag_atlantic -ljtag_client -L $(QUARTUS_ROOTDIR)/linux64/ \ | ||
-Wl,-rpath,$(QUARTUS_ROOTDIR)/linux64 | ||
|
||
sim: run.cpp $(HL)/sim/*.o | ||
g++ -O2 -I $(INC) -I $(HL) -o sim run.cpp $(HL)/sim/*.o | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -f *.o *.elf link.ld *.v run sim |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
# We assume the boot loader has already setup the stack. | ||
# All we need to do is jump to main. | ||
j main |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,105 @@ | ||
#include <tinsel.h> | ||
#include <io.h> | ||
|
||
// Each thread sends a message to N random neighbours | ||
#define N 10 | ||
|
||
// Address construction | ||
uint32_t toAddr(uint32_t meshX, uint32_t meshY, | ||
uint32_t coreId, uint32_t threadId) | ||
{ | ||
uint32_t addr; | ||
addr = meshY; | ||
addr = (addr << TinselMeshXBits) | meshX; | ||
addr = (addr << TinselLogCoresPerBoard) | coreId; | ||
addr = (addr << TinselLogThreadsPerCore) | threadId; | ||
return addr; | ||
} | ||
|
||
// Address deconstruction | ||
void fromAddr(uint32_t addr, uint32_t* meshX, uint32_t* meshY, | ||
uint32_t* coreId, uint32_t* threadId) | ||
{ | ||
*threadId = addr & ((1 << TinselLogThreadsPerCore) - 1); | ||
addr >>= TinselLogThreadsPerCore; | ||
|
||
*coreId = addr & ((1 << TinselLogCoresPerBoard) - 1); | ||
addr >>= TinselLogCoresPerBoard; | ||
|
||
*meshX = addr & ((1 << TinselMeshXBits) - 1); | ||
addr >>= TinselMeshXBits; | ||
|
||
*meshY = addr; | ||
} | ||
|
||
uint32_t min(uint32_t a, uint32_t b) | ||
{ return a < b ? a : b; } | ||
|
||
// Psuedo random address | ||
uint32_t randAddr(uint32_t* state) | ||
{ | ||
*state = *state * 1103515245 + 12345; | ||
uint32_t mask = (1 << (TinselMeshXBits + TinselMeshYBits + | ||
TinselLogThreadsPerBoard)) - 1; | ||
uint32_t addr = *state & mask; | ||
|
||
uint32_t x, y, c, t; | ||
fromAddr(addr, &x, &y, &c, &t); | ||
return toAddr(min(x, TinselMeshXLen-1), | ||
min(y, TinselMeshYLen-1), c, t); | ||
} | ||
|
||
int main() | ||
{ | ||
// Get thread id | ||
uint32_t me = tinselId(); | ||
|
||
// Get host id | ||
uint32_t host = tinselHostId(); | ||
|
||
// Get pointers to mailbox message slots | ||
volatile int* msgOut = tinselSlot(0); | ||
volatile int* msgIn = tinselSlot(1); | ||
|
||
// Intiialise send slot | ||
msgOut[0] = me; | ||
|
||
// Allocate receive slot | ||
tinselAlloc(msgIn); | ||
|
||
// Set number of flits per message | ||
tinselSetLen(3); | ||
|
||
// Determine random neighbours | ||
uint32_t seed = me; | ||
uint32_t neighbours[N]; | ||
for (uint32_t i = 0; i < N; i++) | ||
neighbours[i] = randAddr(&seed); | ||
|
||
// Track number of messages sent & received | ||
uint32_t sent = 0; | ||
uint32_t received = 0; | ||
|
||
// Send messages | ||
while (1) { | ||
if (tinselCanSend()) { | ||
if (sent == N) { | ||
// Tell host we're done | ||
tinselSetLen(0); | ||
tinselSend(host, msgOut); | ||
sent++; | ||
} | ||
else if (sent < N) { | ||
tinselSend(neighbours[sent], msgOut); | ||
sent++; | ||
} | ||
} | ||
if (tinselCanRecv()) { | ||
tinselAlloc(tinselRecv()); | ||
received++; | ||
} | ||
} | ||
|
||
|
||
return 0; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
#!/bin/bash | ||
|
||
# Load config parameters | ||
while read -r EXPORT; do | ||
eval $EXPORT | ||
done <<< `python ../../config.py envs` | ||
# Compute space available for instructions | ||
MaxInstrBytes=$((4 * 2**$LogInstrsPerCore - $MaxBootImageBytes)) | ||
cat - << EOF | ||
/* THIS FILE HAS BEEN GENERATED AUTOMATICALLY. */ | ||
/* DO NOT MODIFY. INSTEAD, MODIFY THE genld.sh SCRIPT. */ | ||
OUTPUT_ARCH( "riscv" ) | ||
MEMORY | ||
{ | ||
instrs : ORIGIN = $MaxBootImageBytes, LENGTH = $MaxInstrBytes | ||
globals : ORIGIN = $DRAMBase, LENGTH = $DRAMGlobalsLength | ||
} | ||
SECTIONS | ||
{ | ||
.text : { *.o(.text*) } > instrs | ||
.bss : { *.o(.bss*) } > globals = 0 | ||
.rodata : { *.o(.rodata*) } > globals | ||
.sdata : { *.o(.sdata*) } > globals | ||
.data : { *.o(.data*) } > globals | ||
__heapBase = ALIGN(.); | ||
} | ||
EOF |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
#include <HostLink.h> | ||
|
||
int main() | ||
{ | ||
HostLink hostLink; | ||
|
||
printf("Booting\n"); | ||
hostLink.boot("code.v", "data.v"); | ||
|
||
printf("Starting\n"); | ||
hostLink.go(); | ||
|
||
uint32_t totalThreads = | ||
TinselMeshXLen * TinselMeshYLen * TinselThreadsPerBoard; | ||
|
||
printf("Waiting for responses from %d threads\n", totalThreads); | ||
uint32_t resp[4]; | ||
for (int i = 0; i < totalThreads; i++) { | ||
hostLink.recv(resp); | ||
printf("Received response from %d\n", resp[0]); | ||
} | ||
|
||
printf("Test passed, all threads finished\n"); | ||
|
||
return 0; | ||
} |