Compare commits

..

6 Commits

Author SHA1 Message Date
Nils Hölscher cf2907d1d9 Added new dev container setup to README and removed VM setup
continuous-integration/drone/push Build is failing Details
2022-07-15 07:42:26 +00:00
Nils Hölscher 65c74a1883 Better dev container 2022-07-15 07:42:04 +00:00
Nils Hölscher 73e16bd797 Added VS Code devcontainer and uptaded needed llvm versionn to 14.
continuous-integration/drone/push Build is failing Details
2022-07-15 09:10:44 +02:00
Nils Hölscher 388103da3f Updated Debug Task.
continuous-integration/drone/push Build is passing Details
2022-06-20 08:49:23 +02:00
Nils Hölscher 9146caf849 Added Unit tests to the helper scripts.
continuous-integration/drone/push Build is passing Details
2022-06-07 09:08:07 +02:00
Nils Hölscher 0079b4f0e0 removed Tests from llvm build in poolhleper.
continuous-integration/drone/push Build is passing Details
2022-05-30 13:06:51 +02:00
12 changed files with 194 additions and 197 deletions

12
.devcontainer/Dockerfile Normal file
View File

@ -0,0 +1,12 @@
# See here for image contents: https://github.com/microsoft/vscode-dev-containers/tree/v0.241.1/containers/ubuntu/.devcontainer/base.Dockerfile
# [Choice] Ubuntu version (use ubuntu-22.04 or ubuntu-18.04 on local arm64/Apple Silicon): ubuntu-22.04, ubuntu-20.04, ubuntu-18.04
ARG VARIANT="jammy"
FROM mcr.microsoft.com/vscode/devcontainers/base:0-${VARIANT}
# [Optional] Uncomment this section to install additional OS packages.
RUN apt-get update && export DEBIAN_FRONTEND=noninteractive \
&& apt-get -y install --no-install-recommends \
llvm llvm-dev clang lldb gcc gdb cmake make ninja-build
ENV LLVM_DIR=/usr/lib/llvm-14

View File

@ -0,0 +1,33 @@
// For format details, see https://aka.ms/devcontainer.json. For config options, see the README at:
// https://github.com/microsoft/vscode-dev-containers/tree/v0.241.1/containers/ubuntu
{
"name": "Ubuntu",
"build": {
"dockerfile": "Dockerfile",
// Update 'VARIANT' to pick an Ubuntu version: jammy / ubuntu-22.04, focal / ubuntu-20.04, bionic /ubuntu-18.04
// Use ubuntu-22.04 or ubuntu-18.04 on local arm64/Apple Silicon.
"args": { "VARIANT": "ubuntu-22.04" }
},
"extensions": ["llvm-vs-code-extensions.vscode-clangd",
"matepek.vscode-catch2-test-adapter",
"twxs.cmake",
"vadimcn.vscode-lldb",
"xaver.clang-format",
"yzhang.markdown-all-in-one",
"shd101wyy.markdown-preview-enhanced",
"streetsidesoftware.code-spell-checker"
],
// Use 'forwardPorts' to make a list of ports inside the container available locally.
// "forwardPorts": [],
// Use 'postCreateCommand' to run commands after the container is created.
// "postCreateCommand": "uname -a",
// Comment out to connect as root instead. More info: https://aka.ms/vscode-remote/containers/non-root.
"remoteUser": "vscode",
"features": {
"git": "latest",
"fish": "latest"
}
}

1
.gitignore vendored
View File

@ -10,4 +10,3 @@ build/
*.solution *.solution
compile_commands.json compile_commands.json
llvm/ llvm/
.idea

View File

@ -1,17 +0,0 @@
{
"configurations": [
{
"name": "Linux",
"includePath": [
"${workspaceFolder}/**"
],
"defines": [],
"compilerPath": "/usr/bin/clang",
"cStandard": "c17",
"cppStandard": "c++14",
"intelliSenseMode": "linux-clang-x64",
"compileCommands": "${workspaceFolder}/build/compile_commands.json"
}
],
"version": 4
}

