Skip to content

Commit

Permalink
Update makefiles for Ubuntu 18.04
Browse files Browse the repository at this point in the history
  • Loading branch information
Matthew Naylor committed Sep 2, 2018
1 parent 515642b commit 3ee03f5
Show file tree
Hide file tree
Showing 15 changed files with 327 additions and 4 deletions.
3 changes: 2 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,8 @@ clean:
make -C apps/ping clean
make -C apps/ring clean
make -C apps/ring/general clean
make -C apps/flood clean
make -C apps/flood1 clean
make -C apps/flood2 clean
make -C apps/benchmarks clean
make -C apps/linktest clean
make -C apps/multiprog clean
Expand Down
2 changes: 1 addition & 1 deletion apps/POLite/asp/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ $(HL)/%.o:
make -C $(HL)

run: Run.cpp $(HL)/*.o
g++ -O2 -I $(INC) -I $(HL) -o run Run.cpp $(HL)/*.o \
g++ -O2 -std=c++98 -I $(INC) -I $(HL) -o run Run.cpp $(HL)/*.o \
-ljtag_atlantic -ljtag_client -L $(QUARTUS_ROOTDIR)/linux64/ \
-Wl,-rpath,$(QUARTUS_ROOTDIR)/linux64 -lmetis

Expand Down
2 changes: 1 addition & 1 deletion apps/POLite/heat/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ $(HL)/%.o:
make -C $(HL)

run: Run.cpp Colours.cpp $(HL)/*.o
g++ -O2 -I $(INC) -I $(HL) -o run Run.cpp Colours.cpp $(HL)/*.o \
g++ -O2 -std=c++98 -I $(INC) -I $(HL) -o run Run.cpp Colours.cpp $(HL)/*.o \
-ljtag_atlantic -ljtag_client -L $(QUARTUS_ROOTDIR)/linux64/ \
-Wl,-rpath,$(QUARTUS_ROOTDIR)/linux64 -lmetis

Expand Down
2 changes: 1 addition & 1 deletion apps/POLite/ring/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ $(HL)/%.o:
make -C $(HL)

run: Run.cpp $(HL)/*.o
g++ -O2 -I $(INC) -I $(HL) -o run Run.cpp $(HL)/*.o \
g++ -std=c++98 -O2 -I $(INC) -I $(HL) -o run Run.cpp $(HL)/*.o \
-ljtag_atlantic -ljtag_client -L $(QUARTUS_ROOTDIR)/linux64/ \
-Wl,-rpath,$(QUARTUS_ROOTDIR)/linux64 -lmetis

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
105 changes: 105 additions & 0 deletions apps/flood1/flood2.c
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.
51 changes: 51 additions & 0 deletions apps/flood2/Makefile
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
3 changes: 3 additions & 0 deletions apps/flood2/entry.S
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
105 changes: 105 additions & 0 deletions apps/flood2/flood.c
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;
}
32 changes: 32 additions & 0 deletions apps/flood2/genld.sh
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
26 changes: 26 additions & 0 deletions apps/flood2/run.cpp
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;
}

0 comments on commit 3ee03f5

Please sign in to comment.