diff --git a/src/runtime/machine_view.cc b/src/runtime/machine_view.cc index dadece7691..408a87ca8d 100644 --- a/src/runtime/machine_view.cc +++ b/src/runtime/machine_view.cc @@ -1,4 +1,5 @@ #include "flexflow/machine_view.h" +#include "flexflow/utils/hash_utils.h" namespace FlexFlow { @@ -47,13 +48,13 @@ size_t MachineView::num_parts() const { } size_t MachineView::hash() const { - size_t ret = 17; - ret = ret * 31 + std::hash()(device_type); - ret = ret * 31 + std::hash()(ndims); - ret = ret * 31 + std::hash()(start_device_id); + size_t ret = 0; + hash_combine(ret, device_type); + hash_combine(ret, ndims); + hash_combine(ret, start_device_id); for (int i = 0; i < ndims; i++) { - ret = ret * 31 + std::hash()(dim[i]); - ret = ret * 31 + std::hash()(stride[i]); + hash_combine(ret, dim[i]); + hash_combine(ret, stride[i]); } return ret; } @@ -116,12 +117,12 @@ MachineResource::MachineResource(FFConfig const &config) available_gpus_per_node(config.workersPerNode) {} size_t MachineResource::hash() const { - size_t ret = 17; - ret = ret * 31 + std::hash()(num_nodes); - ret = ret * 31 + std::hash()(available_gpus_per_node); - ret = ret * 31 + std::hash()(available_cpus_per_node); - ret = ret * 31 + std::hash()(start_gpu_id); - ret = ret * 31 + std::hash()(start_cpu_id); + size_t ret = 0; + hash_combine(ret, num_nodes); + hash_combine(ret, available_gpus_per_node); + hash_combine(ret, available_cpus_per_node); + hash_combine(ret, start_gpu_id); + hash_combine(ret, start_cpu_id); return ret; } @@ -132,4 +133,4 @@ size_t hash::operator()( FlexFlow::MachineView const &mv) const { return mv.hash(); } -}; // namespace std \ No newline at end of file +}; // namespace std diff --git a/src/runtime/parallel_tensor.cc b/src/runtime/parallel_tensor.cc index 202983e8f0..7dc6c52442 100644 --- a/src/runtime/parallel_tensor.cc +++ b/src/runtime/parallel_tensor.cc @@ -449,13 +449,14 @@ bool ParallelTensorBase::get_output_sub_tensor(ParallelConfig const &pc, } size_t ParallelTensorBase::get_owner_independent_hash() const { - size_t hash = 17 * 31 + std::hash()((int)data_type); - hash = hash * 31 + std::hash()((int)sync_type); - hash = hash * 31 + std::hash()(num_dims); + size_t hash = 0; + hash_combine(hash, static_cast(data_type)); + hash_combine(hash, static_cast(sync_type)); + hash_combine(hash, num_dims); for (int i = 0; i < num_dims; i++) { - hash = hash * 31 + std::hash()(dims[i].size); - hash = hash * 31 + std::hash()(dims[i].degree); - hash = hash * 31 + std::hash()(dims[i].parallel_idx); + hash_combine(hash, dims[i].size); + hash_combine(hash, dims[i].degree); + hash_combine(hash, dims[i].parallel_idx); } return hash; } diff --git a/src/runtime/simulator.cc b/src/runtime/simulator.cc index b71af0d47e..6a7f88cfb6 100644 --- a/src/runtime/simulator.cc +++ b/src/runtime/simulator.cc @@ -315,8 +315,9 @@ SimTask *TaskManager::new_comm_task(std::string const &name, SimTask *TaskManager::new_forward_task(Op const *op, int idx) { SimTask *task = new_task(); task->type = SimTask::TASK_FORWARD; - size_t hash = 17 * 31 + (size_t)(op); - hash = hash * 31 + std::hash()(idx); + size_t hash = 0; + hash_combine(hash, (size_t)op); + hash_combine(hash, idx); hash_to_forward_task[hash] = task; task->name = op->name; return task; @@ -325,23 +326,26 @@ SimTask *TaskManager::new_forward_task(Op const *op, int idx) { SimTask *TaskManager::new_backward_task(Op const *op, int idx) { SimTask *task = new_task(); task->type = SimTask::TASK_BACKWARD; - size_t hash = 17 * 31 + (size_t)(op); - hash = hash * 31 + std::hash()(idx); + size_t hash = 0; + hash_combine(hash, (size_t)op); + hash_combine(hash, idx); hash_to_backward_task[hash] = task; task->name = op->name; return task; } SimTask *TaskManager::get_forward_task(Op const *op, int idx) { - size_t hash = 17 * 31 + (size_t)(op); - hash = hash * 31 + std::hash()(idx); + size_t hash = 0; + hash_combine(hash, (size_t)op); + hash_combine(hash, idx); assert(hash_to_forward_task.find(hash) != hash_to_forward_task.end()); return hash_to_forward_task[hash]; } SimTask *TaskManager::get_backward_task(Op const *op, int idx) { - size_t hash = 17 * 31 + (size_t)(op); - hash = hash * 31 + std::hash()(idx); + size_t hash = 0; + hash_combine(hash, (size_t)op); + hash_combine(hash, idx); assert(hash_to_backward_task.find(hash) != hash_to_backward_task.end()); return hash_to_backward_task[hash]; } @@ -535,11 +539,12 @@ CostMetrics Simulator::measure_operator_cost(Op const *op, return this->strict_hash_to_operator_cost.at(key); } - size_t hash = 17 * 31 + op->get_untyped_params_hash(); - hash = hash * 31 + std::hash()(mv.device_type); - hash = hash * 31 + std::hash()(mv.ndims); + size_t hash = 0; + hash_combine(hash, op->get_untyped_params_hash()); + hash_combine(hash, mv.device_type); + hash_combine(hash, mv.ndims); for (int i = 0; i < mv.ndims; i++) { - hash = hash * 31 + std::hash()(mv.dim[i]); + hash_combine(hash, mv.dim[i]); } std::unordered_map::const_iterator iter = hash_to_operator_cost.find(hash);