From f61d738fda559903a0429defdc037ed518febb1f Mon Sep 17 00:00:00 2001 From: mickeyasa <100796045+mickeyasa@users.noreply.github.com> Date: Mon, 13 Jan 2025 17:57:43 +0200 Subject: [PATCH 1/2] pass compilation --- icicle/backend/cpu/src/field/cpu_vec_ops.cpp | 39 ++++++++++++++------ 1 file changed, 28 insertions(+), 11 deletions(-) diff --git a/icicle/backend/cpu/src/field/cpu_vec_ops.cpp b/icicle/backend/cpu/src/field/cpu_vec_ops.cpp index 496621c31..147253391 100644 --- a/icicle/backend/cpu/src/field/cpu_vec_ops.cpp +++ b/icicle/backend/cpu/src/field/cpu_vec_ops.cpp @@ -10,6 +10,7 @@ #include #include +#include "taskflow/taskflow.hpp" #include "icicle/program/program.h" #include "cpu_program_executor.h" @@ -852,20 +853,36 @@ eIcicleError cpu_execute_program( << " parameters"; return eIcicleError::INVALID_ARGUMENT; } + tf::Taskflow taskflow; // Accumulate tasks + tf::Executor executor; // execute all tasks accumulated on multiple threads const uint64_t total_nof_operations = size * config.batch_size; - CpuProgramExecutor prog_executor(program); - // init prog_executor to point to data vectors - for (int param_idx = 0; param_idx < program.m_nof_parameters; ++param_idx) { - prog_executor.m_variable_ptrs[param_idx] = data[param_idx]; - } + + // Divide the problem to workers + const int nof_workers = get_nof_workers(config); + const uint64_t worker_task_size = (total_nof_operations + nof_workers - 1) / nof_workers; // round up + + for (uint64_t start_idx = 0; start_idx < total_nof_operations; start_idx+=worker_task_size) { + taskflow.emplace([=]() { + CpuProgramExecutor prog_executor(program); + // init prog_executor to point to data vectors + for (int param_idx = 0; param_idx < program.m_nof_parameters; ++param_idx) { + prog_executor.m_variable_ptrs[param_idx] = &(data[param_idx][start_idx]); + } - // run over all elements in the arrays and execute the program - for (uint64_t i = 0; i < total_nof_operations; i++) { - prog_executor.execute(); - for (int param_idx = 0; param_idx < program.m_nof_parameters; ++param_idx) { - (prog_executor.m_variable_ptrs[param_idx])++; - } + const uint64_t task_size = std::min(worker_task_size, total_nof_operations-start_idx); + // run over all task elements in the arrays and execute the program + for (uint64_t i = 0; i < task_size; i++) { + prog_executor.execute(); + // update the program pointers + for (int param_idx = 0; param_idx < program.m_nof_parameters; ++param_idx) { + (prog_executor.m_variable_ptrs[param_idx])++; + } + } + }); } + + executor.run(taskflow).wait(); + taskflow.clear(); return eIcicleError::SUCCESS; } From d6004b3927ff05c7b346464d3250bdf295ca943b Mon Sep 17 00:00:00 2001 From: mickeyasa <100796045+mickeyasa@users.noreply.github.com> Date: Tue, 14 Jan 2025 05:11:40 +0200 Subject: [PATCH 2/2] format --- icicle/backend/cpu/src/field/cpu_vec_ops.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/icicle/backend/cpu/src/field/cpu_vec_ops.cpp b/icicle/backend/cpu/src/field/cpu_vec_ops.cpp index 147253391..38d859e02 100644 --- a/icicle/backend/cpu/src/field/cpu_vec_ops.cpp +++ b/icicle/backend/cpu/src/field/cpu_vec_ops.cpp @@ -853,15 +853,15 @@ eIcicleError cpu_execute_program( << " parameters"; return eIcicleError::INVALID_ARGUMENT; } - tf::Taskflow taskflow; // Accumulate tasks - tf::Executor executor; // execute all tasks accumulated on multiple threads + tf::Taskflow taskflow; // Accumulate tasks + tf::Executor executor; // execute all tasks accumulated on multiple threads const uint64_t total_nof_operations = size * config.batch_size; - + // Divide the problem to workers const int nof_workers = get_nof_workers(config); const uint64_t worker_task_size = (total_nof_operations + nof_workers - 1) / nof_workers; // round up - - for (uint64_t start_idx = 0; start_idx < total_nof_operations; start_idx+=worker_task_size) { + + for (uint64_t start_idx = 0; start_idx < total_nof_operations; start_idx += worker_task_size) { taskflow.emplace([=]() { CpuProgramExecutor prog_executor(program); // init prog_executor to point to data vectors @@ -869,7 +869,7 @@ eIcicleError cpu_execute_program( prog_executor.m_variable_ptrs[param_idx] = &(data[param_idx][start_idx]); } - const uint64_t task_size = std::min(worker_task_size, total_nof_operations-start_idx); + const uint64_t task_size = std::min(worker_task_size, total_nof_operations - start_idx); // run over all task elements in the arrays and execute the program for (uint64_t i = 0; i < task_size; i++) { prog_executor.execute();