-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
(1) C++ template API that is backend (GPU, ZPU or other) agnostic (polynomials.h) (2) concrete CUDA implementation (polynomial_cuda_backend.cu/cuh) (3) C API for FFI (4) Groth16 example (test) (5) icicle library is now built for tests as well. Polynomial tests are linked to icicle lib.
- Loading branch information
Showing
27 changed files
with
3,154 additions
and
118 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
@startuml | ||
skinparam componentStyle uml2 | ||
|
||
' Define Components | ||
component "C++ Template\nComponent" as CppTemplate { | ||
[Parameterizable Interface] | ||
} | ||
component "C API Wrapper\nComponent" as CApiWrapper { | ||
[C API Interface] | ||
} | ||
component "Rust Code\nComponent" as RustCode { | ||
[Macro Interface\n(Template Instantiation)] | ||
} | ||
|
||
' Define Artifact | ||
artifact "Static Library\n«artifact»" as StaticLib | ||
|
||
' Connections | ||
CppTemplate -down-> CApiWrapper : Instantiates | ||
CApiWrapper .down.> StaticLib : Compiles into | ||
RustCode -left-> StaticLib : Links against\nand calls via FFI | ||
|
||
' Notes | ||
note right of CppTemplate : Generic C++\ntemplate implementation | ||
note right of CApiWrapper : Exposes C API for FFI\nto Rust/Go | ||
note right of RustCode : Uses macros to\ninstantiate templates | ||
@enduml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
@startuml | ||
|
||
' Define Interface for Polynomial Backend Operations | ||
interface IPolynomialBackend { | ||
+add() | ||
+subtract() | ||
+multiply() | ||
+divide() | ||
+evaluate() | ||
} | ||
|
||
' Define Interface for Polynomial Context (State Management) | ||
interface IPolynomialContext { | ||
+initFromCoeffs() | ||
+initFromEvals() | ||
+getCoeffs() | ||
+getEvals() | ||
} | ||
|
||
' PolynomialAPI now uses two strategies: Backend and Context | ||
class PolynomialAPI { | ||
-backendStrategy: IPolynomialBackend | ||
-contextStrategy: IPolynomialContext | ||
-setBackendStrategy(IPolynomialBackend) | ||
-setContextStrategy(IPolynomialContext) | ||
+add() | ||
+subtract() | ||
+multiply() | ||
+divide() | ||
+evaluate() | ||
} | ||
|
||
' Backend Implementations | ||
class GPUPolynomialBackend implements IPolynomialBackend { | ||
#gpuResources: Resource | ||
+add() | ||
+subtract() | ||
+multiply() | ||
+divide() | ||
+evaluate() | ||
} | ||
|
||
class ZPUPolynomialBackend implements IPolynomialBackend { | ||
#zpuResources: Resource | ||
+add() | ||
+subtract() | ||
+multiply() | ||
+divide() | ||
+evaluate() | ||
} | ||
|
||
class TracerPolynomialBackend implements IPolynomialBackend { | ||
#traceData: Data | ||
+add() | ||
+subtract() | ||
+multiply() | ||
+divide() | ||
+evaluate() | ||
} | ||
|
||
' Context Implementations (Placeholder for actual implementation) | ||
class GPUContext implements IPolynomialContext { | ||
+initFromCoeffs() | ||
+initFromEvals() | ||
+getCoeffs() | ||
+getEvals() | ||
} | ||
|
||
class ZPUContext implements IPolynomialContext { | ||
+initFromCoeffs() | ||
+initFromEvals() | ||
+getCoeffs() | ||
+getEvals() | ||
} | ||
|
||
class TracerContext implements IPolynomialContext { | ||
+initFromCoeffs() | ||
+initFromEvals() | ||
+getCoeffs() | ||
+getEvals() | ||
} | ||
|
||
' Relationships | ||
PolynomialAPI o-- IPolynomialBackend : uses | ||
PolynomialAPI o-- IPolynomialContext : uses | ||
@enduml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,59 @@ | ||
cmake_minimum_required(VERSION 3.18) | ||
|
||
project(icicle LANGUAGES CUDA CXX) | ||
|
||
include(cmake/Common.cmake) | ||
include(cmake/FieldsCommon.cmake) | ||
include(cmake/CurvesCommon.cmake) | ||
|
||
set_env() | ||
set_gpu_env() | ||
|
||
project(icicle LANGUAGES CUDA CXX) | ||
|
||
option(DEVMODE "Enable development mode" OFF) | ||
if (DEVMODE) | ||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -O0 --ptxas-options=-O0 --ptxas-options=-allow-expensive-optimizations=false -DDEVMODE=ON") | ||
endif () | ||
option(EXT_FIELD "Build extension field" OFF) | ||
option(G2 "Build G2" OFF) | ||
option(ECNTT "Build ECNTT" OFF) | ||
option(BUILD_HASH "Build hash functions" OFF) | ||
option(BUILD_TESTS "Build unit tests" OFF) | ||
option(BUILD_BENCHMARKS "Build benchmarks" OFF) | ||
# add options here | ||
|
||
if((DEFINED CURVE) AND (DEFINED FIELD)) | ||
message( FATAL_ERROR "CURVE and FIELD cannot be defined at the same time" ) | ||
endif () | ||
|
||
option(EXT_FIELD "Build extension field" OFF) | ||
if (DEVMODE) | ||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -O0 --ptxas-options=-O0 --ptxas-options=-allow-expensive-optimizations=false -DDEVMODE=ON") | ||
endif () | ||
|
||
if(DEFINED FIELD) | ||
check_field() | ||
add_subdirectory(src/fields) | ||
endif () | ||
|
||
option(G2 "Build G2" OFF) | ||
option(ECNTT "Build ECNTT" OFF) | ||
if(DEFINED CURVE) | ||
check_curve() | ||
set(FIELD ${CURVE}) | ||
add_subdirectory(src/fields) | ||
add_subdirectory(src/curves) | ||
endif () | ||
|
||
option(BUILD_HASH "Build hash functions" OFF) | ||
if (G2) | ||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -DG2") | ||
endif () | ||
|
||
if (EXT_FIELD) | ||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -DEXT_FIELD") | ||
endif () | ||
|
||
if(BUILD_HASH) | ||
add_subdirectory(src/hash) | ||
endif () | ||
endif () | ||
|
||
if (BUILD_TESTS) | ||
add_subdirectory(tests) | ||
endif() | ||
|
||
if (BUILD_BENCHMARKS) | ||
add_subdirectory(benchmarks) | ||
endif() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,31 +1,5 @@ | ||
cmake_minimum_required(VERSION 3.18) | ||
|
||
include(../cmake/Common.cmake) | ||
include(../cmake/CurvesCommon.cmake) | ||
include(../cmake/FieldsCommon.cmake) | ||
|
||
set_env() | ||
set_gpu_env() | ||
|
||
project(icicle_benchmarks LANGUAGES CUDA CXX) | ||
|
||
if(DEFINED CURVE) | ||
if(DEFINED FIELD) | ||
message( FATAL_ERROR "CURVE and FIELD cannot be defined at the same time" ) | ||
endif () | ||
check_curve() | ||
elseif(DEFINED FIELD) | ||
if (EXT_FIELD) | ||
set(CMAKE_CUDA_FLAGS "${CMAKE_CUDA_FLAGS} -DEXT_FIELD") | ||
endif () | ||
check_field() | ||
endif () | ||
|
||
add_executable( | ||
benches | ||
benches.cu | ||
) | ||
|
||
add_executable(benches benches.cu) | ||
target_link_libraries(benches benchmark::benchmark) | ||
|
||
target_include_directories(benches PUBLIC ${CMAKE_SOURCE_DIR}/include/) | ||
find_package(benchmark REQUIRED) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
icicle/include/polynomials/cuda_backend/polynomial_cuda_backend.cuh
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
#pragma once | ||
|
||
#include "gpu-utils/device_context.cuh" | ||
#include "fields/field_config.cuh" | ||
#include "polynomials/polynomials.h" | ||
|
||
using device_context::DeviceContext; | ||
|
||
namespace polynomials { | ||
template <typename C = scalar_t, typename D = C, typename I = C> | ||
class CUDAPolynomialFactory : public AbstractPolynomialFactory<C, D, I> | ||
{ | ||
std::vector<DeviceContext> m_device_contexts; // device-id --> device context | ||
std::vector<cudaStream_t> m_device_streams; // device-id --> device stream. Storing the streams here as workaround | ||
// since DeviceContext has a reference to a stream. | ||
|
||
public: | ||
CUDAPolynomialFactory(); | ||
~CUDAPolynomialFactory(); | ||
std::shared_ptr<IPolynomialContext<C, D, I>> create_context() override; | ||
std::shared_ptr<IPolynomialBackend<C, D, I>> create_backend() override; | ||
}; | ||
} // namespace polynomials |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
#pragma once | ||
|
||
#include "polynomial_context.h" | ||
#include "polynomial_backend.h" | ||
#include <memory> // For std::shared_ptr | ||
|
||
namespace polynomials { | ||
|
||
/** | ||
* @brief Abstract factory for creating polynomial contexts and backends. | ||
* | ||
* The `AbstractPolynomialFactory` serves as an interface for factories capable of creating | ||
* instances of `IPolynomialContext` and `IPolynomialBackend`. This design allows for the | ||
* decoupling of object creation from their usage, facilitating the implementation of various | ||
* computational strategies (e.g., GPU, ZPU) without altering client code. Each concrete factory | ||
* is expected to provide tailored implementations of polynomial contexts and backends that | ||
* are optimized for specific computational environments. | ||
* | ||
* @tparam C Type of the coefficients. | ||
* @tparam D Domain type, representing the input space of the polynomial. | ||
* @tparam I Image type, representing the output space of the polynomial. | ||
*/ | ||
template <typename C, typename D, typename I> | ||
class AbstractPolynomialFactory | ||
{ | ||
public: | ||
/** | ||
* @brief Creates and returns a shared pointer to an `IPolynomialContext` instance. | ||
* | ||
* @return std::shared_ptr<IPolynomialContext<C, D, I>> A shared pointer to the created | ||
* polynomial context instance. | ||
*/ | ||
virtual std::shared_ptr<IPolynomialContext<C, D, I>> create_context() = 0; | ||
|
||
/** | ||
* @brief Creates and returns a shared pointer to an `IPolynomialBackend` instance. | ||
* | ||
* @return std::shared_ptr<IPolynomialBackend<C, D, I>> A shared pointer to the created | ||
* polynomial backend instance. | ||
*/ | ||
virtual std::shared_ptr<IPolynomialBackend<C, D, I>> create_backend() = 0; | ||
|
||
/** | ||
* @brief Virtual destructor for the `AbstractPolynomialFactory`. | ||
*/ | ||
virtual ~AbstractPolynomialFactory() = default; | ||
}; | ||
|
||
} // namespace polynomials |
Oops, something went wrong.