Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Barnes Hut (Do not Merge) #768

Open
wants to merge 39 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
0502ea9
Added running Galois NBody Code
drichmond Dec 23, 2021
eea1037
Cleanup
drichmond Dec 23, 2021
4015083
Refactor to split out header files for Manycore use
drichmond Dec 23, 2021
3ae5035
Added index field to node (and tried to fix printing code)
drichmond Dec 23, 2021
dc740c4
Undo error, set index of wrong node
drichmond Dec 23, 2021
d0e266b
Add predecessor pointer
drichmond Dec 23, 2021
1cb3b34
Added code to transform Galois structures into Manycore structures
drichmond Dec 23, 2021
3b5aa87
Fixed/finished tree traversal and HB conversion
drichmond Dec 27, 2021
6806839
NodeIdx -> BodyIdx
drichmond Dec 28, 2021
20dca74
Refactor HB Tree conversion into separate method
drichmond Dec 28, 2021
da10472
Factor out checking methods for reuse
drichmond Dec 28, 2021
c67f4eb
Hooked in RTL Simulation
drichmond Dec 28, 2021
6eab10a
fixup! Hooked in RTL Simulation
drichmond Dec 28, 2021
9d2469b
Added update kernel implementation
drichmond Dec 29, 2021
f67c70a
Add working single-thread implementation of summarize forces
drichmond Dec 29, 2021
cde93d1
Add tag 1 to kernel
drichmond Dec 30, 2021
6cc003e
Add Center of Mass summarization kernel
drichmond Jan 4, 2022
1b18a43
Finished tree-building kernel
drichmond Jan 5, 2022
b4333a1
Added some descriptive comments
drichmond Jan 5, 2022
efd0e2e
Finished Build Tree kernel
drichmond Jan 6, 2022
45fb929
Added body conversion from raw array
drichmond Jan 7, 2022
959f8e0
Update Galois code
drichmond Mar 4, 2022
e53df2e
Move nbody app
drichmond Apr 1, 2022
e01bd67
Fix two small bugs in BH
drichmond Apr 2, 2022
2896d3d
Switch to heap allocation of arrays (stack allocated segfaults)
drichmond Apr 2, 2022
bb88c05
Small sizeof fix
drichmond Apr 2, 2022
c57f305
Switched to Leaf flag as LOB of child address
drichmond Apr 3, 2022
c6c0992
Optimizations for build tree.
drichmond Apr 5, 2022
1a60a35
Added phase and pod arguments
drichmond Apr 5, 2022
4cc7aa3
More cleanup for host program
drichmond Apr 5, 2022
0c50fe7
Compute forces working
drichmond Apr 5, 2022
5104221
Added README file
drichmond Apr 5, 2022
916e741
Add all objects to Makefile
drichmond May 3, 2022
0ae32b1
Experiment with smoothing parameter
drichmond May 3, 2022
3040554
Revert to box radius for building
drichmond May 5, 2022
c10919a
Add trace commands for heatmap
drichmond May 25, 2022
0cf8fe2
Forces computation updates
drichmond May 26, 2022
7f5f1ce
Add sweep commands for nbody simulation
drichmond May 26, 2022
9ad2d2a
Fix minor variable name bug
drichmond May 26, 2022
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
4 changes: 4 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
Expand Up @@ -2,3 +2,7 @@
path = examples/apps/aes/tiny-AES-c
url = [email protected]:bespoke-silicon-group/tiny-AES-c.git
update = none
[submodule "examples/cuda/nbody/Galois"]
path = examples/apps/nbody/Galois
url = [email protected]:bespoke-silicon-group/Galois.git
update = none
1 change: 1 addition & 0 deletions examples/apps/nbody/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.deploy
1,318 changes: 1,318 additions & 0 deletions examples/apps/nbody/Barneshut.cpp

Large diffs are not rendered by default.

28 changes: 28 additions & 0 deletions examples/apps/nbody/Body.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include <Point.hpp>
#include <Node.hpp>

typedef NodeIdx BodyIdx;

struct _Body {
Point vel;
Point acc;
};

struct HBBody : public HBNode, public _Body{
};

#ifndef RISCV
struct Body : public Node, public _Body {
void convert(eva_t pred, HBBody &b){
Node::convert(pred, static_cast<HBNode&>(b));
_Body &_b = static_cast<_Body&>(b);
_b = static_cast<_Body>(*this);
}

bool isMatch(HBBody &b, bool HBLeaf){
return Node::isMatch(static_cast<HBNode&>(b), HBLeaf) && b.vel == vel && b.acc == acc;
}
};
#endif
28 changes: 28 additions & 0 deletions examples/apps/nbody/BoundingBox.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
#pragma once

#include <Point.hpp>