79
.vscode/launch.json vendored
View File

@ -4,21 +4,6 @@
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0", "version": "0.2.0",
"configurations": [ "configurations": [
// {
// "type": "lldb",
// "request": "launch",
// "name": "LLDB Unrolling",
// "program": "/usr/bin/opt",
// "args": [
// "-load-pass-plugin",
// "${workspaceFolder}/build/libCacheAnalysisPass.so",
// "-passes=lru-misses",
// "${workspaceFolder}/test/cnt.ll",
// "-o",
// "/dev/null"
// ],
// "cwd": "${workspaceFolder}"
// },
{ {
"type": "lldb", "type": "lldb",
"request": "launch", "request": "launch",
@ -26,7 +11,7 @@
"program": "/usr/bin/opt", "program": "/usr/bin/opt",
"args": [ "args": [
"-load-pass-plugin", "-load-pass-plugin",
"${workspaceFolder}/build/libCacheAnalysisPass.so", "${workspaceFolder}/build/lib/libCacheAnalysisPass.so",
"-passes=lru-misses", "-passes=lru-misses",
"${workspaceFolder}/test/fft1.ll", "${workspaceFolder}/test/fft1.ll",
"-o", "-o",
@ -34,36 +19,36 @@
], ],
"cwd": "${workspaceFolder}" "cwd": "${workspaceFolder}"
}, },
{ // {
"name": "gdb fft1", // "name": "gdb fft1",
"type": "cppdbg",//Only Usable with C/C++ extension installed from Microsoft. // "type": "cppdbg",//Only Usable with C/C++ extension installed from Microsoft.
"request": "launch", // "request": "launch",
"program": "/usr/bin/opt", // "program": "/usr/bin/opt",
"args": [ // "args": [
"-load-pass-plugin", // "-load-pass-plugin",
"${fileDirname}/../build/libCacheAnalysisPass.so", // "${fileDirname}/../build/lib/libCacheAnalysisPass.so",
"-passes='lru-misses'", // "-passes='lru-misses'",
"${fileDirname}/../test/fft1.ll", // "${fileDirname}/../test/fft1.ll",
"-o", // "-o",
"/dev/null" // "/dev/null"
], // ],
"stopAtEntry": false, // "stopAtEntry": false,
"cwd": "${fileDirname}", // "cwd": "${fileDirname}",
"environment": [], // "environment": [],
"externalConsole": false, // "externalConsole": false,
"MIMode": "gdb", // "MIMode": "gdb",
"setupCommands": [ // "setupCommands": [
{ // {
"description": "Enable pretty-printing for gdb", // "description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing", // "text": "-enable-pretty-printing",
"ignoreFailures": true // "ignoreFailures": true
}, // },
{ // {
"description": "Set Disassembly Flavor to Intel", // "description": "Set Disassembly Flavor to Intel",
"text": "-gdb-set disassembly-flavor intel", // "text": "-gdb-set disassembly-flavor intel",
"ignoreFailures": true // "ignoreFailures": true
} // }
] // ]
} // }
] ]
} }

8
.vscode/tasks.json vendored
View File

@ -3,10 +3,16 @@
// for the documentation about the tasks.json format // for the documentation about the tasks.json format
"version": "2.0.0", "version": "2.0.0",
"tasks": [ "tasks": [
{
"label": "config",
"type": "shell",
"command": "rm -r build ; rm complile_commands.json ; mkdir build ; cd build ; cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DLT_LLVM_INSTALL_DIR=$LLVM_DIR ..",
"group": "build"
},
{ {
"label": "build", "label": "build",
"type": "shell", "type": "shell",
"command": "./helper.sh all", "command": " cd build ; ninja ",
"group": "build" "group": "build"
}, },
] ]

View File

