Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Salvatore committed Apr 13, 2021
0 parents commit e230c61
Show file tree
Hide file tree
Showing 682 changed files with 194,410 additions and 0 deletions.
13 changes: 13 additions & 0 deletions examples/aggregate/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
SPIN_APP_NAME = aggregate_global
SPIN_APP_SRCS = aggregate_global.c
SPIN_CFLAGS = -O3 -g
SPIN_LDFLAGS = -lm
NUM_PACKETS ?=512
HAS_HH=0
HAS_TH=1
FULL_PKT=1
PKT_SIZE ?= 1024
PKT_DELAY=0

include $(PSPIN_RT)/spin-handlers.mk

69 changes: 69 additions & 0 deletions examples/aggregate/handlers/aggregate_global.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
#ifndef HOST
#include <handler.h>
#else
#include <handler_profiler.h>
#endif

#include <packets.h>

#define MAX_CLUSTERS 4
#define MAX_HPUS 32
#define STRIDE 1
#define OFFSET 0
#define NUM_INT_OP 0

//#define USE_AMO

// Handler that implements data race free aggregation for int32
volatile __attribute__((section(".l2_handler_data"))) uint8_t handler_mem[] = {0xde, 0xad, 0xbe, 0xef};

__handler__ void aggregate_global_hh(handler_args_t *args)
{
}
__handler__ void aggregate_global_ph(handler_args_t *args)
{

task_t* task = args->task;
uint32_t *scratchpad = (uint32_t *)task->scratchpad;

uint8_t *pkt_pld_ptr;
uint32_t pkt_pld_len;
GET_IP_UDP_PLD(task->pkt_mem, pkt_pld_ptr, pkt_pld_len);

uint32_t *nic_pld_addr = (uint32_t*) pkt_pld_ptr;

uint32_t aggregator=0;
for(uint32_t i=0;i<pkt_pld_len/4;i++)
{
aggregator+=nic_pld_addr[i*STRIDE+OFFSET];
}

uint32_t my_cluster_id = args->cluster_id;
amo_add(&(scratchpad[my_cluster_id]), aggregator);
}

__handler__ void aggregate_global_th(handler_args_t *args)
{
task_t* task = args->task;
uint32_t *scratchpad=(uint32_t*) task->scratchpad;
uint32_t result=0;
for(uint8_t i=0;i<MAX_CLUSTERS;i++){
result+=scratchpad[i];
}
//printf("final result %u\n",result);
uint64_t host_address = task->host_mem_high;
host_address = (host_address << 32) | (task->host_mem_low);

spin_host_write(host_address, (uint64_t) result, false);
}


void init_handlers(handler_fn * hh, handler_fn *ph, handler_fn *th, void **handler_mem_ptr)
{
volatile handler_fn handlers[] = {aggregate_global_hh, aggregate_global_ph, aggregate_global_th};
*hh = handlers[0];
*ph = handlers[1];
*th = handlers[2];

*handler_mem_ptr = (void*) handler_mem;
}
13 changes: 13 additions & 0 deletions examples/copy_from_host/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
SPIN_APP_NAME = copy_from_host
SPIN_APP_SRCS = copy_from_host.c
SPIN_CFLAGS = -O3 -g -flto
SPIN_LDFLAGS = -lm
NUM_PACKETS ?= 512
PKT_DELAY ?= 0
MSG_DELAY ?= 0
HAS_HH ?= 0
HAS_TH ?= 0
FULL_PKT ?= 1

include $(PSPIN_RT)/spin-handlers.mk

58 changes: 58 additions & 0 deletions examples/copy_from_host/handlers/copy_from_host.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
#ifndef HOST
#include <handler.h>
#include <packets.h>
#include <spin_dma.h>
#else
#include <handler_profiler.h>
#endif

#if !defined(TO_L2) && !defined(TO_L1)
#define TO_L1
#endif

volatile __attribute__((section(".l2_handler_data"))) uint8_t handler_mem[] = {0xde, 0xad, 0xbe, 0xef};


__handler__ void copy_from_host_hh(handler_args_t *args) {;}
__handler__ void copy_from_host_ph(handler_args_t *args)
{
task_t* task = args->task;
ip_hdr_t *ip_hdr = (ip_hdr_t*) (task->pkt_mem);
#ifndef TO_L1
uint8_t *nic_pld_addr = ((uint8_t*) (task->l2_pkt_mem));
#else
uint8_t *nic_pld_addr = ((uint8_t*) (task->pkt_mem));
#endif
uint16_t pkt_pld_len = ip_hdr->length;
udp_hdr_t *udp_hdr = (udp_hdr_t*) (((uint8_t*) (task->pkt_mem)) + ip_hdr->ihl * 4);

uint32_t src_id = ip_hdr->source_id;
ip_hdr->source_id = ip_hdr->dest_id;
ip_hdr->dest_id = src_id;

uint16_t src_port = udp_hdr->src_port;
udp_hdr->src_port = udp_hdr->dst_port;
udp_hdr->dst_port = src_port;

spin_cmd_t dma;

uint64_t host_address = task->host_mem_high;
host_address = (host_address << 32) | (task->host_mem_low);
spin_dma_from_host(host_address, (uint32_t) nic_pld_addr, pkt_pld_len, 1, &dma);

spin_cmd_wait(dma);

spin_cmd_t send;
spin_send_packet(nic_pld_addr, pkt_pld_len, &send);
}
__handler__ void copy_from_host_th(handler_args_t *args){;}

