Skip to content

Commit

Permalink
icicle and backends are now shared libs
Browse files Browse the repository at this point in the history
  • Loading branch information
yshekel committed Jun 2, 2024
1 parent 706a960 commit 8c53b14
Show file tree
Hide file tree
Showing 9 changed files with 80 additions and 51 deletions.
10 changes: 6 additions & 4 deletions icicle_v3/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,15 +9,17 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
include(cmake/field.cmake)
include(cmake/curve.cmake)

set(CMAKE_POSITION_INDEPENDENT_CODE ON)

option(BUILD_TESTS "Build unit tests" OFF)
option(BUILD_CPU_BE "Build CPU backend" ON) # TODO Yuval remove from here once separating the backends from frontend
option(BUILD_CUDA_BE "Build CUDA backend" ON) # TODO Yuval remove from here once separating the backends from frontend

# device API library
add_library(icicle_device STATIC
src/device_api.cpp
src/errors.cpp
src/runtime.cpp
add_library(icicle_device SHARED
src/device_api.cpp
src/errors.cpp
src/runtime.cpp
)

# Add the include directory
Expand Down
12 changes: 6 additions & 6 deletions icicle_v3/backend/cpu/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,14 @@ set(CMAKE_CXX_STANDARD_REQUIRED True)
# TODO Yuval: handle incdir when backend is separated from frontend
# TODO Yuval: dll?

include_directories(${CMAKE_SOURCE_DIR}/include)

# device API library
add_library(icicle_cpu_device STATIC src/cpu_device_api.cpp)
add_library(icicle_cpu_device SHARED src/cpu_device_api.cpp)
target_link_libraries(icicle_cpu_device PUBLIC icicle_device)

# field API library
add_library(icicle_cpu_field STATIC
add_library(icicle_cpu_field SHARED
src/field/cpu_vec_ops.cpp
src/field/cpu_ntt.cpp
src/field/cpu_matrix_ops.cpp
Expand All @@ -23,8 +25,6 @@ target_link_libraries(icicle_cpu_field PUBLIC icicle_device icicle_field)
set_target_properties(icicle_cpu_field PROPERTIES OUTPUT_NAME "icicle_cpu_field_${FIELD}")

# curve API library
add_library(icicle_cpu_curve STATIC
src/curve/cpu_msm.cpp
)
add_library(icicle_cpu_curve SHARED src/curve/cpu_msm.cpp)
target_link_libraries(icicle_cpu_curve PUBLIC icicle_device icicle_curve)
set_target_properties(icicle_cpu_curve PROPERTIES OUTPUT_NAME "icicle_cpu_curve_${FIELD}")
set_target_properties(icicle_cpu_curve PROPERTIES OUTPUT_NAME "icicle_cpu_curve_${CURVE}")
2 changes: 1 addition & 1 deletion icicle_v3/backend/cuda/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ include_directories(include)

# TODO Yuval: handle incdir when backend is separated from frontend
# TODO Yuval: dll?
add_library(icicle_cuda_device STATIC src/cuda_device_api.cu)
add_library(icicle_cuda_device SHARED src/cuda_device_api.cu)
target_link_libraries(icicle_cuda_device PUBLIC icicle_device)
# Link to CUDA
target_include_directories(icicle_cuda_device PRIVATE ${CMAKE_CUDA_TOOLKIT_INCLUDE_DIRECTORIES})
Expand Down
6 changes: 2 additions & 4 deletions icicle_v3/cmake/curve.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,7 @@ function(check_curve)
math(EXPR I "${I} + 1")
if (CURVE STREQUAL SUPPORTED_CURVE)
add_compile_definitions(FIELD_ID=${I})
add_compile_definitions(DCURVE_ID=${I})
add_compile_definitions(FIELD=${CURVE})
add_compile_definitions(CURVE=${CURVE})
add_compile_definitions(CURVE_ID=${I})
set(IS_CURVE_SUPPORTED TRUE)
endif ()
endforeach()
Expand All @@ -23,7 +21,7 @@ function(setup_curve_target)
set(FIELD ${CURVE})
setup_field_target()

add_library(icicle_curve STATIC
add_library(icicle_curve SHARED
src/msm.cpp
)
set_target_properties(icicle_curve PROPERTIES OUTPUT_NAME "icicle_curve_${CURVE}")
Expand Down
2 changes: 1 addition & 1 deletion icicle_v3/cmake/field.cmake
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ function(check_field)
endfunction()

function(setup_field_target)
add_library(icicle_field STATIC
add_library(icicle_field SHARED
src/vec_ops.cpp
src/matrix_ops.cpp
src/ntt.cpp
Expand Down
59 changes: 24 additions & 35 deletions icicle_v3/tests/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@

message("icicle_fe tests enabled")
message("icicle_v3 tests enabled")

include(GoogleTest)
include(FetchContent)
Expand All @@ -15,58 +15,47 @@ FetchContent_MakeAvailable(googletest)

# Force load backend libraries even though they the symbols are not referenced by icicle or the app
# TODO Yuval: implement dynamic loading and avoid this compiler specific thing
message("CMAKE_CXX_COMPILER_ID=${CMAKE_CXX_COMPILER_ID}")
set(FORCE_LOAD_START "")
set(FORCE_LOAD_END "")
if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
set(FORCE_LOAD_START "-Wl,-force_load")
elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
set(FORCE_LOAD_START "-Wl,--whole-archive")
set(FORCE_LOAD_END "-Wl,--no-whole-archive")
else()
message(FATAL_ERROR "This CMake configuration only supports Clang and GCC.")
endif()
# message("CMAKE_CXX_COMPILER_ID=${CMAKE_CXX_COMPILER_ID}")
# set(FORCE_LOAD_START "")
# set(FORCE_LOAD_END "")
# if (CMAKE_CXX_COMPILER_ID STREQUAL "Clang" OR CMAKE_CXX_COMPILER_ID STREQUAL "AppleClang")
# set(FORCE_LOAD_START "-Wl,-force_load")
# elseif (CMAKE_CXX_COMPILER_ID STREQUAL "GNU")
# set(FORCE_LOAD_START "-Wl,--whole-archive")
# set(FORCE_LOAD_END "-Wl,--no-whole-archive")
# else()
# message(FATAL_ERROR "This CMake configuration only supports Clang and GCC.")
# endif()

# device API test
add_executable(test_device_api test_device_api.cpp)
target_include_directories(test_device_api PUBLIC ${CMAKE_SOURCE_DIR}/include/)
target_link_libraries(test_device_api PUBLIC GTest::gtest_main icicle_device)
# force loading the backend even when no symbols used. TODO Yuval: this is not compatible with windows
if(BUILD_CPU_BE)
target_link_libraries(test_device_api PRIVATE ${FORCE_LOAD_START} icicle_cpu_device ${FORCE_LOAD_END})
endif()
if(BUILD_CUDA_BE)
target_link_libraries(test_device_api PRIVATE ${FORCE_LOAD_START} icicle_cuda_device ${FORCE_LOAD_END})
endif()

#field API test
add_executable(test_field_api test_field_api.cpp)
target_include_directories(test_field_api PUBLIC ${CMAKE_SOURCE_DIR}/include/)
target_link_libraries(test_field_api PUBLIC GTest::gtest_main icicle_device icicle_field)
# force loading the backend even when no symbols used. TODO Yuval: this is not compatible with windows
if(BUILD_CPU_BE)
target_link_libraries(test_field_api PRIVATE ${FORCE_LOAD_START} icicle_cpu_device ${FORCE_LOAD_END})
target_link_libraries(test_field_api PRIVATE ${FORCE_LOAD_START} icicle_cpu_field ${FORCE_LOAD_END})
endif()
if(BUILD_CUDA_BE)
target_link_libraries(test_field_api PRIVATE ${FORCE_LOAD_START} icicle_cuda_device ${FORCE_LOAD_END})
target_link_libraries(test_field_api PRIVATE ${FORCE_LOAD_START} icicle_cuda_field ${FORCE_LOAD_END})
endif()

#curve API test
add_executable(test_curve_api test_curve_api.cpp)
target_include_directories(test_curve_api PUBLIC ${CMAKE_SOURCE_DIR}/include/)
target_link_libraries(test_curve_api PUBLIC GTest::gtest_main icicle_device icicle_curve)
# force loading the backend even when no symbols used. TODO Yuval: this is not compatible with windows
if(BUILD_CPU_BE)
target_link_libraries(test_curve_api PRIVATE ${FORCE_LOAD_START} icicle_cpu_device ${FORCE_LOAD_END})
target_link_libraries(test_curve_api PRIVATE ${FORCE_LOAD_START} icicle_cpu_curve ${FORCE_LOAD_END})


if(BUILD_CPU_BE)
target_link_libraries(test_device_api PUBLIC icicle_cpu_device dl)
target_link_libraries(test_field_api PUBLIC icicle_cpu_device icicle_cpu_field dl)
target_link_libraries(test_curve_api PUBLIC icicle_cpu_device icicle_cpu_curve dl)
endif()
if(BUILD_CUDA_BE)
target_link_libraries(test_curve_api PRIVATE ${FORCE_LOAD_START} icicle_cuda_device ${FORCE_LOAD_END})
target_link_libraries(test_curve_api PRIVATE ${FORCE_LOAD_START} icicle_cuda_curve ${FORCE_LOAD_END})

if(BUILD_CUDA_BE)
target_link_libraries(test_device_api PUBLIC icicle_cuda_device dl)
target_link_libraries(test_field_api PUBLIC icicle_cuda_device icicle_cuda_field dl)
target_link_libraries(test_curve_api PUBLIC icicle_cuda_device icicle_cuda_curve dl)
endif()


enable_testing()
gtest_discover_tests(test_device_api)
gtest_discover_tests(test_field_api)
Expand Down
17 changes: 17 additions & 0 deletions icicle_v3/tests/test_curve_api.cpp
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@

#include <gtest/gtest.h>
#include <iostream>
#include "dlfcn.h"

#include "icicle/runtime.h"
#include "icicle/curves/curve_config.h"

#include "dlfcn.h"

// using namespace curve_config;
using namespace icicle;

Expand All @@ -25,6 +28,20 @@ class CurveApiTest : public ::testing::Test
// SetUpTestSuite/TearDownTestSuite are called once for the entire test suite
static void SetUpTestSuite()
{
dlopen(
"/home/administrator/users/yuvals/icicle/icicle_v3/build/backend/cpu/libicicle_cpu_device.so",
RTLD_LAZY | RTLD_NOW);
dlopen(
"/home/administrator/users/yuvals/icicle/icicle_v3/build/backend/cpu/libicicle_cpu_curve_bn254.so",
RTLD_LAZY | RTLD_NOW);

dlopen(
"/home/administrator/users/yuvals/icicle/icicle_v3/build/backend/cuda/libicicle_cuda_device.so",
RTLD_LAZY | RTLD_NOW);
dlopen(
"/home/administrator/users/yuvals/icicle/icicle_v3/build/backend/cuda/libicicle_cuda_curve_bn254.so",
RTLD_LAZY | RTLD_NOW);

s_regsitered_devices = get_registered_devices();
ASSERT_GT(s_regsitered_devices.size(), 0);
}
Expand Down
8 changes: 8 additions & 0 deletions icicle_v3/tests/test_device_api.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
#include <iostream>

#include "icicle/runtime.h"
#include "dlfcn.h"

using namespace icicle;

Expand All @@ -13,6 +14,13 @@ class DeviceApiTest : public ::testing::Test
// SetUpTestSuite/TearDownTestSuite are called once for the entire test suite
static void SetUpTestSuite()
{
// dlopen(
// "/home/administrator/users/yuvals/icicle/icicle_v3/build/backend/cpu/libicicle_cpu_device.so",
// RTLD_LAZY | RTLD_NOW);
// dlopen(
// "/home/administrator/users/yuvals/icicle/icicle_v3/build/backend/cuda/libicicle_cuda_device.so",
// RTLD_LAZY | RTLD_NOW);

s_regsitered_devices = get_registered_devices();
ASSERT_GT(s_regsitered_devices.size(), 0);
}
Expand Down
15 changes: 15 additions & 0 deletions icicle_v3/tests/test_field_api.cpp
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@

#include <gtest/gtest.h>
#include <iostream>
#include "dlfcn.h"

#include "icicle/runtime.h"
#include "icicle/vec_ops.h"
Expand Down Expand Up @@ -29,6 +30,20 @@ class FieldApiTest : public ::testing::Test
// SetUpTestSuite/TearDownTestSuite are called once for the entire test suite
static void SetUpTestSuite()
{
dlopen(
"/home/administrator/users/yuvals/icicle/icicle_v3/build/backend/cpu/libicicle_cpu_device.so",
RTLD_LAZY | RTLD_NOW);
dlopen(
"/home/administrator/users/yuvals/icicle/icicle_v3/build/backend/cpu/libicicle_cpu_field_bn254.so",
RTLD_LAZY | RTLD_NOW);

dlopen(
"/home/administrator/users/yuvals/icicle/icicle_v3/build/backend/cuda/libicicle_cuda_device.so",
RTLD_LAZY | RTLD_NOW);
dlopen(
"/home/administrator/users/yuvals/icicle/icicle_v3/build/backend/cuda/libicicle_cuda_field_bn254.so",
RTLD_LAZY | RTLD_NOW);

s_regsitered_devices = get_registered_devices();
ASSERT_GT(s_regsitered_devices.size(), 0);
}
Expand Down

0 comments on commit 8c53b14

Please sign in to comment.