// DR: What is a bounding box used for?
struct BoundingBox {
Point min;
Point max;
explicit BoundingBox(const Point& p) : min(p), max(p) {}
BoundingBox()
: min(std::numeric_limits<float>::max()),
max(std::numeric_limits<float>::min()) {}

// DR: Merge two bounding boxes by taking the min and max
// x,y,z dimension from this box and another.
BoundingBox merge(const BoundingBox& other) const {
BoundingBox copy(*this);

copy.min.pairMin(other.min);
copy.max.pairMax(other.max);
return copy;
}

float diameter() const { return (max - min).minDim(); }
float radius() const { return diameter() * 0.5; }
// DR: Compute the geometric center of the bounding box
Point center() const { return (min + max) * 0.5; }
};
12 changes: 12 additions & 0 deletions examples/apps/nbody/Config.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
#pragma once

// DR: Configuration arguments
struct Config {
const float dtime; // length of one time step
const float eps; // potential softening parameter
const float tol; // tolerance for stopping recursion, <0.57 to bound error
const float dthf, epssq, itolsq;
Config()
: dtime(0.5), eps(0.05), tol(0.05), // 0.025),
dthf(dtime * 0.5), epssq(eps * eps), itolsq(1.0 / (tol * tol)) {}
};
1 change: 1 addition & 0 deletions examples/apps/nbody/Galois
Submodule Galois added at 6b8364
238 changes: 238 additions & 0 deletions examples/apps/nbody/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,238 @@
# 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 = nbody

Galois:
git submodule init --update Galois

Galois/install:
mkdir $@

Galois/build:
mkdir $@

Galois/build/CMakeCache.txt: | Galois/build
LLVM_DIR=$(shell llvm-config-11-64 --prefix) cmake -B $(dir $@) -S Galois -DBOOST_ROOT=/usr/include/boost169 -DCMAKE_INSTALL_PREFIX=Galois/install -DBUILD_SHARED_LIBS=ON

Galois/install/lib64/libgalois_shmem.so: Galois/build/CMakeCache.txt | Galois/install
$(MAKE) -C Galois/build/ install

setup: Galois/install/lib64/libgalois_shmem.so


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

vpath %.cpp $(REPLICANT_PATH)/examples/apps/nbody/Galois/lonestar/liblonestar/src/
TEST_SOURCES = Barneshut.cpp
TEST_SOURCES += BoilerPlate.cpp

TEST_HEADERS = Node.hpp Point.hpp Body.hpp Config.hpp

TILE_GROUP_DIM_X ?= 16
TILE_GROUP_DIM_Y ?= 8

DEFINES += -DTILE_GROUP_DIM_X=$(TILE_GROUP_DIM_X)
DEFINES += -DTILE_GROUP_DIM_Y=$(TILE_GROUP_DIM_Y)
DEFINES += -D_XOPEN_SOURCE=500 -D_BSD_SOURCE -D_DEFAULT_SOURCE
CDEFINES +=
CXXDEFINES +=

INCLUDES = -I$(REPLICANT_PATH)/examples/apps/nbody/Galois/install/include -I$(REPLICANT_PATH)/examples/apps/nbody/Galois/lonestar/liblonestar/include/
INCLUDES += -I$(shell llvm-config-11-64 --includedir) -I$(REPLICANT_PATH)/examples/apps/nbody/
FLAGS = -O3 -g -Wall -Wno-unused-function -Wno-unused-variable -Wno-strict-aliasing -Wno-deprecated-declarations
CFLAGS += -std=c99 $(FLAGS)
CXXFLAGS += -std=c++17 $(FLAGS)
LDFLAGS = -lpthread -Wl,-rpath=$(REPLICANT_PATH)/examples/apps/nbody/Galois/install/lib64 -L$(REPLICANT_PATH)/examples/apps/nbody/Galois/install/lib64 -lgalois_shmem -lnuma $(shell llvm-config-11-64 --ldflags --libs)

main.so: $(REPLICANT_PATH)/examples/apps/nbody/Galois/install/lib64/libgalois_shmem.so

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

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

# 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.

update.rvo: RISCV_CXX = $(RISCV_CLANGXX)
forces.rvo: RISCV_CXX = $(RISCV_GCC)
build.rvo: RISCV_CXX = $(RISCV_CLANGXX)

BSG_MANYCORE_KERNELS ?= kernel.riscv
kernel.riscv: update.rvo
kernel.riscv: forces.rvo
kernel.riscv: summarize.rvo
kernel.riscv: build.rvo

RISCV_INCLUDES += -I$(REPLICANT_PATH)/examples/apps/nbody/
RISCV_CCPPFLAGS += -D__KERNEL__ -O3

