diff --git a/llvm/projects/visc-rt/policy.h b/llvm/projects/visc-rt/policy.h index 7fa3c27e3b8f7fb5a34ef27df4135a8a1f4948a0..f30c310c1a30ad36b4dbfdd6628453f5bf308874 100644 --- a/llvm/projects/visc-rt/policy.h +++ b/llvm/projects/visc-rt/policy.h @@ -8,6 +8,7 @@ class Policy { public: virtual int getVersion(const char *, int64_t) = 0; + virtual ~Policy() {}; }; class NodePolicy : public Policy { @@ -26,17 +27,16 @@ class NodePolicy : public Policy { // std::cout << s << ": CPU" << "\n"; // return 0; //} - std::cout << s << ": GPU" << "\n"; - return 1; + return 2; } }; class IterationPolicy : public Policy { virtual int getVersion(const char *name, int64_t it) override { - if (it % 10 == 0) + if ((it % 10 == 0) || (it % 10 == 1)) return 0; else - return 1; + return 2; } }; @@ -44,7 +44,7 @@ class DeviceStatusPolicy : public Policy { virtual int getVersion(const char *name, int64_t it) override { if (deviceStatus) { //std::cout << "Returning GPU\n"; - return 1; + return 2; } else { //std::cout << "Returning CPU\n"; @@ -53,4 +53,46 @@ class DeviceStatusPolicy : public Policy { } }; +/* ------------------------------------------------------------------------- */ +// Added for the CFAR interactive policy demo. + +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__ diff --git a/llvm/projects/visc-rt/visc-rt.cpp b/llvm/projects/visc-rt/visc-rt.cpp index 0b563191fd025919cda054f07f97ae5ee560184d..9f26411e3f64fb6afdb8986f5161cf5f0c33a73e 100644 --- a/llvm/projects/visc-rt/visc-rt.cpp +++ b/llvm/projects/visc-rt/visc-rt.cpp @@ -71,9 +71,10 @@ static inline void checkErr(cl_int err, cl_int success, const char * name) { /************************* Policies *************************************/ void llvm_visc_policy_init() { cout << "Initializing policy object ...\n"; - policy = new NodePolicy(); +// policy = new NodePolicy(); // policy = new IterationPolicy(); // policy = new DeviceStatusPolicy(); + policy = new InteractivePolicy(); cout << "DONE: Initializing policy object.\n"; }