Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion environment.mk
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ __BSG_ENVIRONMENT_MK := 1
# Name of this project
PROJECT = cl_manycore

CL_DIR := $(shell git rev-parse --show-toplevel)
CL_DIR ?= $(shell git rev-parse --show-toplevel)
HARDWARE_PATH := $(CL_DIR)/hardware
LIBRARIES_PATH := $(CL_DIR)/libraries
MACHINES_PATH := $(CL_DIR)/machines
Expand Down
1 change: 1 addition & 0 deletions examples/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -24,3 +24,4 @@ ucli.key
*.saifgen
*.json
dramsim3.txt
*.a
141 changes: 141 additions & 0 deletions examples/cuda/hw_barrier/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
# Copyright (c) 2021, University of Washington All rights reserved.
#
# Redistribution and use in source and binary forms, with or without modification,
# are permitted provided that the following conditions are met:
#
# Redistributions of source code must retain the above copyright notice, this list
# of conditions and the following disclaimer.
#
# Redistributions in binary form must reproduce the above copyright notice, this
# list of conditions and the following disclaimer in the documentation and/or
# other materials provided with the distribution.
#
# Neither the name of the copyright holder nor the names of its contributors may
# be used to endorse or promote products derived from this software without
# specific prior written permission.
#
# THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
# ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
# WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
# DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
# ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
# (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
# LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
# ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
# SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

# This Makefile compiles, links, and executes examples Run `make help`
# to see the available targets for the selected platform.

################################################################################
# environment.mk verifies the build environment and sets the following
# makefile variables:
#
# LIBRAIRES_PATH: The path to the libraries directory
# HARDWARE_PATH: The path to the hardware directory
# EXAMPLES_PATH: The path to the examples directory
# BASEJUMP_STL_DIR: Path to a clone of BaseJump STL
# BSG_MANYCORE_DIR: Path to a clone of BSG Manycore
###############################################################################

REPLICANT_PATH:=$(shell git rev-parse --show-toplevel)

include $(REPLICANT_PATH)/environment.mk

# TEST_NAME is the basename of the executable
TEST_NAME = main
# KERNEL_NAME is the name of the CUDA-Lite Kernel
KERNEL_NAME = barrier_test

###############################################################################
# Host code compilation flags and flow
###############################################################################
# TEST_SOURCES is a list of source files that need to be compiled
TEST_SOURCES = main.cpp

TEST_HEADERS =

DEFINES += -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -D_DEFAULT_SOURCE
CDEFINES +=
CXXDEFINES +=

FLAGS = -O3 -g -Wall -Wno-unused-function -Wno-unused-variable
CFLAGS += -std=c99 $(FLAGS)
CXXFLAGS += -std=c++11 $(FLAGS)

# compilation.mk defines rules for compilation of C/C++
include $(EXAMPLES_PATH)/compilation.mk

###############################################################################
# Host code link flags and flow
###############################################################################

LDFLAGS =

# link.mk defines rules for linking of the final execution binary.
include $(EXAMPLES_PATH)/link.mk

$(TEST_OBJECTS): $(TEST_HEADERS)

###############################################################################
# Device code compilation flow
###############################################################################

# BSG_MANYCORE_KERNELS is a list of manycore executables that should
# be built before executing.

BSG_MANYCORE_KERNELS ?= kernel.riscv
RISCV_TARGET_OBJECTS += kernel.rvo
RISCV_INCLUDES +=
RISCV_CCPPFLAGS += -D__KERNEL__

TILE_GROUP_DIM_X ?= 16
TILE_GROUP_DIM_Y ?= 8
RISCV_DEFINES += -DTILE_GROUP_DIM_X=$(TILE_GROUP_DIM_X)
RISCV_DEFINES += -DTILE_GROUP_DIM_Y=$(TILE_GROUP_DIM_Y)
RISCV_DEFINES += -Dbsg_tiles_X=$(TILE_GROUP_DIM_X)
RISCV_DEFINES += -Dbsg_tiles_Y=$(TILE_GROUP_DIM_Y)

include $(EXAMPLES_PATH)/cuda/riscv.mk

