Skip to content

Commit

Permalink
adding task num for priority
Browse files Browse the repository at this point in the history
  • Loading branch information
ShreyaTalati committed Nov 28, 2023
1 parent e9a0cbe commit 605726e
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 10 deletions.
12 changes: 12 additions & 0 deletions src/c/backend/include/containers.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,18 @@
// as well as std::atomic_flag.
// template <> auto constexpr is_atomic<std::atomic_flag> = true;

// struct taskStructure { // Structure declaration
// int priority; // Member (int variable)
// int wait_time;
// InnerTask *task; // Member (string variable)
// bool operator() <(taskStructure& b){
// if(priority < b.priority) {
// return true; // the order is correct and NO swapping of elements takes place
// }
// return false; // the order is NOT correct and swapping of elements takes place
// }
// };

template <typename T> class ProtectedVector {

Check warning on line 50 in src/c/backend/include/containers.hpp

View workflow job for this annotation

GitHub Actions / cpp-linter

/src/c/backend/include/containers.hpp:50:29 [cppcoreguidelines-special-member-functions]

class 'ProtectedVector' defines a copy constructor but does not define a destructor, a copy assignment operator, a move constructor or a move assignment operator

private:
Expand Down
18 changes: 8 additions & 10 deletions src/c/backend/include/device_queues.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
#include "device_manager.hpp"
#include "runtime.hpp"
#include "containers.hpp"
#include <ctime>

// TODO(wlr): FIXME Change these back to smart pointers. I'm leaking memory
// here...
Expand All @@ -35,11 +34,15 @@ template <typename ResourceCategory> class DeviceQueue {
*/
Device *get_device() { return device; }

/**
* Calculates priority for the task. The scheduling algorithm follows a low priority scheme.
* @param task the task to set priority for
*/
void set_priority(InnerTask *task) {
int num_dependents = task->dependents.size(); // inveresly propotional -> more the # of dependents, earlier it should be scheduled
int num_gpus_required = task->assigned_devices.size(); // directly propotional -> more the # of GPUs req, later it should be scheduled
int relative_start_time = time(NULL); // task coming later, should be later in the queue
int priority = relative_start_time + (num_gpus_required / num_dependents); // normalize and change this
int priority = total_num_tasks + (num_gpus_required / num_dependents); // normalize and change this
std::cout << total_num_tasks << std::endl;
task->set_priority(priority);
// critical path length to most recently spawned task
// estimated completion time
Expand All @@ -50,16 +53,10 @@ template <typename ResourceCategory> class DeviceQueue {
* @param task the task to enqueue
*/
void enqueue(InnerTask *task) {
// taskStructure new_task;
// int global_start_time = 1701038679;
// new_task.priority = set_priority(task);
// new_task.task = task;
// std::cout << "DeviceQueue::enqueue() - " << task->get_name() <<
// std::endl;
this->set_priority(task);
// std::cout << "Mixed Queue size: " << mixed_queue.size() << std::endl;
this->mixed_queue.push(task);
num_tasks++;
total_num_tasks++;
};

/**
Expand Down Expand Up @@ -174,6 +171,7 @@ template <typename ResourceCategory> class DeviceQueue {
MixedQueue_t mixed_queue;
MDQueue_t waiting_queue;
std::atomic<int> num_tasks{0};
std::atomic<int> total_num_tasks{0};
};

// TODO(wlr): I don't know what to name this.
Expand Down

0 comments on commit 605726e

Please sign in to comment.