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

WIP: PMU data collection #4

Open
wants to merge 9 commits into
base: dev
Choose a base branch
from
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
The table of contents is too big for display.
Diff view
Diff view
  •  
  •  
  •  
The diff you're trying to view is too large. We only load the first 3000 changed files.
33 changes: 26 additions & 7 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -7,12 +7,18 @@ find_package(MPI REQUIRED)
include_directories(${MPI_INCLUDE_PATH})

include_directories(include)
include_directories(3rd-party/dbg-macro)
# Required packages: libunwind, papi, jsoncpp

SET(CMAKE_C_COMPILER mpicc)
SET(CMAKE_CXX_COMPILER mpicxx)
set(CMAKE_CXX_STANDARD 17)

#if(CMAKE_BUILD_TYPE MATCHES "Release")
# set(CMAKE_CXX_COMPILER_OPTIONS "-O3")
#set(CMAKE_C_COMPILER_OPTIONS "-O3")
#endif()


SET(CMAKE_CXX_FLAGS "-Wall -g")
SET(CMAKE_SHARED_LINKER_FLAGS "-g")
Expand All @@ -23,15 +29,28 @@ SET(CMAKE_SHARED_LINKER_FLAGS "-g")
# link_directories(${CMAKE_SOURCE_DIR}/jevents)