###############################################################################
# Execution flow
#
# C_ARGS: Use this to pass arguments that you want to appear in argv
# For SPMD tests C arguments are: <Path to RISC-V Binary> <Test Name>
#
# SIM_ARGS: Use this to pass arguments to the simulator
###############################################################################

C_ARGS ?= $(BSG_MANYCORE_KERNELS) $(KERNEL_NAME)
C_ARGS += $(TILE_GROUP_DIM_X) $(TILE_GROUP_DIM_Y)

SIM_ARGS ?=

# Include platform-specific execution rules
include $(EXAMPLES_PATH)/execution.mk

###############################################################################
# Regression Flow
###############################################################################

regression: main.exec.log
@grep "BSG REGRESSION TEST .*PASSED.*" $< > /dev/null

###############################################################################
# Default rules, help, and clean
###############################################################################
.DEFAULT_GOAL := help
help:
@echo "Usage:"
@echo "make {clean | $(TEST_NAME).{profile,debug} | $(TEST_NAME).{profile,debug}.log}"
@echo " $(TEST_NAME).profile: Build executable with profilers enabled"
@echo " $(TEST_NAME).debug: Build waveform executable (if VCS)"
@echo " $(TEST_NAME).{profile,debug}.log: Run specific executable"
@echo " clean: Remove all subdirectory-specific outputs"


.PHONY: clean

clean:
19 changes: 19 additions & 0 deletions examples/cuda/hw_barrier/kernel.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
#include "bsg_manycore.h"
#include "bsg_cuda_lite_barrier.h"
#include "bsg_barrier_amoadd.h"

int barrier_test()
{
bsg_barrier_hw_tile_group_init();
for (int x = 0; x < bsg_tiles_X; x++) {
for (int y = 0; y < bsg_tiles_Y; y++) {
if (__bsg_x == x && __bsg_y == y) {
int *ptr = (int*)bsg_remote_ptr_io(IO_X_INDEX, 0x8888);
*ptr = (__bsg_x<<16)|(__bsg_y);
}
bsg_barrier_hw_tile_group_sync();
}
}

return 0;
}
113 changes: 113 additions & 0 deletions examples/cuda/hw_barrier/main.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,113 @@
#include "bsg_manycore_regression.h"
#include "bsg_manycore_cuda.h"
#include "bsg_manycore.h"
#include "bsg_manycore_responder.h"
#include <cstring>
#include <vector>

static hb_mc_device_t *dev = nullptr;
static std::vector<int> pkt_data;


//////////////////////////////////////////////////////
// Responder to check for packets from the manycore //
//////////////////////////////////////////////////////
static
hb_mc_request_packet_id_t resp_ids [] = {
RQST_ID(RQST_ID_ANY_X, RQST_ID_ANY_Y, RQST_ID_ADDR(0x8888)),
{/*sentinal*/},
};

static int resp_init(hb_mc_responder_t *resp, hb_mc_manycore_t *mc)
{
return HB_MC_SUCCESS;
}

static int resp_quit(hb_mc_responder_t *resp, hb_mc_manycore_t *mc)
{
return HB_MC_SUCCESS;
}

static int resp_respond(hb_mc_responder_t *resp, hb_mc_manycore_t *mc, const hb_mc_request_packet_t *rqst)
{
bsg_pr_dbg("%s: received packet from (%3d,%3d)\n"
, __func__
, rqst->x_src
, rqst->y_src);

pkt_data.push_back(static_cast<int>(hb_mc_request_packet_get_data(rqst)));
return HB_MC_SUCCESS;
}


static
hb_mc_responder_t resp ("barrier-test", resp_ids, resp_init, resp_quit, resp_respond);
source_responder(resp);

