Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/main' into MSM--acceleration
Browse files Browse the repository at this point in the history
  • Loading branch information
yshekel committed Jan 7, 2025
2 parents 079ecb8 + 56f406e commit 999d969
Show file tree
Hide file tree
Showing 32 changed files with 341 additions and 121 deletions.
2 changes: 1 addition & 1 deletion examples/c++/examples_utils.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,5 @@ void try_load_and_set_backend_device(int argc = 0, char** argv = nullptr)
return;
}

ICICLE_LOG_INFO << "Device " << selected_device << " is not available, falling back to CPU";
ICICLE_LOG_ERROR << "Device " << selected_device << " is not available, falling back to CPU";
}
23 changes: 16 additions & 7 deletions examples/rust/arkworks-icicle-conversions/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,24 +5,33 @@ edition = "2018"

[dependencies]
icicle-runtime = { path = "../../../wrappers/rust/icicle-runtime" }
icicle-core = { path = "../../../wrappers/rust/icicle-core"}
icicle-core = { path = "../../../wrappers/rust/icicle-core" }
icicle-bn254 = { path = "../../../wrappers/rust/icicle-curves/icicle-bn254" }
ark-bn254 = { version = "0.4.0"}
ark-ff = { version = "0.4.0" , features=["parallel"]}
ark-ec = { version = "0.4.0" , features=["parallel"]}
ark-bn254 = { version = "0.4.0" }
ark-ff = { version = "0.4.0", features = ["parallel"] }
ark-ec = { version = "0.4.0", features = ["parallel"] }
rand = "0.8"
rayon = "1.5"
clap = { version = "<=4.4.12", features = ["derive"] }

