forked from pulp-platform/snitch_cluster
-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
re-add lib files for streamer-gemm and streamer-gemm-add-c (#281)
- Loading branch information
1 parent
30c4732
commit fafec39
Showing
6 changed files
with
434 additions
and
0 deletions.
There are no files selected for viewing
78 changes: 78 additions & 0 deletions
78
target/snitch_cluster/sw/snax/streamer-gemm-add-c/Makefile
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,78 @@ | ||
# Copyright 2023 KU Leuven. | ||
# Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# Xiaoling Yi <[email protected]> | ||
|
||
# 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 | ||
|
||
# Banshee runtime is not supported | ||
ifeq ($(SELECT_RUNTIME), rtl-generic) | ||
RUNTIME_DIR := rtl-generic | ||
else | ||
RUNTIME_DIR := rtl | ||
endif | ||
|
||
################ | ||
## Directories # | ||
################ | ||
|
||
# Fixed paths in repository tree | ||
ROOT = $(abspath $(MK_DIR)/../../../../..) | ||
SNRT_DIR = $(ROOT)/sw/snRuntime | ||
## Paths relative to the runtime including this Makefile | ||
BUILDDIR = $(abspath build) | ||
SRC_DIR = $(abspath src) | ||
|
||
#################### | ||
## Build variables # | ||
#################### | ||
|
||
INCDIRS += $(abspath include) | ||
INCDIRS += $(SNRT_DIR)/src | ||
INCDIRS += $(SNRT_DIR)/api | ||
INCDIRS += $(SNRT_DIR)/src/omp | ||
INCDIRS += $(SNRT_DIR)/api/omp | ||
INCDIRS += $(SNRT_DIR)/vendor/riscv-opcodes | ||
INCDIRS += $(ROOT)/target/snitch_cluster/sw/runtime/common | ||
|
||
# math.h needed by snRuntime | ||
|
||
INCDIRS += $(SNRT_DIR)/../math/arch/riscv64/ | ||
INCDIRS += $(SNRT_DIR)/../math/arch/generic | ||
INCDIRS += $(SNRT_DIR)/../math/src/include | ||
INCDIRS += $(SNRT_DIR)/../math/src/internal | ||
INCDIRS += $(SNRT_DIR)/../math/include/bits | ||
INCDIRS += $(SNRT_DIR)/../math/include | ||
|
||
INCDIRS += $(ROOT)/target/snitch_cluster/sw/runtime/$(RUNTIME_DIR)/src | ||
INCDIRS += $(ROOT)/target/snitch_cluster/sw/runtime/$(RUNTIME_DIR)/include | ||
|
||
############ | ||
## Outputs # | ||
############ | ||
|
||
OBJS = $(BUILDDIR)/snax-streamer-gemm-add-c-lib.o | ||
ALL_OUTPUTS = $(OBJS) | ||
|
||
|
||
########## | ||
## Rules # | ||
########## | ||
|
||
.PHONY: all | ||
all: $(ALL_OUTPUTS) | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -rf $(BUILDDIR) | ||
|
||
$(BUILDDIR): | ||
mkdir -p $@ | ||
|
||
$(BUILDDIR)/%.o: $(SRC_DIR)/%.c | $(BUILDDIR) | ||
$(RISCV_CC) $(RISCV_CFLAGS) -c $< -o $@ |
38 changes: 38 additions & 0 deletions
38
target/snitch_cluster/sw/snax/streamer-gemm-add-c/include/snax-streamer-gemm-add-c-lib.h
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,38 @@ | ||
// Copyright 2023 KU Leuven. | ||
// Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Xiaoling Yi <[email protected]> | ||
|
||
#include <stdbool.h> | ||
#include "snrt.h" | ||
#include "stdint.h" | ||
|
||
#pragma once | ||
|
||
// Set STREAMER configuration CSR | ||
void set_streamer_csr(int tempLoop0, int tempLoop1, int tempLoop2, | ||
int tempStride0A, int tempStride2A, int spatialStride1A, | ||
int tempStride0B, int tempStride1B, int spatialStride1B, | ||
int tempStride1C, int tempStride2C, int spatialStride1C, | ||
int delta_local_a, int delta_local_b, int delta_local_c, | ||
int delta_local_d); | ||
|
||
// Set CSR to start STREAMER | ||
void set_streamer_start(); | ||
|
||
// Set GEMM configuration CSR | ||
void set_block_gemm_csr(int tempLoop0, int tempLoop1, int tempLoop2, | ||
int subtractions); | ||
|
||
// Set CSR to start GEMM | ||
void set_block_gemm_start(); | ||
|
||
// Poll until Streamer and GEMM accelerator finish | ||
void wait_streamer_gemm(); | ||
|
||
// Read perforamcne counter of the Streamer, a read-only CSR | ||
uint32_t read_gemm_streamer_perf_counter(); | ||
|
||
// Read perforamcne counter of GEMM, a read-only CSR | ||
uint32_t read_gemm_perf_counter(); |
104 changes: 104 additions & 0 deletions
104
target/snitch_cluster/sw/snax/streamer-gemm-add-c/src/snax-streamer-gemm-add-c-lib.c
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,104 @@ | ||
// Copyright 2023 KU Leuven. | ||
// Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Xiaoling Yi <[email protected]> | ||
|
||
#include "snax-streamer-gemm-add-c-lib.h" | ||
|
||
// Set STREAMER configuration CSR | ||
void set_streamer_csr(int tempLoop0, int tempLoop1, int tempLoop2, | ||
int tempStride0A, int tempStride2A, int spatialStride1A, | ||
int tempStride0B, int tempStride1B, int spatialStride1B, | ||
int tempStride1C, int tempStride2C, int spatialStride1C, | ||
int delta_local_a, int delta_local_b, int delta_local_c, | ||
int delta_local_d) { | ||
// loop bounds, from innermost to outermost, from K to N to M | ||
write_csr(960, tempLoop0); | ||
write_csr(961, tempLoop1); | ||
write_csr(962, tempLoop2); | ||
|
||
// temporal strides for A | ||
write_csr(963, tempStride0A); | ||
write_csr(964, 0); | ||
write_csr(965, tempStride2A); | ||
|
||
// temporal strides for B | ||
write_csr(966, tempStride0B); | ||
write_csr(967, tempStride1B); | ||
write_csr(968, 0); | ||
|
||
// temporal strides for C | ||
write_csr(969, 0); | ||
write_csr(970, tempStride1C); | ||
write_csr(971, tempStride2C); | ||
|
||
// temporal strides for D | ||
write_csr(972, 0); | ||
write_csr(973, tempStride1C); | ||
write_csr(974, tempStride2C); | ||
|
||
// spatial strides for A | ||
write_csr(975, 1); | ||
write_csr(976, spatialStride1A); | ||
|
||
// spatial strides for B | ||
write_csr(977, 1); | ||
write_csr(978, spatialStride1B); | ||
|
||
// spatial strides for C | ||
write_csr(979, 4); | ||
write_csr(980, spatialStride1C); | ||
|
||
// spatial strides for D | ||
write_csr(981, 4); | ||
write_csr(982, spatialStride1C); | ||
|
||
// base ptr for A | ||
write_csr(983, (uint32_t)(delta_local_a + snrt_l1_next())); | ||
|
||
// base ptr for B | ||
write_csr(984, (uint32_t)(delta_local_b + snrt_l1_next())); | ||
|
||
// base ptr for C | ||
write_csr(985, (uint32_t)(delta_local_c + snrt_l1_next())); | ||
|
||
// base ptr for D | ||
write_csr(986, (uint32_t)(delta_local_d + snrt_l1_next())); | ||
} | ||
|
||
// Set CSR to start STREAMER | ||
void set_streamer_start() { write_csr(987, 1); } | ||
|
||
// Set GEMM configuration CSR | ||
void set_block_gemm_csr(int tempLoop0, int tempLoop1, int tempLoop2, | ||
int subtractions) { | ||
// set loop bounds, from innermost to outermost, aka from K to N to M | ||
write_csr(990, tempLoop0); | ||
write_csr(991, tempLoop1); | ||
write_csr(992, tempLoop2); | ||
|
||
// set subtraction a and b | ||
write_csr(993, subtractions); | ||
} | ||
|
||
// Set CSR to start GEMM | ||
void set_block_gemm_start() { write_csr(994, 1); } | ||
|
||
// Poll until Streamer and GEMM accelerator finish | ||
void wait_streamer_gemm() { | ||
write_csr(994, 0); | ||
write_csr(988, 0); | ||
} | ||
|
||
// Read performance counter of the Streamer, a read-only CSR | ||
uint32_t read_gemm_streamer_perf_counter() { | ||
uint32_t perf_counter = read_csr(989); | ||
return perf_counter; | ||
} | ||
|
||
// Read performance counter of GEMM, a read-only CSR | ||
uint32_t read_gemm_perf_counter() { | ||
uint32_t perf_counter = read_csr(996); | ||
return perf_counter; | ||
} |
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,85 @@ | ||
# Copyright 2023 KU Leuven. | ||
# Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
# SPDX-License-Identifier: Apache-2.0 | ||
# | ||
# Xiaoling Yi <[email protected]> | ||
|
||
# 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 | ||
|
||
# Banshee runtime is not supported | ||
ifeq ($(SELECT_RUNTIME), rtl-generic) | ||
RUNTIME_DIR := rtl-generic | ||
else | ||
RUNTIME_DIR := rtl | ||
endif | ||
|
||
################ | ||
## Directories # | ||
################ | ||
|
||
# Fixed paths in repository tree | ||
ROOT = $(abspath $(MK_DIR)/../../../../..) | ||
SNRT_DIR = $(ROOT)/sw/snRuntime | ||
## Paths relative to the runtime including this Makefile | ||
BUILDDIR = $(abspath build) | ||
SRC_DIR = $(abspath src) | ||
|
||
#################### | ||
## Build variables # | ||
#################### | ||
|
||
INCDIRS += $(abspath include) | ||
INCDIRS += $(SNRT_DIR)/src | ||
INCDIRS += $(SNRT_DIR)/api | ||
INCDIRS += $(SNRT_DIR)/src/omp | ||
INCDIRS += $(SNRT_DIR)/api/omp | ||
INCDIRS += $(SNRT_DIR)/vendor/riscv-opcodes | ||
INCDIRS += $(ROOT)/target/snitch_cluster/sw/runtime/common | ||
|
||
# math.h needed by snRuntime | ||
|
||
INCDIRS += $(SNRT_DIR)/../math/arch/riscv64/ | ||
INCDIRS += $(SNRT_DIR)/../math/arch/generic | ||
INCDIRS += $(SNRT_DIR)/../math/src/include | ||
INCDIRS += $(SNRT_DIR)/../math/src/internal | ||
INCDIRS += $(SNRT_DIR)/../math/include/bits | ||
INCDIRS += $(SNRT_DIR)/../math/include | ||
|
||
INCDIRS += $(ROOT)/target/snitch_cluster/sw/runtime/$(RUNTIME_DIR)/src | ||
INCDIRS += $(ROOT)/target/snitch_cluster/sw/runtime/$(RUNTIME_DIR)/include | ||
|
||
############ | ||
## Outputs # | ||
############ | ||
|
||
OBJS = $(BUILDDIR)/snax-streamer-gemm-lib.o | ||
ALL_OUTPUTS = $(OBJS) | ||
|
||
|
||
########## | ||
## Rules # | ||
########## | ||
|
||
.PHONY: all | ||
all: $(ALL_OUTPUTS) | ||
|
||
.PHONY: clean | ||
clean: | ||
rm -rf $(BUILDDIR) | ||
|
||
$(BUILDDIR): | ||
mkdir -p $@ | ||
|
||
$(BUILDDIR)/%.o: $(SRC_DIR)/%.c | $(BUILDDIR) | ||
$(RISCV_CC) $(RISCV_CFLAGS) -c $< -o $@ | ||
|
||
#ifneq ($(MAKECMDGOALS),clean) | ||
#-include $(DEPS) | ||
#endif | ||
|
||
# mkdir -p /repo/target/snitch_cluster/sw/snax/streamer-gemm/build | ||
# /tools/riscv-llvm/bin/clang -mcpu=snitch -menable-experimental-extensions -I/repo/target/snitch_cluster/sw/snax/streamer-gemm/include -I/repo/sw/snRuntime/src -I/repo/sw/snRuntime/api -I/repo/sw/snRuntime/src/omp -I/repo/sw/snRuntime/api/omp -I/repo/sw/snRuntime/vendor/riscv-opcodes -I/repo/target/snitch_cluster/sw/runtime/common -I/repo/target/snitch_cluster/sw/runtime/rtl/src -I/repo/target/snitch_cluster/sw/runtime/rtl/include -mabi=ilp32d -mcmodel=medany -ffast-math -fno-builtin-printf -fno-builtin-sqrtf -fno-common -fopenmp -ftls-model=local-exec -O3 -D__DEFINED_uint64_t -c /repo/target/snitch_cluster/sw/snax/streamer-gemm/src/snax-streamer-gemm-lib.c -o /repo/target/snitch_cluster/sw/snax/streamer-gemm/build/streamer-gemm.o |
37 changes: 37 additions & 0 deletions
37
target/snitch_cluster/sw/snax/streamer-gemm/include/snax-streamer-gemm-lib.h
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,37 @@ | ||
// Copyright 2023 KU Leuven. | ||
// Licensed under the Apache License, Version 2.0, see LICENSE for details. | ||
// SPDX-License-Identifier: Apache-2.0 | ||
// | ||
// Xiaoling Yi <[email protected]> | ||
|
||
#include <stdbool.h> | ||
#include "snrt.h" | ||
#include "stdint.h" | ||
|
||
#pragma once | ||
|
||
// Set STREAMER configuration CSR | ||
void set_streamer_csr(int tempLoop0, int tempLoop1, int tempLoop2, | ||
int tempStride0A, int tempStride2A, int spatialStride1A, | ||
int tempStride0B, int tempStride1B, int spatialStride1B, | ||
int tempStride1C, int tempStride2C, int spatialStride1C, | ||
int delta_local_a, int delta_local_b, int delta_local_c); | ||
|
||
// Set CSR to start STREAMER | ||
void set_streamer_start(); | ||
|
||
// Set GEMM configuration CSR | ||
void set_block_gemm_csr(int tempLoop0, int tempLoop1, int tempLoop2, | ||
int subtractions); | ||
|
||
// Set CSR to start GEMM | ||
void set_block_gemm_start(); | ||
|
||
// Poll until Streamer and GEMM accelerator finish | ||
void wait_streamer_gemm(); | ||
|
||
// Read perforamcne counter of the Streamer, a read-only CSR | ||
uint32_t read_gemm_streamer_perf_counter(); | ||
|
||
// Read perforamcne counter of GEMM, a read-only CSR | ||
uint32_t read_gemm_perf_counter(); |
Oops, something went wrong.