////////////////////////
// Main hosst program //
////////////////////////
int barrier_test_main(int argc, char *argv[])
{
char *rvp = argv[1];
char *kname = argv[2];
int tgx = atoi(argv[3]);
int tgy = atoi(argv[4]);

dev = (hb_mc_device_t*)malloc(sizeof(*dev));
if (!dev) {
bsg_pr_err("failed to allocate memory\n");
return HB_MC_NOMEM;
}

// initialize
BSG_CUDA_CALL(hb_mc_device_init(dev, "cuda hw barrier", 0));
BSG_CUDA_CALL(hb_mc_device_program_init(dev, rvp, "baralloc", 0));

// enque job and execute
hb_mc_dimension_t gd, tgd;
gd = hb_mc_dimension(1,1);
tgd = hb_mc_dimension(tgx, tgy);

BSG_CUDA_CALL(hb_mc_kernel_enqueue(dev, gd, tgd, kname, 0, nullptr));
BSG_CUDA_CALL(hb_mc_device_tile_groups_execute(dev));

// cleanup
BSG_CUDA_CALL(hb_mc_device_program_finish(dev));
BSG_CUDA_CALL(hb_mc_device_finish(dev));

// check that we got the right number of packets
if (static_cast<int>(pkt_data.size()) != tgx*tgy) {
bsg_pr_err("Expected %d packets from %3d X %3d group, received %d\n"
, tgx*tgy
, tgx
, tgy
, static_cast<int>(pkt_data.size()));
return HB_MC_FAIL;
}

// validate results by checking that the expected packets arrived in-order
int id = 0;
for (int x = 0; x < tgx; x++) {
for (int y = 0; y < tgy; y++) {
int data = pkt_data[id];
int dx = (data >> 16) & 0xffff;
int dy = data & 0xffff;

if (x != dx || y != dy) {
bsg_pr_err("Packet %d: expected from (%d,%d) but found (%d,%d)\n"
, id
, x
, y
, dx
, dy);
return HB_MC_FAIL;
}
id++;
}
}
return HB_MC_SUCCESS;
}

declare_program_main("HW Barrier Test", barrier_test_main);

26 changes: 18 additions & 8 deletions examples/cuda/riscv.mk
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ RISCV_LLVM_PATH := $(RISCV_TOOLS_PATH)/llvm/llvm-install
# RISC-V Tool Configuration
################################################################################

RISCV_LINK_GEN := $(BSG_MANYCORE_DIR)/software/py/bsg_manycore_link_gen.py
RISCV_LINK_GEN ?= $(BSG_MANYCORE_DIR)/software/py/bsg_manycore_link_gen.py

# These flags are not supported by clang
RISCV_GNU_FLAGS = -frerun-cse-after-loop -fweb -frename-registers -mtune=bsg_vanilla_2020
Expand Down Expand Up @@ -267,17 +267,25 @@ crt.rvo: $(BSG_MANYCORE_COMMON_PATH)/crt.S
# We compile these locally so that we don't interfere with the files in
# $(BSG_MANYCORE_LIB_PATH).
# BSG Manycore Library Objects
LIBBSG_MANYCORE_OBJECTS += bsg_set_tile_x_y.rvo
LIBBSG_MANYCORE_OBJECTS += bsg_tile_config_vars.rvo
LIBBSG_MANYCORE_OBJECTS += bsg_printf.rvo
LIBBSG_MANYCORE_OBJECTS += bsg_set_tile_x_y.c.rvo
LIBBSG_MANYCORE_OBJECTS += bsg_tile_config_vars.c.rvo
LIBBSG_MANYCORE_OBJECTS += bsg_printf.c.rvo
LIBBSG_MANYCORE_OBJECTS += bsg_barrier_amoadd.S.rvo
LIBBSG_MANYCORE_OBJECTS += bsg_cuda_lite_barrier.c.rvo

libbsg_manycore_riscv.a: $(LIBBSG_MANYCORE_OBJECTS)
$(RISCV_AR) rcs $@ $^

# See comment above about _RISCV_GCC and _RISCV_GXX for explanation of
# the preceding underscore.
$(LIBBSG_MANYCORE_OBJECTS) main.rvo: RISCV_CXX = $(_RISCV_GCC)

$(LIBBSG_MANYCORE_OBJECTS): %.rvo:$(BSG_MANYCORE_LIB_PATH)/%.c
$(filter %.c.rvo,$(LIBBSG_MANYCORE_OBJECTS)): %.c.rvo:$(BSG_MANYCORE_LIB_PATH)/%.c
$(_RISCV_GCC) $(RISCV_CFLAGS) $(RISCV_DEFINES) $(RISCV_INCLUDES) -c $< -o $@

$(filter %.S.rvo,$(LIBBSG_MANYCORE_OBJECTS)): %.S.rvo:$(BSG_MANYCORE_LIB_PATH)/%.S
$(_RISCV_GCC) $(RISCV_CFLAGS) $(RISCV_DEFINES) -D__ASSEMBLY__=1 $(RISCV_INCLUDES) -c $< -o $@

