Skip to content
Snippets Groups Projects
Commit fe2bdc25 authored by Yifan Zhao's avatar Yifan Zhao
Browse files

Removed unused files

parent bb2eaaff
No related branches found
No related tags found
No related merge requests found
10
10 15 10 16 15 30 15 25 20 15
#ifndef __DEVICE_ABSTRACTION__
#define __DEVICE_ABSTRACTION__
#include <fstream>
#include <iostream>
#include <stdio.h>
#include <stdlib.h>
#include <thread>
#include <time.h>
#include <vector>
#define MIN_INTERVAL 2
#define MAX_INTERVAL 8
#define NUM_INTERVALS 10
// Device status variable: true if the device is available for use
volatile bool deviceStatus = true;
// Intervals at which to change the device status
std::vector<unsigned> Intervals;
// Set to true when program execution ends and so we can end the device
// simulation
volatile bool executionEnd = false;
void initializeDeviceStatusIntervals() {
unsigned sz = 0;
unsigned tmp = 0;
const char *fn = "/home/kotsifa2/HPVM/hpvm/build/projects/hpvm-rt/"
"deviceStatusSwitchIntervals.txt";
std::ifstream infile;
infile.open(fn);
if (!infile.is_open()) {
std::cout << "Failed to open " << fn << " for reading\n";
return;
}
infile >> sz;
if (sz) {
// We have data. Read them into the vector
for (unsigned i = 0; i < sz; i++) {
infile >> tmp;
Intervals.push_back(tmp);
}
infile.close();
} else {
// We have no data. Create random data and write them into the file
infile.close();
std::ofstream outfile;
outfile.open(fn);
if (!outfile.is_open()) {
std::cout << "Failed to open " << fn << " for writing\n";
return;
}
sz = 1 + rand() % NUM_INTERVALS;
outfile << sz;
for (unsigned i = 0; i < sz; i++) {
Intervals.push_back(MIN_INTERVAL +
rand() % (MAX_INTERVAL - MIN_INTERVAL));
outfile << Intervals[i];
}
outfile.close();
}
return;
}
void updateDeviceStatus() {
unsigned i = 0;
while (!executionEnd) {
std::this_thread::sleep_for(std::chrono::seconds(Intervals[i]));
deviceStatus = !deviceStatus;
std::cout << "Changed device status to " << deviceStatus << "\n";
i = (i + 1) % Intervals.size();
}
}
#endif // __DEVICE_ABSTRACTION__
#LLVM_SRC_ROOT =
LLVM_BUILD_ROOT = ${LLVM_SRC_ROOT}/../build/
CUDA_INC_PATH = /software/cuda-9.1/include/CL/
ifeq ($(NUM_CORES),)
NUM_CORES=1
endif
CPP_FLAGS = -I$(LLVM_SRC_ROOT)/include -I$(LLVM_BUILD_ROOT)/include -I$(CUDA_INC_PATH) -std=c++11 -D__STDC_CONSTANT_MACROS -D__STDC_LIMIT_MACROS
TARGET:=hpvm-rt
LLVM_CC:=$(LLVM_BUILD_ROOT)/bin/clang
LLVM_CXX:=$(LLVM_BUILD_ROOT)/bin/clang++
OPTS =
ifeq ($(DEBUG),1)
OPTS+=-DDEBUG_BUILD
endif
all: $(TARGET:%=%.ll)
$(TARGET:%=%.ll):%.ll:%.cpp %.h
$(LLVM_CXX) -DNUM_CORES=$(NUM_CORES) -O3 -S -emit-llvm $(CPP_FLAGS) $(OPTS) $< -o $@
clean :
rm -f $(TARGET).ll
#ifndef __POLICY__
#define __POLICY__
#include "device_abstraction.h"
#include <string>
/************************* Policies *************************************/
class Policy {
public:
virtual int getVersion(const char *, int64_t) = 0;
virtual ~Policy(){};
};
class ConstPolicy : public Policy {
public:
ConstPolicy(int deviceID) : deviceID(deviceID) {}
int getVersion(const char *, int64_t) override { return deviceID; }
private:
int deviceID;
};
class NodePolicy : public Policy {
virtual int getVersion(const char *name, int64_t it) override {
std::string s(name);
std::string NodeNames[] = {
"WrapperGaussianSmoothing_cloned",
"WrapperlaplacianEstimate_cloned",
"WrapperComputeZeroCrossings_cloned",
"WrapperComputeGradient_cloned",
"WrapperComputeMaxGradient_cloned",
"WrapperRejectZeroCrossings_cloned",
};
return 2;
}
};
class IterationPolicy : public Policy {
virtual int getVersion(const char *name, int64_t it) override {
if ((it % 10 == 0) || (it % 10 == 1))
return 0;
else
return 2;
}
};
class DeviceStatusPolicy : public Policy {
virtual int getVersion(const char *name, int64_t it) override {
if (deviceStatus) {
return 2;
} else {
return 0;
}
}
};
/* ------------------------------------------------------------------------- */
class InteractivePolicy : public Policy {
private:
// 0 :for CPU, 1 for GPU, 2 for Vector
unsigned int userTargetDeviceChoice;
// Used to end thread execution
bool end;
// Thread that will update userTargetDeviceChoice
std::thread userTargetDeviceChoiceThread;
// Thread function
void updateUserTargetChoice() {
while (!end) {
std::cout << "Select target device (0 for CPU, 1 fpr GPU): ";
std::cin >> userTargetDeviceChoice;
if (userTargetDeviceChoice > 1) {
std::cout << "Invalid target device. Selecting GPU instead.\n";
userTargetDeviceChoice = 1;
}
}
}
public:
// Inherited method, erquired for every policy object
virtual int getVersion(const char *name, int64_t it) {
return userTargetDeviceChoice;
}
InteractivePolicy() {
userTargetDeviceChoice = 1;
end = false;
userTargetDeviceChoiceThread =
std::thread(&InteractivePolicy::updateUserTargetChoice, this);
}
~InteractivePolicy() {
end = true;
userTargetDeviceChoiceThread.join();
}
};
#endif // __POLICY__
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment