Skip to content

Commit

Permalink
general offload: Add a generic host offload application and add first…
Browse files Browse the repository at this point in the history
… snDNN gemm kernel setup
  • Loading branch information
GiannaP authored and colluca committed Aug 21, 2023
1 parent 864fb3c commit a06f8ce
Show file tree
Hide file tree
Showing 26 changed files with 2,754 additions and 23 deletions.
2 changes: 1 addition & 1 deletion target/sim/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -575,7 +575,7 @@ clean-work:
rm -rf work

clean-bender:
rm -rf Bender.lock .bender/ work/
rm -rf $(ROOT)/Bender.lock $(ROOT)/.bender/ $(ROOT)/deps

clean-logs:
rm -rf $(LOGS_DIR)/
Expand Down
7 changes: 5 additions & 2 deletions target/sim/sw/device/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
# Luca Colagrande <colluca@iis.ee.ethz.ch>

# Add user applications to APPS variable
APPS = offload
APPS = offload sndnn/gemm axpy

TARGET ?= all

Expand All @@ -22,5 +22,8 @@ runtime:
$(MAKE) -C $@ $(TARGET)

# Explicit dependency of apps on runtime
$(APP_SUBDIRS): runtime
$(APP_SUBDIRS): libraries/snDNN runtime
$(MAKE) -C $@ $(TARGET)

libraries/snDNN: runtime
$(MAKE) -C $@ $(TARGET)
28 changes: 28 additions & 0 deletions target/sim/sw/device/apps/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Copyright 2023 ETH Zurich and University of Bologna.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
#
# Luca Colagrande <colluca@iis.ee.ethz.ch>

SUBDIRS = offload
# SUBDIRS += gemm
SUBDIRS += axpy
# SUBDIRS += nop
# SUBDIRS += blas/axpy
# SUBDIRS += blas/gemm
# SUBDIRS += sndnn/batchnorm
# # SUBDIRS += sndnn/conv2d # fails with exit code 32
# SUBDIRS += sndnn/fusedconv
# SUBDIRS += sndnn/gelu
SUBDIRS += sndnn/gemm
# # SUBDIRS += sndnn/layernorm # throws illegal instruction in simulation
# SUBDIRS += sndnn/linear
# SUBDIRS += sndnn/maxpool
# # SUBDIRS += sndnn/softmax

.PHONY: all clean $(SUBDIRS)

all: $(SUBDIRS)

$(SUBDIRS):
$(MAKE) -C $@ $(TARGET)
42 changes: 36 additions & 6 deletions target/sim/sw/device/apps/common.mk
Original file line number Diff line number Diff line change
Expand Up @@ -4,18 +4,48 @@
#
# Luca Colagrande <colluca@iis.ee.ethz.ch>

include ../../toolchain.mk
# Usage of absolute paths is required to externally include
# this Makefile from multiple different locations
MK_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
include $(MK_DIR)/../toolchain.mk

###################
# Build variables #
###################

# Fixed paths in repository tree
ROOT = $(abspath $(MK_DIR)/../../../../..)
# Directories
BUILDDIR = $(abspath build)
APPSDIR = $(abspath ../)
RUNTIME_DIR = $(abspath ../../runtime)
APPSDIR = $(abspath $(MK_DIR)/)
# RUNTIME_DIR = $(abspath ../../runtime)
RUNTIME_DIR = $(abspath $(MK_DIR)/../runtime)
SNRT_DIR = $(shell bender path snitch_cluster)/sw/snRuntime
SW_DIR = $(abspath ../../../)
# SW_DIR = $(abspath ../../../)
SW_DIR = $(abspath $(MK_DIR)/../../)

#################
# SNDNN_LIBRARY #
#################
ifdef USE_SNDNN_LIBRARY
SNDNN_DIR := $(shell bender path snitch_cluster)/sw/snDNN
SNDNN_LIB_DIR := $(abspath $(MK_DIR)/../libraries/snDNN)
SNDNN_LIB_NAME = snDNN

