Skip to content

Commit

Permalink
formatting and spelling
Browse files Browse the repository at this point in the history
  • Loading branch information
HadarIngonyama committed Oct 31, 2024
1 parent d9a0b5f commit 9798073
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 50 deletions.
2 changes: 1 addition & 1 deletion examples/c++/vector-api/example.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
#include "icicle/utils/log.h"


// SP: I undertstand this code is auto-generated, but I can't get scrip/gen to work.
// SP: I understand this code is auto-generated, but I can't get script/gen to work.

extern "C" eIcicleError bn254_vector_product(
const bn254::scalar_t* vec_a, uint64_t n, const VecOpsConfig* config, bn254::scalar_t* result, uint64_t offset, uint64_t stride);
Expand Down
45 changes: 11 additions & 34 deletions icicle/backend/cpu/src/field/cpu_vec_ops.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,7 @@ class VectorOpTask : public TaskBase
}
}

// Single worker functionality for out of palce matrix transpose
// Single worker functionality for out of place matrix transpose
void out_of_place_transpose()
{
for (uint32_t k = 0; k < m_nof_operations; ++k) {
Expand Down Expand Up @@ -367,8 +367,8 @@ class VectorOpTask : public TaskBase

public:
T m_intermidiate_res; // pointer to the output. Can be a vector or scalar pointer
uint64_t m_idx_in_batch; // index in the batch. Used in intermidiate res tasks
}; // class VectorOpTask
uint64_t m_idx_in_batch; // index in the batch. Used in intermediate res tasks
}; // class VectorOpTask

#define NOF_OPERATIONS_PER_TASK 512
#define CONFIG_NOF_THREADS_KEY "n_threads"
Expand Down Expand Up @@ -401,12 +401,7 @@ cpu_2vectors_op(VecOperation op, const T* vec_a, const T* vec_b, uint64_t size,
// Execute a full task from the type vector = scalar (op) vector
template <typename T>
eIcicleError cpu_scalar_vector_op(
VecOperation op,
const T* scalar_a,
const T* vec_b,
uint64_t size,
const VecOpsConfig& config,
T* output)
VecOperation op, const T* scalar_a, const T* vec_b, uint64_t size, const VecOpsConfig& config, T* output)
{
TasksManager<VectorOpTask<T>> task_manager(get_nof_workers(config) - 1);
const uint64_t total_nof_operations = size;
Expand All @@ -416,11 +411,8 @@ eIcicleError cpu_scalar_vector_op(
VectorOpTask<T>* task_p = task_manager.get_idle_or_completed_task();
task_p->send_2ops_task(
op, std::min((uint64_t)NOF_OPERATIONS_PER_TASK, total_nof_operations - i), scalar_a + idx_in_batch,
config.columns_batch ? vec_b + idx_in_batch + i * config.batch_size
: vec_b + idx_in_batch * size + i,
stride,
config.columns_batch ? output + idx_in_batch + i * config.batch_size
: output + idx_in_batch * size + i);
config.columns_batch ? vec_b + idx_in_batch + i * config.batch_size : vec_b + idx_in_batch * size + i, stride,
config.columns_batch ? output + idx_in_batch + i * config.batch_size : output + idx_in_batch * size + i);
}
}
task_manager.wait_done();
Expand Down Expand Up @@ -590,12 +582,7 @@ REGISTER_VECTOR_PRODUCT_BACKEND("CPU", cpu_vector_product<scalar_t>);
/*********************************** Scalar + Vector***********************************/
template <typename T>
eIcicleError cpu_scalar_add(
const Device& device,
const T* scalar_a,
const T* vec_b,
uint64_t size,
const VecOpsConfig& config,
T* output)
const Device& device, const T* scalar_a, const T* vec_b, uint64_t size, const VecOpsConfig& config, T* output)
{
return cpu_scalar_vector_op(VecOperation::SCALAR_ADD_VEC, scalar_a, vec_b, size, config, output);
}
Expand All @@ -605,12 +592,7 @@ REGISTER_SCALAR_ADD_VEC_BACKEND("CPU", cpu_scalar_add<scalar_t>);
/*********************************** Scalar - Vector***********************************/
template <typename T>
eIcicleError cpu_scalar_sub(
const Device& device,
const T* scalar_a,
const T* vec_b,
uint64_t size,
const VecOpsConfig& config,
T* output)
const Device& device, const T* scalar_a, const T* vec_b, uint64_t size, const VecOpsConfig& config, T* output)
{
return cpu_scalar_vector_op(VecOperation::SCALAR_SUB_VEC, scalar_a, vec_b, size, config, output);
}
Expand All @@ -620,12 +602,7 @@ REGISTER_SCALAR_SUB_VEC_BACKEND("CPU", cpu_scalar_sub<scalar_t>);
/*********************************** MUL BY SCALAR***********************************/
template <typename T>
eIcicleError cpu_scalar_mul(
const Device& device,
const T* scalar_a,
const T* vec_b,
uint64_t size,
const VecOpsConfig& config,
T* output)
const Device& device, const T* scalar_a, const T* vec_b, uint64_t size, const VecOpsConfig& config, T* output)
{
return cpu_scalar_vector_op(VecOperation::SCALAR_MUL_VEC, scalar_a, vec_b, size, config, output);
}
Expand Down Expand Up @@ -669,7 +646,7 @@ uint32_t gcd(uint32_t a, uint32_t b)
return a;
}