void init_handlers(handler_fn * hh, handler_fn *ph, handler_fn *th, void **handler_mem_ptr)
{
volatile handler_fn handlers[] = {copy_from_host_hh, copy_from_host_ph, copy_from_host_th};
*hh = handlers[0];
*ph = handlers[1];
*th = handlers[2];

*handler_mem_ptr = (void*) handler_mem;
}
13 changes: 13 additions & 0 deletions examples/copy_to_host/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
SPIN_APP_NAME = copy_to_host
SPIN_APP_SRCS = copy_to_host.c
SPIN_CFLAGS = -O3 -g -flto
SPIN_LDFLAGS = -lm
NUM_PACKETS ?= 512
PKT_DELAY ?= 0
MSG_DELAY ?= 0
HAS_HH ?= 0
HAS_TH ?= 0
FULL_PKT ?= 1

include $(PSPIN_RT)/spin-handlers.mk

56 changes: 56 additions & 0 deletions examples/copy_to_host/handlers/copy_to_host.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
#ifndef HOST
#include <handler.h>
#include <packets.h>
#include <spin_dma.h>
#else
#include <handler_profiler.h>
#endif

#if !defined(FROM_L2) && !defined(FROM_L1)
#define FROM_L1
#endif

volatile __attribute__((section(".l2_handler_data"))) uint8_t handler_mem[] = {0xde, 0xad, 0xbe, 0xef};


__handler__ void copy_to_host_hh(handler_args_t *args) {;}
__handler__ void copy_to_host_ph(handler_args_t *args)
{
task_t* task = args->task;
ip_hdr_t *ip_hdr = (ip_hdr_t*) (task->pkt_mem);
#ifdef FROM_L2
uint8_t *nic_pld_addr = ((uint8_t*) (task->l2_pkt_mem));
#else
uint8_t *nic_pld_addr = ((uint8_t*) (task->pkt_mem));
#endif
uint16_t pkt_pld_len = ip_hdr->length;

spin_cmd_t dma;

uint64_t host_address = task->host_mem_high;
host_address = (host_address << 32) | (task->host_mem_low);
spin_dma_to_host(host_address, (uint32_t) nic_pld_addr, pkt_pld_len, 1, &dma);

//It's not strictly necessary to wait. The hw will enforce that the feedback is not
//sent until all commands issued by this handlers are completed.
#ifdef WAIT_POLL
bool completed = false;
do {
spin_cmd_test(dma, &completed);
} while (!completed);
#elif defined(WAIT_SUSPEND)
spin_cmd_wait(dma);
#endif

}
__handler__ void copy_to_host_th(handler_args_t *args){;}

void init_handlers(handler_fn * hh, handler_fn *ph, handler_fn *th, void **handler_mem_ptr)
{
volatile handler_fn handlers[] = {copy_to_host_hh, copy_to_host_ph, copy_to_host_th};
*hh = handlers[0];
*ph = handlers[1];
*th = handlers[2];

*handler_mem_ptr = (void*) handler_mem;
}
11 changes: 11 additions & 0 deletions examples/empty/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
SPIN_APP_NAME = empty
SPIN_APP_SRCS = empty.c
SPIN_CFLAGS = -O3 -g ${DEFINITIONS}
SPIN_LDFLAGS = -lm -flto
NUM_PACKETS ?= 512
PKT_DELAY ?= 0
MSG_DELAY ?= 0


include $(PSPIN_RT)/spin-handlers.mk

40 changes: 40 additions & 0 deletions examples/empty/handlers/empty.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@

#ifndef HOST
#include <handler.h>
#include <packets.h>
#include <spin_dma.h>
#else
#include <handler_profiler.h>
#endif

#ifndef NUM_INT_OP
#define NUM_INT_OP 0
#endif

volatile __attribute__((section(".l2_handler_data"))) uint8_t handler_mem[] = {0xde, 0xad, 0xbe, 0xef};

__handler__ void empty_hh(handler_args_t *args) {;}
__handler__ void empty_ph(handler_args_t *args)
{
//printf("Payload handler!\n");
#if (NUM_INT_OP > 0)
volatile int xx = 0;
int x = xx;
for (int i=0; i<NUM_INT_OP; i++) {
x = x*i;
}
xx = x;
#endif
}
__handler__ void empty_th(handler_args_t *args){;}

void init_handlers(handler_fn * hh, handler_fn *ph, handler_fn *th, void **handler_mem_ptr)
{
volatile handler_fn handlers[] = {empty_hh, empty_ph, empty_th};
*hh = handlers[0];
*ph = handlers[1];
*th = handlers[2];

*handler_mem_ptr = (void*) handler_mem;
}

15 changes: 15 additions & 0 deletions examples/filtering/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
SPIN_APP_NAME = filtering
SPIN_APP_SRCS = filtering.c
SPIN_CFLAGS = -O3 -g
SPIN_LDFLAGS = -lm
NUM_PACKETS ?=512
MSG_COUNT ?= 1
HAS_HH=0
HAS_TH=0
FULL_PKT=0
PKT_SIZE ?=1024
PKT_DELAY ?= 0
MSG_DELAY ?= 0

include $(PSPIN_RT)/spin-handlers.mk

Loading

0 comments on commit e230c61

Please sign in to comment.