[features]
cuda = ["icicle-runtime/cuda_backend",
cuda = [
"icicle-runtime/cuda_backend",
"icicle-bn254/cuda_backend",
"icicle-bn254/no_ecntt",
"icicle-bn254/no_g2",
]

metal = ["icicle-runtime/metal_backend",
metal = [
"icicle-runtime/metal_backend",
"icicle-bn254/metal_backend",
"icicle-bn254/no_ecntt",
"icicle-bn254/no_g2",
]
]

vulkan = [
"icicle-runtime/vulkan_backend",
"icicle-bn254/vulkan_backend",
"icicle-bn254/no_ecntt",
"icicle-bn254/no_g2",
]
28 changes: 18 additions & 10 deletions examples/rust/hash-and-merkle/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,20 +4,28 @@ version = "0.1.0"
edition = "2018"

[dependencies]
hex = "0.4"
hex = "0.4"
clap = { version = "<=4.4.12", features = ["derive"] }
icicle-core = {path = "../../../wrappers/rust/icicle-core" }
icicle-runtime = {path = "../../../wrappers/rust/icicle-runtime" }
icicle-hash = {path = "../../../wrappers/rust/icicle-hash" }
icicle-babybear = {path = "../../../wrappers/rust/icicle-fields/icicle-babybear" }
icicle-core = { path = "../../../wrappers/rust/icicle-core" }
icicle-runtime = { path = "../../../wrappers/rust/icicle-runtime" }
icicle-hash = { path = "../../../wrappers/rust/icicle-hash" }
icicle-babybear = { path = "../../../wrappers/rust/icicle-fields/icicle-babybear" }

[features]
cuda = ["icicle-runtime/cuda_backend",
cuda = [
"icicle-runtime/cuda_backend",
"icicle-babybear/cuda_backend",
"icicle-hash/cuda_backend",
"icicle-hash/cuda_backend",
]

metal = ["icicle-runtime/metal_backend",
metal = [
"icicle-runtime/metal_backend",
"icicle-babybear/metal_backend",
"icicle-hash/metal_backend",
]
"icicle-hash/metal_backend",
]

vulkan = [
"icicle-runtime/vulkan_backend",
"icicle-babybear/vulkan_backend",
"icicle-hash/vulkan_backend",
]
18 changes: 14 additions & 4 deletions examples/rust/msm/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -11,16 +11,26 @@ icicle-bls12-377 = { path = "../../../wrappers/rust/icicle-curves/icicle-bls12-3
clap = { version = "<=4.4.12", features = ["derive"] }

[features]
cuda = ["icicle-runtime/cuda_backend",
cuda = [
"icicle-runtime/cuda_backend",
"icicle-bn254/cuda_backend",
"icicle-bn254/no_ecntt",
"icicle-bls12-377/cuda_backend",
"icicle-bls12-377/no_ecntt"
"icicle-bls12-377/no_ecntt",
]

metal = ["icicle-runtime/metal_backend",
metal = [
"icicle-runtime/metal_backend",
"icicle-bn254/metal_backend",
"icicle-bn254/no_ecntt",
"icicle-bls12-377/metal_backend",
"icicle-bls12-377/no_ecntt"
"icicle-bls12-377/no_ecntt",
]

vulkan = [
"icicle-runtime/vulkan_backend",
"icicle-bn254/vulkan_backend",
"icicle-bn254/no_ecntt",
"icicle-bls12-377/vulkan_backend",
"icicle-bls12-377/no_ecntt",
]
16 changes: 14 additions & 2 deletions examples/rust/ntt/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,8 @@ icicle-bls12-377 = { path = "../../../wrappers/rust/icicle-curves/icicle-bls12-3
clap = { version = "<=4.4.12", features = ["derive"] }

[features]
cuda = ["icicle-runtime/cuda_backend",
cuda = [
"icicle-runtime/cuda_backend",
"icicle-bn254/cuda_backend",
"icicle-bn254/no_ecntt",
"icicle-bn254/no_g2",
Expand All @@ -21,11 +22,22 @@ cuda = ["icicle-runtime/cuda_backend",
"icicle-bls12-377/no_g2",
]

metal = ["icicle-runtime/metal_backend",
metal = [
"icicle-runtime/metal_backend",
"icicle-bn254/metal_backend",
"icicle-bn254/no_ecntt",
"icicle-bn254/no_g2",
"icicle-bls12-377/metal_backend",
"icicle-bls12-377/no_ecntt",
"icicle-bls12-377/no_g2",
]

vulkan = [
"icicle-runtime/vulkan_backend",
"icicle-bn254/vulkan_backend",
"icicle-bn254/no_ecntt",
"icicle-bn254/no_g2",
"icicle-bls12-377/vulkan_backend",
"icicle-bls12-377/no_ecntt",
"icicle-bls12-377/no_g2",
]
22 changes: 16 additions & 6 deletions examples/rust/polynomials/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,16 +12,26 @@ icicle-babybear = { path = "../../../wrappers/rust/icicle-fields/icicle-babybear
clap = { version = "<=4.4.12", features = ["derive"] }

[features]
cuda = ["icicle-runtime/cuda_backend",
cuda = [
"icicle-runtime/cuda_backend",
"icicle-bn254/cuda_backend",
"icicle-bn254/no_ecntt",
"icicle-bn254/no_g2",
"icicle-bn254/no_ecntt",
"icicle-bn254/no_g2",
"icicle-babybear/cuda_backend",
]
metal = ["icicle-runtime/metal_backend",

metal = [
"icicle-runtime/metal_backend",
"icicle-bn254/metal_backend",
"icicle-bn254/no_ecntt",
"icicle-bn254/no_g2",
"icicle-bn254/no_ecntt",
"icicle-bn254/no_g2",
"icicle-babybear/metal_backend",
]

vulkan = [
"icicle-runtime/vulkan_backend",
"icicle-bn254/vulkan_backend",
"icicle-bn254/no_ecntt",
"icicle-bn254/no_g2",
"icicle-babybear/vulkan_backend",
]
26 changes: 20 additions & 6 deletions examples/rust/poseidon2/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@ version = "0.1.0"
edition = "2018"

[dependencies]
icicle-core = {path = "../../../wrappers/rust/icicle-core" }
icicle-runtime = {path = "../../../wrappers/rust/icicle-runtime" }
icicle-hash = {path = "../../../wrappers/rust/icicle-hash" }
icicle-babybear = {path = "../../../wrappers/rust/icicle-fields/icicle-babybear" }
icicle-m31 = {path = "../../../wrappers/rust/icicle-fields/icicle-m31" }
hex = "0.4"
icicle-core = { path = "../../../wrappers/rust/icicle-core" }
icicle-runtime = { path = "../../../wrappers/rust/icicle-runtime" }
icicle-hash = { path = "../../../wrappers/rust/icicle-hash" }
icicle-babybear = { path = "../../../wrappers/rust/icicle-fields/icicle-babybear" }
icicle-m31 = { path = "../../../wrappers/rust/icicle-fields/icicle-m31" }
hex = "0.4"
rand = "0.8"
clap = { version = "<=4.4.12", features = ["derive"] }

Expand All @@ -20,3 +20,17 @@ cuda = [
"icicle-babybear/cuda_backend",
"icicle-m31/cuda_backend",
]

metal = [
"icicle-runtime/metal_backend",
"icicle-hash/metal_backend",
"icicle-babybear/metal_backend",
"icicle-m31/metal_backend",
]

vulkan = [
"icicle-runtime/vulkan_backend",
"icicle-hash/vulkan_backend",
"icicle-babybear/vulkan_backend",
"icicle-m31/vulkan_backend",
]
57 changes: 6 additions & 51 deletions icicle/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -55,11 +55,13 @@ endif()
set(CMAKE_POSITION_INDEPENDENT_CODE ON)

# Build options
option(BUILD_TESTS "Build unit tests. Default=OFF" OFF)
option(BUILD_TESTS "Build unit test2s. Default=OFF" OFF)
# Backends: typically CPU is built into the frontend, the rest are DSOs loaded at runtime from installation
option(CPU_BACKEND "Build CPU backend. Default=ON" ON)
# TODO Yuval: consider decoupling backends from frontend build. Is that worth the effort?
# To enable building backends, use the following options: (note they are in private repos)
option(CUDA_BACKEND "Branch/commit to pull for CUDA backend or `local` if under icicle/backend/cuda. Default=OFF" OFF)
option(METAL_BACKEND "Branch/commit to pull for METAL backend or `local` if under icicle/backend/metal. Default=OFF" OFF)
option(VULKAN_BACKEND "Branch/commit to pull for VULKAN backend or `local` if under icicle/backend/vulkan. Default=OFF" OFF)

# features that some fields/curves have and some don't.
option(NTT "Build NTT" ON)
Expand Down Expand Up @@ -130,55 +132,8 @@ if (CPU_BACKEND)
add_subdirectory(backend/cpu)
endif()

if (CUDA_BACKEND)
string(TOLOWER "${CUDA_BACKEND}" CUDA_BACKEND_LOWER)
if (CUDA_BACKEND_LOWER STREQUAL "local")
# CUDA backend is local, no need to pull
message(STATUS "Adding CUDA backend from local path: icicle/backend/cuda")
add_subdirectory(backend/cuda)

# Set the compile definition for the backend build directory
add_compile_definitions(BACKEND_BUILD_DIR="${CMAKE_BINARY_DIR}/backend")
else()
set(CUDA_BACKEND_URL "[email protected]:ingonyama-zk/icicle-cuda-backend.git")

include(FetchContent)
message(STATUS "Fetching cuda backend from ${CUDA_BACKEND_URL}:${CUDA_BACKEND}")
FetchContent_Declare(
cuda_backend
GIT_REPOSITORY ${CUDA_BACKEND_URL}
GIT_TAG ${CUDA_BACKEND}
)
FetchContent_MakeAvailable(cuda_backend)
# Set the compile definition for the backend build directory
add_compile_definitions(BACKEND_BUILD_DIR="${CMAKE_BINARY_DIR}/_deps/cuda_backend-build")
endif()
endif()

if (METAL_BACKEND)
string(TOLOWER "${METAL_BACKEND}" METAL_BACKEND_LOWER)
if (METAL_BACKEND_LOWER STREQUAL "local")
# METAL backend is local, no need to pull
message(STATUS "Adding Metal backend from local path: icicle/backend/metal")
add_subdirectory(backend/metal)

# Set the compile definition for the backend build directory
add_compile_definitions(BACKEND_BUILD_DIR="${CMAKE_BINARY_DIR}/backend")
else()
set(METAL_BACKEND_URL "[email protected]:ingonyama-zk/icicle-metal-backend.git")

include(FetchContent)
message(STATUS "Fetching cuda backend from ${METAL_BACKEND_URL}:${METAL_BACKEND}")
FetchContent_Declare(
metal_backend
GIT_REPOSITORY ${METAL_BACKEND_URL}
GIT_TAG ${METAL_BACKEND}
)
FetchContent_MakeAvailable(metal_backend)
# Set the compile definition for the backend build directory
add_compile_definitions(BACKEND_BUILD_DIR="${CMAKE_BINARY_DIR}/_deps/metal_backend-build")
endif()
endif()
# Include and configure (for build) backends based on the backend options
include(cmake/backend_include.cmake)

if (BUILD_TESTS)
add_subdirectory(tests)
Expand Down
74 changes: 74 additions & 0 deletions icicle/cmake/backend_include.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
if (CUDA_BACKEND)
string(TOLOWER "${CUDA_BACKEND}" CUDA_BACKEND_LOWER)
if (CUDA_BACKEND_LOWER STREQUAL "local")
# CUDA backend is local, no need to pull
message(STATUS "Adding CUDA backend from local path: icicle/backend/cuda")
add_subdirectory(backend/cuda)

# Set the compile definition for the backend build directory
add_compile_definitions(BACKEND_BUILD_DIR="${CMAKE_BINARY_DIR}/backend")
else()
set(CUDA_BACKEND_URL "[email protected]:ingonyama-zk/icicle-cuda-backend.git")

include(FetchContent)
message(STATUS "Fetching cuda backend from ${CUDA_BACKEND_URL}:${CUDA_BACKEND}")
FetchContent_Declare(
cuda_backend
GIT_REPOSITORY ${CUDA_BACKEND_URL}
GIT_TAG ${CUDA_BACKEND}
)
FetchContent_MakeAvailable(cuda_backend)
# Set the compile definition for the backend build directory
add_compile_definitions(BACKEND_BUILD_DIR="${CMAKE_BINARY_DIR}/_deps/cuda_backend-build")
endif()
endif()

if (METAL_BACKEND)
string(TOLOWER "${METAL_BACKEND}" METAL_BACKEND_LOWER)
if (METAL_BACKEND_LOWER STREQUAL "local")
# METAL backend is local, no need to pull
message(STATUS "Adding Metal backend from local path: icicle/backend/metal")
add_subdirectory(backend/metal)

# Set the compile definition for the backend build directory
add_compile_definitions(BACKEND_BUILD_DIR="${CMAKE_BINARY_DIR}/backend")
else()
set(METAL_BACKEND_URL "[email protected]:ingonyama-zk/icicle-metal-backend.git")

include(FetchContent)
message(STATUS "Fetching cuda backend from ${METAL_BACKEND_URL}:${METAL_BACKEND}")
FetchContent_Declare(
metal_backend
GIT_REPOSITORY ${METAL_BACKEND_URL}
GIT_TAG ${METAL_BACKEND}
)
FetchContent_MakeAvailable(metal_backend)
# Set the compile definition for the backend build directory
add_compile_definitions(BACKEND_BUILD_DIR="${CMAKE_BINARY_DIR}/_deps/metal_backend-build")
endif()
endif()

if (VULKAN_BACKEND)
string(TOLOWER "${VULKAN_BACKEND}" VULKAN_BACKEND_LOWER)
if (VULKAN_BACKEND_LOWER STREQUAL "local")
# VULKAN backend is local, no need to pull
message(STATUS "Adding Vulkan backend from local path: icicle/backend/vulkan")
add_subdirectory(backend/vulkan)

# Set the compile definition for the backend build directory
add_compile_definitions(BACKEND_BUILD_DIR="${CMAKE_BINARY_DIR}/backend")
else()
set(VULKAN_BACKEND_URL "[email protected]:ingonyama-zk/icicle-vulkan-backend.git")

include(FetchContent)
message(STATUS "Fetching cuda backend from ${VULKAN_BACKEND_URL}:${VULKAN_BACKEND}")
FetchContent_Declare(
vulkan_backend
GIT_REPOSITORY ${VULKAN_BACKEND_URL}
GIT_TAG ${VULKAN_BACKEND}
)
FetchContent_MakeAvailable(vulkan_backend)
# Set the compile definition for the backend build directory
add_compile_definitions(BACKEND_BUILD_DIR="${CMAKE_BINARY_DIR}/_deps/vulkan-backend-build")
endif()
endif()
Loading

0 comments on commit 999d969

Please sign in to comment.