// Recursive function to generate all k-ary necklaces and to replace the elements withing the necklaces
// Recursive function to generate all k-ary necklaces and to replace the elements within the necklaces
template <typename T>
void gen_necklace(
uint32_t t,
Expand Down Expand Up @@ -714,7 +691,7 @@ eIcicleError matrix_transpose_necklaces(
uint32_t gcd_value = gcd(log_nof_rows, log_nof_cols);
uint32_t k = 1 << gcd_value; // Base of necklaces
uint32_t length =
(log_nof_cols + log_nof_rows) / gcd_value; // length of necklaces. Since all are powers of 2, equvalent to
(log_nof_cols + log_nof_rows) / gcd_value; // length of necklaces. Since all are powers of 2, equivalent to
// (log_nof_cols + log_nof_rows) / gcd_value;
const uint64_t max_nof_operations = NOF_OPERATIONS_PER_TASK / length;
const uint64_t total_elements_one_mat = static_cast<uint64_t>(nof_rows) * nof_cols;
Expand Down
29 changes: 14 additions & 15 deletions icicle/tests/test_field_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
using namespace field_config;
using namespace icicle;

//TODO - add tests that test different configurations of data on device or on host.
// TODO - add tests that test different configurations of data on device or on host.

using FpMicroseconds = std::chrono::duration<float, std::chrono::microseconds::period>;
#define START_TIMER(timer) auto timer##_start = std::chrono::high_resolution_clock::now();
Expand Down Expand Up @@ -98,11 +98,11 @@ TYPED_TEST(FieldApiTest, vectorVectorOps)
const uint64_t N = 1 << (rand() % 15 + 3);
const int batch_size = 1 << (rand() % 5);
const bool columns_batch = rand() % 2;

ICICLE_LOG_DEBUG << "N = " << N;
ICICLE_LOG_DEBUG << "batch_size = " << batch_size;
ICICLE_LOG_DEBUG << "columns_batch = " << columns_batch;

const int total_size = N * batch_size;
auto in_a = std::make_unique<TypeParam[]>(total_size);
auto in_b = std::make_unique<TypeParam[]>(total_size);
Expand Down Expand Up @@ -148,7 +148,7 @@ TYPED_TEST(FieldApiTest, vectorVectorOps)
// accumulate
FieldApiTest<TypeParam>::random_samples(in_a.get(), total_size);
FieldApiTest<TypeParam>::random_samples(in_b.get(), total_size);
for (int i = 0; i < total_size; i++) { //TODO - compare gpu against cpu with inplace operations?
for (int i = 0; i < total_size; i++) { // TODO - compare gpu against cpu with inplace operations?
out_ref[i] = in_a[i] + in_b[i];
}
run(s_main_target, nullptr, VERBOSE /*=measure*/, vector_accumulate_wrapper, "vector accumulate", ITERS);
Expand Down Expand Up @@ -391,7 +391,7 @@ TYPED_TEST(FieldApiTest, scalarVectorOps)
run(s_reference_target, out_ref.get(), VERBOSE /*=measure*/, scalar_add_vec<TypeParam>, "scalar add vec", ITERS);
}
run(s_main_target, out_main.get(), VERBOSE /*=measure*/, scalar_add_vec<TypeParam>, "scalar add vec", ITERS);

ASSERT_EQ(0, memcmp(out_main.get(), out_ref.get(), total_size * sizeof(TypeParam)));

// scalar sub vec
Expand Down Expand Up @@ -436,12 +436,13 @@ TYPED_TEST(FieldApiTest, matrixAPIsAsync)
srand(seed);
ICICLE_LOG_DEBUG << "seed = " << seed;
const int R =
1 << (rand() % 8 + 2); // cpu implementation for out of place transpose also supports sizes wich are not powers of 2
1 << (rand() % 8 + 2); // cpu implementation for out of place transpose also supports sizes which are not powers of 2
const int C =
1 << (rand() % 8 + 2); // cpu implementation for out of place transpose also supports sizes wich are not powers of 2
1 << (rand() % 8 + 2); // cpu implementation for out of place transpose also supports sizes which are not powers of 2
const int batch_size = 1 << (rand() % 4);
const bool columns_batch = rand() % 2;
const bool is_in_place = s_is_cuda_registered? 0 : rand() % 2; //TODO - fix inplace (Hadar: I'm not sure we should support it)
const bool is_in_place =
s_is_cuda_registered ? 0 : rand() % 2; // TODO - fix inplace (Hadar: I'm not sure we should support it)

ICICLE_LOG_DEBUG << "rows = " << R;
ICICLE_LOG_DEBUG << "cols = " << C;
Expand Down Expand Up @@ -777,12 +778,12 @@ TYPED_TEST(FieldApiTest, polynomialEval)
const uint64_t domain_size = 1 << (rand() % 8 + 2);
const int batch_size = 1 << (rand() % 5);
const bool columns_batch = rand() % 2;

ICICLE_LOG_DEBUG << "coeffs_size = " << coeffs_size;
ICICLE_LOG_DEBUG << "domain_size = " << domain_size;
ICICLE_LOG_DEBUG << "batch_size = " << batch_size;
ICICLE_LOG_DEBUG << "columns_batch = " << columns_batch;

const int total_coeffs_size = coeffs_size * batch_size;

auto in_coeffs = std::make_unique<TypeParam[]>(total_coeffs_size);
Expand Down Expand Up @@ -815,10 +816,7 @@ TYPED_TEST(FieldApiTest, polynomialEval)
run(s_main_target, out_main.get(), VERBOSE /*=measure*/, "polynomial_eval", 1);
if (s_is_cuda_registered) {
run(s_reference_target, out_ref.get(), VERBOSE /*=measure*/, "polynomial_eval", 1);
ASSERT_EQ(
0, memcmp(
out_main.get(), out_ref.get(),
total_coeffs_size * sizeof(TypeParam)));
ASSERT_EQ(0, memcmp(out_main.get(), out_ref.get(), total_coeffs_size * sizeof(TypeParam)));
}
}

Expand Down Expand Up @@ -865,7 +863,8 @@ TYPED_TEST(FieldApiTest, polynomialEval)
// START_TIMER(polynomialDivision)
// for (int i = 0; i < iters; ++i) {
// ICICLE_CHECK(polynomial_division(
// numerator.get(), numerator_deg, total_numerator_size, denumerator.get(), denumerator_deg, total_denumerator_size, q_size, r_size, config, q_out, r_out));
// numerator.get(), numerator_deg, total_numerator_size, denumerator.get(), denumerator_deg,
// total_denumerator_size, q_size, r_size, config, q_out, r_out));
// }
// END_TIMER(polynomialDivision, oss.str().c_str(), measure);
// };
Expand Down
30 changes: 30 additions & 0 deletions icicle_v3/include/icicle/mmcs.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
#pragma once

#include "errors.h"
#include "runtime.h"
#include "hash.h"
#include "merkle_tree.h"
#include "icicle/utils/utils.h"

#include <cstdint>
#include <functional>


template <typename T>
struct Matrix {
T* values;
size_t width;
size_t height;
};

eIcicleError build_mmcs_tree(const Matrix<limb_t>* inputs,
const unsigned int number_of_inputs,
limb_t** outputs,
const Hash& hash,
const Hash& compression,
const MerkleTreeConfig& config);

//create hash <-hasher,compressor

//sort, and call merkle tree
//how to return outputs?

0 comments on commit 9798073

Please sign in to comment.