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

fix cuda test - remove boost #197

Merged
merged 4 commits into from
Sep 20, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
28 changes: 28 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Use the specified base image
FROM nvidia/cuda:12.0.0-devel-ubuntu22.04

# Update and install dependencies
RUN apt-get update && apt-get install -y \
cmake \
Copy link

@maciejskorski maciejskorski Sep 19, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

My two cents: although I suggested a Docker I think it would be good to implement it under a different PR because this requires some more testing?

protobuf-compiler \
curl \
build-essential \
&& rm -rf /var/lib/apt/lists/*

# Install Rust
RUN curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh -s -- -y
ENV PATH="/root/.cargo/bin:${PATH}"

# Install Golang
ENV GOLANG_VERSION 1.21.1
RUN curl -L https://golang.org/dl/go${GOLANG_VERSION}.linux-amd64.tar.gz | tar -xz -C /usr/local
ENV PATH="/usr/local/go/bin:${PATH}"

# Set the working directory in the container
WORKDIR /app

# Copy the content of the local directory to the working directory
COPY . .

# Specify the default command for the container
CMD ["/bin/bash"]
10 changes: 10 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -167,6 +167,16 @@ The script does the following:
- Creates a test file with the curve name in ``src``.

Testing the new curve could be done by running the tests in ``tests_curve_name`` (e.g. ``tests_bls12_381``).

## Docker

We offer a simple Docker container so you can simply run ICICLE without settig everything up locally.

```
docker build -t <name_of_your_choice> .
docker run --gpus all -it <name_of_your_choice> /bin/bash
```

## Contributions

Join our [Discord Server][DISCORD] and find us on the icicle channel. We will be happy to work together to support your use case and talk features, bugs and design.
Expand Down
4 changes: 3 additions & 1 deletion icicle/README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
# Tests
# ICICLE CUDA

## Running tests

```sh
mkdir -p build; cmake -S . -B build; cmake --build build; cd build && ctest; cd ..
Expand Down
97 changes: 0 additions & 97 deletions icicle/primitives/test.cu
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
#include "test_kernels.cuh"
#include <boost/multiprecision/cpp_int.hpp>
#include <cuda_runtime.h>
#include <gtest/gtest.h>
#include <iostream>
namespace mp = boost::multiprecision;

template <class T>
int device_populate_random(T* d_elements, unsigned n)
Expand All @@ -23,15 +21,6 @@ int device_set(T* d_elements, T el, unsigned n)
return cudaMemcpy(d_elements, h_elements, sizeof(T) * n, cudaMemcpyHostToDevice);
}

mp::int1024_t convert_to_boost_mp(uint32_t* a, uint32_t length)
{
mp::int1024_t res = 0;
for (uint32_t i = 0; i < length; i++) {
res += (mp::int1024_t)(a[i]) << 32 * i;
}
return res;
}

class PrimitivesTest : public ::testing::Test
{
protected:
Expand Down Expand Up @@ -406,92 +395,6 @@ TEST_F(PrimitivesTest, INGO_MP_MULT)
}
}

TEST_F(PrimitivesTest, INGO_MP_MSB_MULT)
vhnatyk marked this conversation as resolved.
Show resolved Hide resolved
{
// MSB multiply, take n msb bits of multiplication, assert that the error is up to 1.
ASSERT_EQ(ingo_mp_msb_mult(scalars1, scalars2, res_scalars_wide, n), cudaSuccess);
std::cout << "INGO MSB = 0x";
for (int i = 2 * scalar_field_t::TLC - 1; i >= 0; i--) {
std::cout << std::hex << res_scalars_wide[0].limbs_storage.limbs[i] << " ";
}
std::cout << std::endl;

ASSERT_EQ(mp_mult(scalars1, scalars2, res_scalars_wide_full), cudaSuccess);
std::cout << "ZKSYNC = 0x";
for (int i = 2 * scalar_field_t::TLC - 1; i >= 0; i--) {
std::cout << std::hex << res_scalars_wide_full[0].limbs_storage.limbs[i] << " ";
}

std::cout << std::endl;

// for (int i=scalar_field::TLC; i < 2*scalar_field::TLC - 1; i++)
// {
// ASSERT_EQ(in_bound, true);
// }
// for (int j=0; j<n; j++)
// {
// for (int i=0; i < 2*scalar_field::TLC - 1; i++)
// {
// ASSERT_EQ(res_scalars_wide_full[j].limbs_storage.limbs[i], res_scalars_wide[j].limbs_storage.limbs[i]);
// }
// }
// mp testing
mp::int1024_t scalar_1_mp = 0;
mp::int1024_t scalar_2_mp = 0;
mp::int1024_t res_mp = 0;
mp::int1024_t res_gpu = 0;
uint32_t num_limbs = scalar_field_t::TLC;

for (int j = 0; j < n; j++) {
uint32_t* scalar1_limbs = scalars1[j].limbs_storage.limbs;
uint32_t* scalar2_limbs = scalars2[j].limbs_storage.limbs;
scalar_1_mp = convert_to_boost_mp(scalar1_limbs, num_limbs);
scalar_2_mp = convert_to_boost_mp(scalar2_limbs, num_limbs);
res_mp = scalar_1_mp * scalar_2_mp;
res_mp = res_mp >> (num_limbs * 32);
res_gpu = convert_to_boost_mp(&(res_scalars_wide[j]).limbs_storage.limbs[num_limbs], num_limbs);
std::cout << "res mp = " << res_mp << std::endl;
std::cout << "res gpu = " << res_gpu << std::endl;
std::cout << "error = " << res_mp - res_gpu << std::endl;
bool upper_bound = res_gpu <= res_mp;
bool lower_bound = res_gpu > (res_mp - num_limbs);
bool in_bound = upper_bound && lower_bound;

ASSERT_EQ(in_bound, true);
}
}

TEST_F(PrimitivesTest, INGO_MP_MOD_MULT)
{
std::cout << " taking num limbs " << std::endl;
uint32_t num_limbs = scalar_field_t::TLC;
std::cout << " calling gpu... = " << std::endl;
ASSERT_EQ(ingo_mp_mod_mult(scalars1, scalars2, res_scalars1, n), cudaSuccess);
std::cout << " gpu call done " << std::endl;
// mp testing
mp::int1024_t scalar_1_mp = 0;
mp::int1024_t scalar_2_mp = 0;
mp::int1024_t res_mp = 0;
mp::int1024_t res_gpu = 0;
mp::int1024_t p = convert_to_boost_mp(scalar_field_t::get_modulus().limbs, num_limbs);
std::cout << " p = " << p << std::endl;

for (int j = 0; j < n; j++) {
uint32_t* scalar1_limbs = scalars1[j].limbs_storage.limbs;
uint32_t* scalar2_limbs = scalars2[j].limbs_storage.limbs;
scalar_1_mp = convert_to_boost_mp(scalar1_limbs, num_limbs);
scalar_2_mp = convert_to_boost_mp(scalar2_limbs, num_limbs);
// std::cout << " s1 = " << scalar_1_mp << std::endl;
// std::cout << " s2 = " << scalar_2_mp << std::endl;
res_mp = (scalar_1_mp * scalar_2_mp) % p;
res_gpu = convert_to_boost_mp((res_scalars1[j]).limbs_storage.limbs, num_limbs);
std::cout << "res mp = " << res_mp << std::endl;
std::cout << "res gpu = " << res_gpu << std::endl;
std::cout << "error = " << res_mp - res_gpu << std::endl;
ASSERT_EQ(res_gpu, res_mp);
}
}

TEST_F(PrimitivesTest, G2ECRandomPointsAreOnCurve)
{
for (unsigned i = 0; i < n; i++)
Expand Down
Loading