# Dependencies
INCDIRS += $(SNDNN_LIB_DIR)/src
INCDIRS += $(SNDNN_DIR)/src
INCDIRS += $(SNDNN_DIR)/include
# Linker script
# RISCV_LDFLAGS += -L$(abspath $(SNDNN_LIB_DIR))
# Link snRuntime library
RISCV_LDFLAGS += -L$(abspath $(SNDNN_LIB_DIR)/build/)
RISCV_LDFLAGS += -l$(SNDNN_LIB_NAME)
BUILDDIR = $(abspath $(MK_DIR)/sndnn/$(APP)/build)
SNDNN_LIB = $(realpath $(SNDNN_LIB_DIR)/build/lib$(SNDNN_LIB_NAME).a)
LD_SRCS += $(SNDNN_LIB)
else
BUILDDIR = $(abspath $(MK_DIR)/$(APP)/build)
endif

# Dependencies
INCDIRS += $(RUNTIME_DIR)/src
Expand Down Expand Up @@ -83,7 +113,7 @@ $(DEP): $(SRCS) | $(BUILDDIR)
$(RISCV_CC) $(RISCV_CFLAGS) -MM -MT '$(ELF)' $< > $@

$(ELF): $(DEP) $(LD_SRCS) | $(BUILDDIR)
$(RISCV_CC) $(RISCV_CFLAGS) $(RISCV_LDFLAGS) $(SRCS) -o $@
$(RISCV_CC) $(RISCV_CFLAGS) $(SRCS) $(RISCV_LDFLAGS) -o $@

$(BIN): $(ELF) | $(BUILDDIR)
$(RISCV_OBJCOPY) $(OBJCOPY_FLAGS) $< $@
Expand Down
34 changes: 34 additions & 0 deletions target/sim/sw/device/apps/sndnn/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
# Copyright 2023 ETH Zurich and University of Bologna.
# Licensed under the Apache License, Version 2.0, see LICENSE for details.
# SPDX-License-Identifier: Apache-2.0
#
# Gianna Paulin <pauling@iis.ee.ethz.ch>

# Usage of absolute paths is required to externally include this Makefile
MK_DIR := $(dir $(realpath $(lastword $(MAKEFILE_LIST))))
DATA_DIR := $(realpath $(MK_DIR)/data)
SRC_DIR := $(realpath $(MK_DIR)/$(APP_NAME)/src)
SNDNN_DIR := $(shell bender path snitch_cluster)/sw/snDNN/)
SNDNN_LIB_DIR := $(realpath $(MK_DIR)/../../libraries/snDNN/)
# SNDNN_SRC_DIR := $(shell bender path snitch_cluster)/sw/snDNN/src)

INCLUDE_DIR = $(realpath $(SNDNN_DIR)/include)
INCLUDE_DIR += $(realpath $(SNDNN_DIR)/src)
INCLUDE_DIR += $(realpath $(SNDNN_LIB_DIR)/src)

DATA_CFG ?= $(DATA_DIR)/$(APP_NAME)_params.hjson

APP ?= $(APP_NAME)
SRCS += $(realpath $(SRC_DIR)/net_$(APP_NAME).c)
# SRCS += $(realpath $(SNDNN_LIB_DIR)/src/sndnn.c)
INCDIRS += $(DATA_DIR) $(SRC_DIR) $(INCLUDE_DIR)

$(DATA_DIR)/data_$(APP_NAME).h: $(MK_DIR)/datagen.py $(DATA_CFG)
$< -c $(DATA_CFG) > $@

.PHONY: clean-data clean

clean-data:
rm -f $(DATA_DIR)/data_$(APP_NAME).h

clean: clean-data
17 changes: 17 additions & 0 deletions target/sim/sw/device/apps/sndnn/data/gemm_params.hjson
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
// Copyright 2020 ETH Zurich and University of Bologna.
// Solderpad Hardware License, Version 0.51, see LICENSE for details.
// SPDX-License-Identifier: SHL-0.51

// Parameters for a GEMM

{
kernel: "GEMM"
M: 16,
N: 16,
K: 16,
alpha: 0,
transpose_A: false,
transpose_B: true,
prec: 32,
expand: 0
}
Loading

0 comments on commit a06f8ce

Please sign in to comment.