# add_wrapped_file(papicnt.cpp papicnt.w)
file(GLOB_RECURSE SRC_Vapro src/*.cc)
file(GLOB_RECURSE SRC_Vapro src/*.cc src/*.cpp)

add_library(vapro SHARED ${SRC_Vapro})
target_link_libraries(vapro ${MPI_CXX_LIBRARIES} papi)
# target_link_libraries(vapro ${MPI_CXX_LIBRARIES} unwind unwind-x86_64 papi jsoncpp jevents)

add_executable(test_vapro test/test_collector.cc)
target_link_libraries(test_vapro vapro)

if (BUILD_EXAMPLES)
add_subdirectory(examples)
endif()
# add_library(libvapro SHARED ${SRC_Vapro})
# target_link_libraries(vapro ${MPI_CXX_LIBRARIES} papi)


# target_include_directories(/home/jyh/1/VAPRO/jsoncpp/build/lib)
# target_link_libraries(/home/jyh/1/VAPRO/jsoncpp/build/lib/libjsoncpp.so)
# add_executable(1 test/1.cpp)
# add_executable(test_vapro test/test_collector.cc)
# target_link_libraries(test_vapro vapro)
#
#
#
#
#
#
# if (BUILD_EXAMPLES)
# add_subdirectory(examples)
# endif()
#
Binary file added data.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added data/origindata.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
10 changes: 4 additions & 6 deletions examples/example_mpi_program.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <iostream>
#include <mpi.h>
#include <random>
#include <stdio.h>

// enum communication
//{
Expand Down Expand Up @@ -81,7 +82,7 @@ void comm(int iter) {
cnt_iter = iter;
// fprintf(stderr, "rank=%d target rank=%d\n", mpi_rank, mpi_rank +
// mpi_size_per_node);
#ifdef SEND_RECV

if (mpi_rank < mpi_size_per_node) {
MPI_Send(calc_result, send_size, MPI_DOUBLE,
mpi_rank + mpi_size_per_node, 0, MPI_COMM_WORLD);
Expand All @@ -90,10 +91,8 @@ void comm(int iter) {
MPI_Recv(recv_buffer, send_size, MPI_DOUBLE,
mpi_rank - mpi_size_per_node, 0, MPI_COMM_WORLD, &status);
}
#else // ALL_REDUCE
MPI_Allreduce(calc_result, recv_buffer, send_size, MPI_DOUBLE, MPI_SUM,
MPI_COMM_WORLD);
#endif

//MPI_Allreduce(calc_result, recv_buffer, send_size, MPI_DOUBLE, MPI_SUM,MPI_COMM_WORLD);
}

int main(int argc, char *argv[]) {
Expand All @@ -103,7 +102,6 @@ int main(int argc, char *argv[]) {
}
MPI_Init(nullptr, nullptr);
MPI_Barrier(MPI_COMM_WORLD);

send_size = atoi(argv[1]);
// double send_time=atof(argv[1]);
// loop_len=atoi(argv[2]);
Expand Down
20 changes: 19 additions & 1 deletion include/collector.h
Original file line number Diff line number Diff line change
@@ -1,12 +1,26 @@
#pragma once
#include <common.h>
#include "common.h"
#include <iostream>

namespace vapro {

using MetricVec = vector<string>;
using DataVec = vector<uint64_t>;

class StoreKey {

private:
bool isComputation;
uint64_t address;

public:
StoreKey(bool isc, uint64_t add) : isComputation(isc), address(add) {}
friend bool operator<(const StoreKey a, const StoreKey b);

bool getisComputation() const;
uint64_t getaddress() const;
};

class Collector {
public:
// Collector(const Collector &) = delete;
Expand All @@ -15,8 +29,12 @@ class Collector {
virtual MetricVec getAvailableMetric() const = 0;
virtual MetricVec getEnabledMetric() const = 0;
virtual MetricVec setMetric() = 0;
virtual StoreKey getKey() = 0;
virtual DataVec readData() = 0;

Collector() {}
DataVec data;

private:
};

Expand Down
16 changes: 10 additions & 6 deletions include/collector_papi.h
Original file line number Diff line number Diff line change
@@ -1,19 +1,23 @@
#pragma once
#include <collector.h>
#include "collector.h"

namespace vapro {

const string metricTotalInst("TOT_INST"), metricTSC("TSC");

class CollectorPapi : public Collector {

MetricVec allMetrics = {metricTotalInst, metricTSC};

int EventSet;

public:
unsigned long long time;
CollectorPapi();
virtual MetricVec getAvailableMetric() const { return allMetrics; }
virtual MetricVec getEnabledMetric() const { return allMetrics; }
virtual MetricVec setMetric() { IT_TODO_HALT(); }
virtual DataVec readData();
MetricVec getAvailableMetric() const override { return allMetrics; }
MetricVec getEnabledMetric() const override { return allMetrics; }
MetricVec setMetric() override { IT_TODO_HALT(); }
DataVec readData() override;
StoreKey getKey() override;
};

} // namespace vapro
8 changes: 7 additions & 1 deletion include/common.h
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
#pragma once
#include "dbg.h"
//#include "dbg.h"
#include <cassert>
#include <exception>
#include <functional>
Expand Down Expand Up @@ -76,4 +76,10 @@ template <typename T> std::string vecToString(const std::vector<T> &vec) {
return ret;
}

static __inline__ unsigned long long rdtsc() {
unsigned hi, lo;
__asm__ __volatile__("rdtsc" : "=a"(lo), "=d"(hi));
return ((unsigned long long)lo) | (((unsigned long long)hi) << 32);
}

} // namespace vapro
34 changes: 30 additions & 4 deletions include/controller.h
Original file line number Diff line number Diff line change
@@ -1,18 +1,44 @@
#pragma once
#include "collector.h"
#include "collector_papi.h"
#include <common.h>
#include "data_store.h"
#include "common.h"
#include "json/json.h"

namespace vapro {

class Controller {
private:
vector<unique_ptr<Collector>> collectors;
public:

vector<unique_ptr<CollectorPapi>> collectors;
vector<DataVec> datas;
vector<unsigned long long> times;
bool hasData = false;
DataStore datastore;

Json::Value root;
Json::StyledWriter writer;
Json::Value* person;

public:
Controller();

void readData();
DataVec readData();

DataVec enterExternal();
// TODO:
// 1. read data D1.
// 2. get address
// 3. If hasData, save the data into store. The data should be D1-D0.
// 4. get the current time T0
DataVec leaveExternal(DataVec workload);
// TODO:
// 1. get the current time T1
// 2. store performacne data of the external functions into store.
// <time T1-T0, workload>
// 3. save current performance data D0.
void savedata(int id);

};

} // namespace vapro
26 changes: 26 additions & 0 deletions include/data_store.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
#pragma once
#include "collector.h"
#include "common.h"

namespace vapro {

using StoreValue = vector<DataVec>;

class DataStore {
public:
map<StoreKey, StoreValue> store;
//class StoreKey
//private:
//bool isComputation;
//uint64_t address;

void insert(const StoreKey &key, const DataVec &value);

const StoreValue &get(const StoreKey &key);

void showdata();

private:
};

} // namespace vapro
Loading