Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Koren/v3 msm #581

Merged
merged 61 commits into from
Aug 29, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
61 commits
Select commit Hold shift + click to select a range
80ed037
basic pipenger cpu works
Koren-Brand Jun 5, 2024
f178ad6
works with precompute factor
Koren-Brand Jun 9, 2024
d86b02f
Signed MSM works
Koren-Brand Jun 10, 2024
236c120
partial cmake commit
Koren-Brand Jun 10, 2024
8982196
reverted changes in test_curve_api from rebase with yuval's branch
Koren-Brand Jun 16, 2024
4db229b
montgomery works
Koren-Brand Jun 24, 2024
09bec30
Multithreaded p1 almost works but fails when prints are removed
Koren-Brand Jul 11, 2024
5c75b6d
multithreaded phase 1 works plus removed unnecessary initialization o…
Koren-Brand Jul 14, 2024
5c8cbfc
Phase 1 is multithreaded and works. Started writing multithreaded ver…
Koren-Brand Jul 29, 2024
9a179e9
fix formatting
Koren-Brand Jul 29, 2024
3de5508
commit before switching to work on one of the servers to compare cpu …
Koren-Brand Jul 30, 2024
fbd0b4e
added framework for generic small tasks thread pool that has yet to b…
Koren-Brand Aug 5, 2024
e8cb7e5
added framework for generic small tasks thread pool that has yet to b…
Koren-Brand Aug 5, 2024
cec0c38
added framework for generic small tasks thread pool that has yet to b…
Koren-Brand Aug 5, 2024
1d37343
Added pre-compute factor to cpu-msm test
Koren-Brand Aug 6, 2024
8c13382
fix: bug where wrong polynomial factory is used to construct polynomi…
yshekel Jul 30, 2024
4679729
rename template files to not format them
yshekel Jul 30, 2024
72bfcdc
fix rust examples calling load_backend() with removed param
yshekel Jul 30, 2024
67afbd0
minor update to rust poly example
yshekel Jul 30, 2024
94facf8
add runtime api to load backend from default installdir and use it ev…
yshekel Jul 31, 2024
7e463e1
add ntt benchmark for rust
yshekel Jul 31, 2024
83d05e6
simplify C++ examples by loading backend from default install dir
yshekel Jul 31, 2024
7377a69
fix rust bw761 curve missing ICICLE backend install path and fix exam…
yshekel Aug 1, 2024
42a5f99
add rust benchmark for msm
yshekel Aug 1, 2024
1064f27
add rust ntt benchmark for fields too
yshekel Aug 1, 2024
0b02d7e
add rust ecntt benchmark
yshekel Aug 1, 2024
8bbeae4
update ntt api to accept config by const
yshekel Aug 1, 2024
8db133b
move backend-specific-config to open part to avoid installing it
yshekel Aug 1, 2024
bded390
rename template files to not format them
yshekel Jul 30, 2024
57976e0
fix rust examples calling load_backend() with removed param
yshekel Jul 30, 2024
301c12b
minor update to rust poly example
yshekel Jul 30, 2024
db6a954
multiplier works
HadarIngonyama Aug 1, 2024
765dac7
add-sub 64 works
HadarIngonyama Aug 6, 2024
db68388
phase 2 and phase 3 now work though timing seems to have worsen for p…
Koren-Brand Aug 13, 2024
8b2fe22
All works with some optimizations
Koren-Brand Aug 18, 2024
885c2c2
Currently passing affine by reference is not possible efficiently as …
Koren-Brand Aug 18, 2024
2fb7cd0
weird duplicate lines removed
emirsoyturk Aug 18, 2024
7700032
Reverted Hadar's multiplier addition to the branch such that the cpu …
Koren-Brand Aug 19, 2024
9cbb3be
merge with yuval's branch
Koren-Brand Aug 19, 2024
fdaf97c
Merge remote-tracking branch 'origin/yshekel/V3' into Koren/V3_msm
Koren-Brand Aug 19, 2024
3da6f43
Final touch ups before PR - removed prints, TODOs etc
Koren-Brand Aug 19, 2024
97d8bb3
rust msm tests full size
Koren-Brand Aug 19, 2024
cabda59
Removing redundant files for PR
Koren-Brand Aug 19, 2024
18f231f
No need for copy in projective.h
Koren-Brand Aug 19, 2024
dccb3d9
format files
Koren-Brand Aug 19, 2024
382c106
fix G2 issues
Koren-Brand Aug 19, 2024
a66b4c9
Merge remote-tracking branch 'origin/yshekel/V3' into Koren/V3_msm
Koren-Brand Aug 19, 2024
993853e
fix formatting
Koren-Brand Aug 19, 2024
ada7289
access c via config, not ext
Koren-Brand Aug 19, 2024
c24a433
Currently MSM does not support a case where c divides scalar without …
Koren-Brand Aug 20, 2024
d11ca7b
Merge remote-tracking branch 'origin/yshekel/V3' into Koren/V3_msm
Koren-Brand Aug 20, 2024
03bc89f
Added c check to msm itself (before it was only in curve tester)
Koren-Brand Aug 20, 2024
ee94c08
fix potential divison by 0 when not specifying c in config
Koren-Brand Aug 20, 2024
f1593ef
Properly check nof_threads (and existence of config.ext) Also properl…
Koren-Brand Aug 25, 2024
e7e3f83
Merge remote-tracking branch 'origin/yshekel/V3' into Koren/V3_msm
Koren-Brand Aug 25, 2024
320a238
FIxed G2 bw-761 definition
Koren-Brand Aug 26, 2024
672d0eb
Merge remote-tracking branch 'origin/yshekel/V3' into Koren/V3_msm
Koren-Brand Aug 26, 2024
fe13b85
spelling and formatting
Koren-Brand Aug 26, 2024
97944ba
fixed config issues that failed in rust tests
Koren-Brand Aug 28, 2024
9f6f3a3
Merge remote-tracking branch 'origin/yshekel/V3' into Koren/V3_msm
Koren-Brand Aug 28, 2024
04be16e
removing limitations on msm size in rust tests
Koren-Brand Aug 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,4 @@
**/Cargo.lock
**/icicle/build/
**/wrappers/rust/icicle-cuda-runtime/src/bindings.rs
**/build/*
**/build/*
47 changes: 43 additions & 4 deletions icicle/backend/cpu/include/tasks_manager.h
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
#pragma once
#include <atomic>
#include <thread>
#include <stdexcept>
#include <cassert>

#define LOG_TASKS_PER_THREAD 3
Expand All @@ -13,7 +12,8 @@
/**
* @class TaskBase
* @brief abstract base for a task supported by `TasksManager`.
* Important
* Important - the user does not manually create these tasks - they are part of the manager and are accessed by the
* various get_task functions.
*/
class TaskBase
{
Expand Down Expand Up @@ -91,12 +91,19 @@ class TasksManager
*/
Task* get_idle_or_completed_task();

/**
* @brief Get idle task to be dispatched without handling previous results (As it holds no previous result). This is
* not a blocking function,
* @return Task* - pointer to an idle task. nullptr if no task is available (All are either running or completed).
*/
Task* get_idle_task();

/**
* @brief Get task that holds previous result to be handled by the user. This function blocks the code until a
* completed task is found or all tasks are idle with no result.
* @return Task* - pointer to a completed task. nullptr if no task is available (all are idle without results).
* NOTE: The task's status should be updated if new tasks are to be assigned / other completed tasks are requested.
* Use dispatch
* Use dispatch if setting a new task, or set_idle if to just mark the task result as handled.
*/
Task* get_completed_task();

Expand Down Expand Up @@ -140,9 +147,16 @@ class TasksManager
*/
Task* get_idle_or_completed_task();

/**
* @brief Get idle task to be dispatched without handling previous results (As it holds no previous result). This
* isn't a blocking function - it checks all worker's tasks and returns.
* @return Task* - pointer to an idle task. nullptr if no task is available.
*/
Task* get_idle_task();

/**
* @brief Get task that holds previous result to be handled by the user. This isn't a blocking function - it checks
* all worker's tasks and if no completed one is found a nullptr is returned.
* all worker's tasks and returns.
* @param is_idle - boolean flag indicating if all worker's tasks are idle.
* @return Task* - pointer to a completed task. nullptr if no task is available.
* NOTE: if using completed_task to assign additional tasks, the existing result must be handled before hand.
Expand Down Expand Up @@ -213,6 +227,17 @@ Task* TasksManager<Task>::Worker::get_idle_or_completed_task()
return nullptr;
}

template <class Task>
Task* TasksManager<Task>::Worker::get_idle_task()
{
for (int i = 0; i < m_tasks.size(); i++) {
m_next_task_idx = (1 + m_next_task_idx) & TASK_IDX_MASK;

if (m_tasks[m_next_task_idx].is_idle()) { return &m_tasks[m_next_task_idx]; }
}
return nullptr;
}

template <class Task>
Task* TasksManager<Task>::Worker::get_completed_task(bool& is_idle)
{
Expand Down Expand Up @@ -255,6 +280,20 @@ Task* TasksManager<Task>::get_idle_or_completed_task()
}
}

template <class Task>
Task* TasksManager<Task>::get_idle_task()
{
Task* idle_task = nullptr;
for (int i = 0; i < m_workers.size(); i++) {
m_next_worker_idx = (m_next_worker_idx < m_workers.size() - 1) ? m_next_worker_idx + 1 : 0;

idle_task = m_workers[m_next_worker_idx].get_idle_task();
if (idle_task != nullptr) { return idle_task; }
}
// No completed tasks were found in the loop - return null.
return nullptr;
}

template <class Task>
Task* TasksManager<Task>::get_completed_task()
{
Expand Down
44 changes: 7 additions & 37 deletions icicle/backend/cpu/src/curve/cpu_msm.cpp
Original file line number Diff line number Diff line change
@@ -1,43 +1,13 @@

#include "cpu_msm.hpp"
#include "icicle/backend/msm_backend.h"
#include "icicle/errors.h"
#include "icicle/runtime.h"

#include "icicle/curves/projective.h"
#include "icicle/curves/curve_config.h"
// This file's purpose is just to register the hpp functions to the Icicle API.

using namespace curve_config;
using namespace icicle;

template <typename S, typename A, typename P>
eIcicleError
cpu_msm(const Device& device, const S* scalars, const A* bases, int msm_size, const MSMConfig& config, P* results)
{
for (auto batch_idx = 0; batch_idx < config.batch_size; ++batch_idx) {
P res = P::zero();
const S* batch_scalars = scalars + msm_size * batch_idx;
const A* batch_bases = config.are_bases_shared ? bases : bases + msm_size * batch_idx;
for (auto i = 0; i < msm_size; ++i) {
res = res + P::from_affine(batch_bases[i]) * batch_scalars[i];
}
results[batch_idx] = res;
}
return eIcicleError::SUCCESS;
}

template <typename A>
eIcicleError cpu_msm_precompute_bases(
const Device& device, const A* input_bases, int nof_bases, const MSMConfig& config, A* output_bases)
{
ICICLE_ASSERT(!config.are_points_on_device && !config.are_scalars_on_device);
memcpy(output_bases, input_bases, sizeof(A) * nof_bases);
return eIcicleError::SUCCESS;
}

REGISTER_MSM_BACKEND("CPU", (cpu_msm<scalar_t, affine_t, projective_t>));
REGISTER_MSM_PRE_COMPUTE_BASES_BACKEND("CPU", cpu_msm_precompute_bases<affine_t>);
REGISTER_MSM_PRE_COMPUTE_BASES_BACKEND("CPU", (cpu_msm_precompute_bases<affine_t, projective_t>));
REGISTER_MSM_BACKEND("CPU", (cpu_msm<affine_t, projective_t>));

#ifdef G2
REGISTER_MSM_G2_BACKEND("CPU", (cpu_msm<scalar_t, g2_affine_t, g2_projective_t>));
REGISTER_MSM_G2_PRE_COMPUTE_BASES_BACKEND("CPU", cpu_msm_precompute_bases<g2_affine_t>);
#endif // G2
REGISTER_MSM_G2_PRE_COMPUTE_BASES_BACKEND("CPU", (cpu_msm_precompute_bases<g2_affine_t, g2_projective_t>));
REGISTER_MSM_G2_BACKEND("CPU", (cpu_msm<g2_affine_t, g2_projective_t>));
#endif
Loading
Loading