main.rvo: $(BSG_MANYCORE_CUDALITE_MAIN_PATH)/main.c
$(_RISCV_GCC) $(RISCV_CFLAGS) $(RISCV_DEFINES) $(RISCV_INCLUDES) -c $< -o $@

Expand Down Expand Up @@ -379,21 +387,23 @@ RISCV_LDFLAGS += -ffast-math
RISCV_LDFLAGS += -lc
RISCV_LDFLAGS += -lm
RISCV_LDFLAGS += -lgcc
RISCV_LDFLAGS += -L.
RISCV_LDFLAGS += -lbsg_manycore_riscv

# TODO: temporary fix to solve this problem: https://stackoverflow.com/questions/56518056/risc-v-linker-throwing-sections-lma-overlap-error-despite-lmas-belonging-to-dif
RISCV_LDFLAGS += -Wl,--no-check-sections

# This builds a .riscv binary for the current machine type and tile
# group size. RISCV_TARGET_OBJECTS are .rvo files that will be linked
# in the final binary.
%.riscv: crt.rvo bsg_set_tile_x_y.rvo bsg_tile_config_vars.rvo main.rvo $(RISCV_TARGET_OBJECTS) $(RISCV_LINK_SCRIPT)
$(RISCV_LD) -T $(RISCV_LINK_SCRIPT) $(RISCV_LDFLAGS) $(filter %.rvo,$^) -o $@
%.riscv: crt.rvo libbsg_manycore_riscv.a main.rvo $(RISCV_TARGET_OBJECTS) $(RISCV_LINK_SCRIPT)
$(RISCV_LD) -T $(RISCV_LINK_SCRIPT) $(filter %.rvo,$^) -o $@ $(RISCV_LDFLAGS)

%.dis: %.riscv
$(RISCV_OBJDUMP) -dS $<

kernel.link.clean:
rm -rf *.riscv *.rvo.S *.rvo.ll $(RISCV_LINK_SCRIPT)
rm -rf *.riscv *.rvo.S *.rvo.ll $(RISCV_LINK_SCRIPT) libbsg_manycore_riscv.a


.PRECIOUS: %.riscv
Expand Down
6 changes: 6 additions & 0 deletions libraries/bsg_manycore_config.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -144,6 +144,12 @@ int hb_mc_config_init(const hb_mc_config_raw_t raw[HB_MC_CONFIG_MAX],
CHECK_FIELD(HB_MC_CONFIG_NOC_COORD_Y_WIDTH, idx > 0 && idx < 32);
config->noc_coord_width.y = idx;

config->noc_ruche_factor.x = 3;
config->noc_ruche_factor.y = 0;

config->bar_ruche_factor.x = config->noc_ruche_factor.x;
config->bar_ruche_factor.y = config->noc_ruche_factor.y;

config->basejump = raw[HB_MC_CONFIG_REPO_BASEJUMP_HASH];
config->manycore = raw[HB_MC_CONFIG_REPO_MANYCORE_HASH];
config->f1 = raw[HB_MC_CONFIG_REPO_F1_HASH];
Expand Down
2 changes: 2 additions & 0 deletions libraries/bsg_manycore_config.h
Original file line number Diff line number Diff line change
Expand Up @@ -93,6 +93,8 @@ extern "C" {
hb_mc_dimension_t pods; // how many vcore pods?
hb_mc_dimension_t pod_shape; // what is the shape of a pod?
hb_mc_dimension_t noc_coord_width;
hb_mc_dimension_t noc_ruche_factor;
hb_mc_dimension_t bar_ruche_factor;
hb_mc_dimension_t pod_coord_width;
hb_mc_dimension_t tile_coord_width;
hb_mc_coordinate_t host_interface;
Expand Down
1 change: 1 addition & 0 deletions libraries/bsg_manycore_config_pod.h
Original file line number Diff line number Diff line change
Expand Up @@ -244,6 +244,7 @@ extern "C" {
return tile.x
+ cfg->pod_shape.x;
}
return 0;
}

static inline hb_mc_idx_t
Expand Down
Loading