@ -59,10 +59,10 @@ endif()
# `find_package(llvm)`. So there's no need to add it here. # `find_package(llvm)`. So there's no need to add it here.
list(APPEND CMAKE_PREFIX_PATH "${LT_LLVM_INSTALL_DIR}/lib/cmake/llvm/") list(APPEND CMAKE_PREFIX_PATH "${LT_LLVM_INSTALL_DIR}/lib/cmake/llvm/")
find_package(LLVM 13.0.0 REQUIRED CONFIG) find_package(LLVM 14.0.0 REQUIRED CONFIG)
# Another sanity check # Another sanity check
if(NOT "13" VERSION_EQUAL "${LLVM_VERSION_MAJOR}") if(NOT "14" VERSION_EQUAL "${LLVM_VERSION_MAJOR}")
message(FATAL_ERROR "Found LLVM ${LLVM_VERSION_MAJOR}, but need LLVM 13") message(FATAL_ERROR "Found LLVM ${LLVM_VERSION_MAJOR}, but need LLVM 13")
endif() endif()

View File

@ -59,7 +59,7 @@ struct CacheAnalysisPass : PassInfoMixin<CacheAnalysisPass> {
bool LoopUnrolling = true; bool LoopUnrolling = true;
// Assume a 4kB Cache // Assume a 4kB Cache
// with 16 Sets, associativity of 4 and Cachelines fitting two times the instruction size // with 16 Sets, associativity of 4 and Cachelines fitting two
CacheType Cache = CacheType(16, 4, 128); CacheType Cache = CacheType(16, 4, 128);
StringRef EntryPoint = "main"; StringRef EntryPoint = "main";
unsigned int EntryAddress; unsigned int EntryAddress;

141
README.md
View File

@ -26,17 +26,74 @@ I am more than happy helping you install Linux on your machine.
## Setups ## Setups
The easiest Way is to use the VM Image (pw:rtsa) provided here: ### VS Code Docker dev container (recommended setup)
<https://tu-dortmund.sciebo.de/s/JbvtbtEADx92eEG/authenticate> 1.) install docker and VS Code on your Distribution. Please keep in mind Dev containers are only supported by the native version of VS Code from Microsoft!
On this VM you can simply open VS Code from the desktop and start coding. <https://docs.docker.com/get-docker/>
Following are native setups and some other unrecommended Setups are at the end of this Readme. <https://code.visualstudio.com/>
Also read the VS Code setup, which might be interesting independent from your chosen Setup. For this setup you cannot use the OSS version of VS code or the version from Snap, as the remote development extensions will not work.
### Mac Setup 2.) I recommend you install the following extensions in vs code
clangd,
Clang-Format,
CodeLLDB,
Docker and
Remote Development (Microsoft VS Code only!)
For a general C/C++ setup of VS Code (I consider good) see:
<https://ahemery.dev/2020/08/24/c-cpp-vscode/>
3.) The project comes with a pre configured dev container and should prompt you to use it after opening the project. With this you have a running setup. If not please continue reading the manual points.
3.manual.) Use the helper script to build and run a Container.
```bash
./helper.sh docker
```
This will build a docker image and run a Docker container with the current directory mounted.
The Docker container can later be started from the Docker VS Code extension.
4.manual) Attach VS Code to the container, in the Docker Tab, and start developing
### VS Code native setup
This is my personally preferred IDE setup for C/C++ and by no means needed to accomplish this exercise.
1.) Install VS Code on your Distribution or get it from Microsoft.
<https://code.visualstudio.com/>
2.) I recommend you install the following extensions in vs code
clangd,
Clang-Format,
CodeLLDB,
C++ TestMate,
Docker and
Remote Development (Microsoft VS Code only!)
For a general C/C++ setup of VS Code (I consider good) see:
<https://ahemery.dev/2020/08/24/c-cpp-vscode/>
Most parts can be skipped, as they are already integrated in this Repo.
3.a.) Set the LLVM_DIR variable to your LLVM(14) installation.
```bash
export LLVM_DIR=<path/to/your/llvm/installation>
```
3.b.) You can auto config and build by hitting Ctr+Shift+B from the IDE or use the helper script.
4.) Pressing F5 will start a debug session, make sure to set halting points.
### Mac setup
I recommend using docker and VS Code for setup. I recommend using docker and VS Code for setup.
Also check out the recommended extensions in the Docker section. Also check out the recommended extensions in the Docker section.
@ -49,7 +106,7 @@ For Mac (tested on M1 Mac mini) you can also use:
But you will need brew installed and also have to use the poolhelper script instead of the normal helper script. But you will need brew installed and also have to use the poolhelper script instead of the normal helper script.
### Setup on a Pool PC ### Setup on a pool PC
At first get an IRB account from the following link and log in: At first get an IRB account from the following link and log in:
@ -77,66 +134,7 @@ Now you have a llvm13 source build.
Remember to use the poolhelper.sh instead of the helper.sh. Remember to use the poolhelper.sh instead of the helper.sh.
### VS Code Setup
This is my personally preferred IDE setup for C/C++ and by no means needed to accomplish this exercise.
1.) Install VS Code on your Distribution or get it from Microsoft.
<https://code.visualstudio.com/>
2.) I recommend you install the following extensions in vs code
clangd,
Clang-Format,
CodeLLDB,
C++ TestMate,
Docker and
Remote Development
For a general C/C++ setup of VS Code (I consider good) see:
<https://ahemery.dev/2020/08/24/c-cpp-vscode/>
Most parts can be skipped, as they are already integrated in this Repo.
3.) You can auto build by hitting Strg+Shift+B from the IDE.
4.) Pressing F5 will start a debug session, make sure to set halting points.
### Setting up Docker
1.) install docker and VS Code on your Distribution.
<https://docs.docker.com/get-docker/>
<https://code.visualstudio.com/>
For this setup you cannot use the OSS version of VS code or the version from Snap, as the remote development extensions will not work.
2.) I recommend you install the following extensions in vs code
clangd,
Clang-Format,
CodeLLDB,
Docker and
Remote Development
For a general C/C++ setup of VS Code (I consider good) see:
<https://ahemery.dev/2020/08/24/c-cpp-vscode/>
Most of the setup can be skipped
3.) Use the helper script to build and run a Container
```bash
./helper.sh docker
```
This will build a docker image and run a Docker container with the current directory mounted.
The Docker container can later be started from the Docker VS Code extension.
4.) Attach VS Code to the container, in the Docker Tab, and start developing
## Debugging ## Debugging
@ -160,11 +158,18 @@ The best way to see what your function does is to use the [UnitTest.cpp](https:/
With "C++ TestMate" install you can simply run or debug the test from the side panel in VS Code (Flask Icon). With "C++ TestMate" install you can simply run or debug the test from the side panel in VS Code (Flask Icon).
The "C++ TestMate" is not installed in the VM as I just added this feature now. The "C++ TestMate" is not installed in the VM as I just added this feature now.
Please feel free to add more test cases to your liking in [UnitTest.cpp](https://git.cs.tu-dortmund.de/nils.hoelscher/RTSA-lab01-CacheAnalysis/src/branch/master/UnitTest/UnitTest.cpp). Please feel free to add more test cases to your liking in [UnitTest.cpp](https://git.cs.tu-dortmund.de/nils.hoelscher/RTSA-lab01-CacheAnalysis/src/branch/master/UnitTest/UnitTest.cpp).
## Use the Helper script
## Configuring and building
The easiest way is to use the VS Code tasks in this project.
By using CTR+Shift+B you can config and then build the project.
### Use the helper script
Again if you work on a Pool PC use poolhelper.sh insted of the helper.sh script. Again if you work on a Pool PC use poolhelper.sh insted of the helper.sh script.
### Initial Setup ### Initial setup
```bash ```bash
./helper.sh all ./helper.sh all

View File

@ -7,11 +7,11 @@ clean () {
} }
config () { config () {
echo "==== Creating build folder ====" echo "==== Crating build folder ===="
mkdir build mkdir build
cd build cd build
echo "==== Configuring cmake ====" echo "==== Configuring cmake ===="
cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DLT_LLVM_INSTALL_DIR=/usr .. cmake -G Ninja -DCMAKE_BUILD_TYPE=Debug -DCMAKE_EXPORT_COMPILE_COMMANDS=1 -DLT_LLVM_INSTALL_DIR=$LLVM_DIR ..
cd .. cd ..
cp build/compile_commands.json compile_commands.json cp build/compile_commands.json compile_commands.json
echo "==== Done! ====" echo "==== Done! ===="
@ -33,6 +33,10 @@ run () {
#llvm-dis < out.bc > out.ll #llvm-dis < out.bc > out.ll
} }
test () {
./build/bin/UnitTest --gtest_brief=1
}
allBenchs=( "adpcm" allBenchs=( "adpcm"
"bs" "bs"
"bsort100" "bsort100"
@ -103,6 +107,9 @@ case $1 in
echo "==== Please provide name of the test as second argument! ====" echo "==== Please provide name of the test as second argument! ===="
fi fi
;; ;;
t | test)
test
;;
ra | runall) ra | runall)
runall runall
;; ;;
@ -157,6 +164,7 @@ case $1 in
echo " r | run [name] Run pass on test/[name] from the test folder" echo " r | run [name] Run pass on test/[name] from the test folder"
echo " cr [name] Compile and run pass on test/[name] from the test folder" echo " cr [name] Compile and run pass on test/[name] from the test folder"
echo " ra | runall Run pass on all tests from the test folder" echo " ra | runall Run pass on all tests from the test folder"
echo " t | test Execute Unit tests, only test that Fail are printed."
exit exit
;; ;;
esac esac

View File

@ -5,7 +5,6 @@
#include <cassert> #include <cassert>
#include <cstddef> #include <cstddef>
#include <cstdlib> #include <cstdlib>
#include <iomanip>
#include <iostream> #include <iostream>
#include <list> #include <list>
#include <map> #include <map>
@ -99,6 +98,10 @@ public: // everything is public, because IDGAF
Unrolled = UnrolledIn; Unrolled = UnrolledIn;
} }
// AbstractState(Address Addr) {
// Sets[Addr.Index].Associativity[0] = {{Addr.Tag}};
// }
void setUnrolled(unsigned int In) { Unrolled = In; } void setUnrolled(unsigned int In) { Unrolled = In; }
bool operator==(AbstractState In) { bool operator==(AbstractState In) {
@ -132,55 +135,9 @@ public: // everything is public, because IDGAF
*/ */
void mustJoin(AbstractState In) { void mustJoin(AbstractState In) {
/** /**
* TODO: Fill this function with an LRU must Join. * The exercise is to Fill this function with an LRU must Join.
* For this you need to use Sets. Associativity and Blocks. * For this you need to use Sets. Associativity and Blocks.
*/ */
// Loop through all 16 sets
for (int Index = 0; Index < 16; Index++) {
// create a temporary set of associativity
struct Set temp_set;
struct Set current_set = Sets[Index];
struct Set incoming_set = In.Sets[Index];
// loop through all Ages
for (auto associativity_map : current_set.Associativity) {
auto current_associativity_age = associativity_map.first;
std::list<unsigned int> current_associativity_blocklist =
associativity_map.second.Blocks;
// for every element of associativity_block_list
for (auto block : current_associativity_blocklist) {
// look through ALL incoming_set.Associativities.Entry.Blocklists for
// occurrences
for (auto incoming_associativity : incoming_set.Associativity) {
auto age = incoming_associativity.first;
struct Entry entry = incoming_associativity.second;
auto ret =
std::find(entry.Blocks.begin(), entry.Blocks.end(), block);
if (ret != entry.Blocks.end()) {
// take the maximum age
auto new_age = std::max(current_associativity_age, age);
// create a new entry at the maximum age and
std::list<unsigned int> new_block_list;
new_block_list.push_back((unsigned int) *ret);
struct Entry new_entry = {new_block_list};
// add it to temporary set
temp_set.Associativity.insert(
std::pair<unsigned int, struct Entry>(new_age, new_entry));
}
}
}
// print_block_list(associativity_age, associativity_block_list);
Sets[Index] = temp_set;
}
}
} }
/** /**
@ -257,17 +214,17 @@ public: // everything is public, because IDGAF
} }
} }
void dumpSet(unsigned int Set) { void dumpSet(unsigned int Set) {
std::cout << Addr << " {\n"; std::cout << Addr << " {\n";
std::cout << "Set[" << Set << "]: \n"; std::cout << "Set[" << Set << "]: \n";
for (auto EntryPair : this->Sets[Set].Associativity) { for (auto EntryPair : this->Sets[Set].Associativity) {
std::cout << " Age[" << EntryPair.first << "]: "; std::cout << " Age[" << EntryPair.first << "]: ";
for (auto Block : EntryPair.second.Blocks) { for (auto Block : EntryPair.second.Blocks) {
std::cout << Block << " "; std::cout << Block << " ";
}
std::cout << "\n";
} }
std::cout << "\n";
}
std::cout << "}\n"; std::cout << "}\n";
} }
@ -299,5 +256,6 @@ public: // everything is public, because IDGAF
} }
std::cout << "}\n"; std::cout << "}\n";
} }
}; // namespace }; // namespace
#endif // STATE_H #endif // STATE_H

View File

@ -36,13 +36,17 @@ run () {
#llvm-dis < out.bc > out.ll #llvm-dis < out.bc > out.ll
} }
test () {
./build/bin/UnitTest --gtest_brief=1
}
buildllvm() { buildllvm() {
mkdir llvm mkdir llvm
cd llvm cd llvm
wget https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.1/llvm-13.0.1.src.tar.xz wget https://github.com/llvm/llvm-project/releases/download/llvmorg-13.0.1/llvm-13.0.1.src.tar.xz
tar -xf llvm-13.0.1.src.tar.xz tar -xf llvm-13.0.1.src.tar.xz
rm llvm-13.0.1.src.tar.xz rm llvm-13.0.1.src.tar.xz
cmake -DCMAKE_BUILD_TYPE=MinSizeRel -DLLVM_TARGETS_TO_BUILD=host llvm-13.0.1.src/ cmake -DCMAKE_BUILD_TYPE=MinSizeRel -DLLVM_INCLUDE_TESTS=FALSE -DLLVM_TARGETS_TO_BUILD=host llvm-13.0.1.src/
make -j 4 make -j 4
export LLVM_DIR=$(pwd) >> ~/.zshrc export LLVM_DIR=$(pwd) >> ~/.zshrc
export LLVM_DIR=$(pwd) >> ~/.bashrc export LLVM_DIR=$(pwd) >> ~/.bashrc
@ -137,6 +141,9 @@ case $1 in
echo "==== Please provide name of the test as second argument! ====" echo "==== Please provide name of the test as second argument! ===="
fi fi
;; ;;
t | test)
test
;;
ra | runall) ra | runall)
runall runall
;; ;;
@ -194,6 +201,7 @@ case $1 in
echo " r | run [name] Run pass on test/[name] from the test folder" echo " r | run [name] Run pass on test/[name] from the test folder"
echo " cr [name] Compile and run pass on test/[name] from the test folder" echo " cr [name] Compile and run pass on test/[name] from the test folder"
echo " ra | runall Run pass on all tests from the test folder" echo " ra | runall Run pass on all tests from the test folder"
echo " t | test Execute Unit tests, only test that Fail are printed."
exit exit
;; ;;
esac esac