RISCV_DEFINES += -DTILE_GROUP_DIM_X=$(TILE_GROUP_DIM_X)
RISCV_DEFINES += -DTILE_GROUP_DIM_Y=$(TILE_GROUP_DIM_Y) -DRISCV
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
###############################################################################

PHASE ?= forces
POD_ID_X ?= 0
POD_ID_Y ?= 0
NPODS_X ?= 8
NPODS_Y ?= 8
NBODIES ?= 128

C_ARGS ?= -n $(NBODIES) -steps 1 -t 1 -phase $(PHASE) -px $(POD_ID_X) -py $(POD_ID_Y) -npx $(NPODS_X) -npy $(NPODS_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:
rm -rf bsg_link.ld
###############################################################################
# Sweep flow
###############################################################################

# 16tx_1ty_threads__1_work__128_offset__18_logsz.deploy

#<phase>_bh__<pod_x>x_<pod_y>x_id__<nbodies>_nbodies__<npods_x>x_<npods_y>y__pods

# bh__forces__
podx-from-name = $(subst x, ,$(word 1, $(subst _, ,$(filter %_id,$(subst __, ,$1)))))
pody-from-name = $(subst y, ,$(word 2, $(subst _, ,$(filter %_id,$(subst __, ,$1)))))
npodsx-from-name = $(subst x, ,$(word 1, $(subst _, ,$(filter %_pods,$(subst __, ,$1)))))
npodsy-from-name = $(subst y, ,$(word 2, $(subst _, ,$(filter %_pods,$(subst __, ,$1)))))
phase-from-name = $(firstword $(subst _, ,$(filter %_bh,$(subst __, ,$1))))
nbodies-from-name = $(firstword $(subst _, ,$(filter %_nbodies,$(subst __, ,$1))))

test-name = $(1)_bh__$(2)x_$(3)y_id__$(4)_nbodies__$(5)x_$(6)y_pods.deploy

range = $(shell seq -s " " $1 $(shell echo $2 - 1 | bc))
RANGE_PODS_X := $(call range,0,$(NPODS_X))
RANGE_PODS_Y := $(call range,0,$(NPODS_Y))

# Forces, 8192 Bodies, 64 pods
$(foreach x,$(RANGE_PODS_X),\
$(foreach y,$(RANGE_PODS_Y),\
$(eval FORCES_TEST_8192 += $(call test-name,forces,$x,$y,8192,8,8))))

# Forces, 16384 Bodies, 64 pods
$(foreach x,$(RANGE_PODS_X),\
$(foreach y,$(RANGE_PODS_Y),\
$(eval FORCES_TEST_16384 += $(call test-name,forces,$x,$y,16384,8,8))))

# Forces, 32768 Bodies, 64 pods
$(foreach x,$(RANGE_PODS_X),\
$(foreach y,$(RANGE_PODS_Y),\
$(eval FORCES_TEST_32768 += $(call test-name,forces,$x,$y,32768,8,8))))

go: $(FORCES_TEST_8192) $(FORCES_TEST_16384) $(FORCES_TEST_32768)

%.deploy:
mkdir $@
echo "PHASE = $(call phase-from-name,$*)">> $@/Makefile
echo "POD_ID_X = $(call podx-from-name,$*)">> $@/Makefile
echo "POD_ID_Y = $(call pody-from-name,$*)">> $@/Makefile
echo "NPODS_X = $(call npodsx-from-name,$*)">> $@/Makefile
echo "NPODS_Y = $(call npodsy-from-name,$*)">> $@/Makefile
echo "NBODIES = $(call nbodies-from-name,$*)">> $@/Makefile
echo "VPATH =.." >> $@/Makefile
cat Makefile >> $@/Makefile
$(MAKE) -C $@ kernel.dis > $@/kernel.dis
$(MAKE) -C $@ main.so
#$(MAKE) -C $@ stats

cleansweep:
rm -rf *.deploy
37 changes: 37 additions & 0 deletions examples/apps/nbody/Node.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#pragma once

#include <Point.hpp>

typedef unsigned int NodeIdx;

struct _Node {
Point pos; // DR: X, Y, Z location
int octant;
float mass;
};

struct HBNode : public _Node{
#ifndef RISCV
eva_t pred; // Used on Manycore
#else
HBNode *pred;
#endif
};

#ifndef RISCV
struct Node : public _Node{
#ifndef RISCV
bool Leaf;
#endif
Node *pred; // Used on x86
void convert(eva_t pred, HBNode &n){
_Node &_n = static_cast<_Node&>(n);
_n = static_cast<_Node>(*this);
n.pred = pred;
}
bool isMatch(HBNode &n, bool HBleaf){
return n.pos == pos && n.mass == mass && HBleaf == Leaf && n.octant == octant;
}

};
#endif
Loading