Skip to content

Commit

Permalink
[Code/Tests] CXX impl:
Browse files Browse the repository at this point in the history
- Add init options args parser
- Add testing utils
- Add basic tests
- Add gtest dep for unit-tests
  • Loading branch information
EgorOrachyov committed Feb 20, 2021
1 parent 37f8f60 commit ca5079c
Show file tree
Hide file tree
Showing 26 changed files with 1,047 additions and 69 deletions.
3 changes: 3 additions & 0 deletions .gitmodules
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
[submodule "deps/gtest"]
path = deps/gtest
url = https://github.com/google/googletest.git
8 changes: 6 additions & 2 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,11 @@ option(SPBLA_WITH_CPU_BACKEND "Build library with cpu backend as fallback" ON)
option(SPBLA_WITH_CUDA_BACKEND "Build library with cuda backend" OFF)
option(SPBLA_WITH_OPENCL_BACKEND "Build library with opencl backend" OFF)

# Make sure our own modules are found
list(APPEND CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake)
option(SPBLA_WITH_TESTS "Build library source code with provided unit tests" ON)

if (SPBLA_WITH_TESTS)
message(STATUS "Add gtest dependency for library unit tests")
add_subdirectory(deps/gtest)
endif()

add_subdirectory(spbla)
38 changes: 38 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# JetBrains Open Source and Community Code of Conduct

This code of conduct outlines our expectations for all those who participate in our
open source projects and communities (community programs), as well as the consequences
for unacceptable behaviour. We invite all those who participate to help us create safe
and positive experiences for everyone. Communities mirror the societies in which they
exist and positive action is essential to counteract the many forms of inequality and
abuses of power that exist in society.

## How to behave

The following behaviours are expected and requested of all community members:

- Participate in an authentic and active way. In doing so, you contribute to the health and longevity of this community.
- Exercise consideration, respect and empathy in your speech and actions. Remember, we have all been through different stages of learning when adopting technologies.
- Refrain from demeaning, discriminatory, or harassing behaviour and speech.
- Disagreements on things are fine, argumentative behaviour or trolling are not.

## How not to behave

- Do not perform threats of violence or use violent language directed against another person.
- Do not make jokes of sexist, racist, homophobic, transphobic, ableist or otherwise discriminatory nature, or use language of this nature.
- Do not post or display sexually explicit or violent material.
- Do not post or threaten to post other people’s personally identifying information ("doxing").
- Do not make personal insults, particularly those related to gender, sexual orientation, race, religion, or disability.
- Do not engage in sexual attention. This includes, sexualised comments or jokes and sexual advances.
- Do not advocate for, or encourage, any of the above behaviour.


Please take into account that online communities bring together people from many
different cultures and backgrounds. It's important to understand that sometimes
the combination of cultural differences and online interaction can lead to misunderstandings.
That is why having empathy is very important.

## Also

You can access original text at
[JetBrains Open Source and Community Code of Conduct](https://confluence.jetbrains.com/display/ALL/JetBrains+Open+Source+and+Community+Code+of+Conduct).
2 changes: 1 addition & 1 deletion LICENSE → LICENSE.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
MIT License
# MIT License

Copyright (c) 2021 JetBrains-Research

Expand Down
1 change: 1 addition & 0 deletions deps/gtest
Submodule gtest added at d9c309
91 changes: 56 additions & 35 deletions spbla/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,39 +6,48 @@ else()
project(spbla-cpp LANGUAGES CXX)
endif()

# Notify user about selected backend options
if (SPBLA_WITH_CPU_BACKEND)
message(STATUS "Add SuiteSparse based CPU backend as fallback")
endif()
if (SPBLA_WITH_CUDA_BACKEND)
message(STATUS "Add cuBool based CUDA backend for GPGPU computations")
endif()
if (SPBLA_WITH_OPENCL_BACKEND)
message(STATUS "Add clBool based OpenCL backend for GPGPU computations")
endif()

# Source code of the library
set(SPBLA_C_API_SOURCES
include/spbla/spbla.h
sources/spbla_Common.hpp
sources/spbla_Initialize.cpp
sources/spbla_Finalize.cpp
sources/spbla_Matrix_New.cpp
sources/spbla_Matrix_Free.cpp
sources/spbla_Matrix_Build.cpp
sources/spbla_Matrix_Extract.cpp
sources/spbla_Matrix_Nrows.cpp
sources/spbla_Matrix_Ncols.cpp
sources/spbla_Matrix_Nvals.cpp
sources/spbla_Matrix_EWiseAdd.cpp
sources/spbla_MxM.cpp
sources/spbla_Kronecker.cpp
)
include/spbla/spbla.h
sources/spbla_Common.hpp
sources/spbla_Initialize.cpp
sources/spbla_Finalize.cpp
sources/spbla_Matrix_New.cpp
sources/spbla_Matrix_Free.cpp
sources/spbla_Matrix_Build.cpp
sources/spbla_Matrix_Extract.cpp
sources/spbla_Matrix_Nrows.cpp
sources/spbla_Matrix_Ncols.cpp
sources/spbla_Matrix_Nvals.cpp
sources/spbla_Matrix_EWiseAdd.cpp
sources/spbla_MxM.cpp
sources/spbla_Kronecker.cpp)

# Generic backend interface
set(SPBLA_BACKEND_SOURCES
sources/backend/Backend.hpp
sources/backend/Matrix.hpp
)
sources/backend/Backend.hpp
sources/backend/Matrix.hpp)

# Source code for the library core (manages state and validates user input)
set(SPBLA_SOURCES
sources/core/Defines.hpp
sources/core/Exception.hpp
sources/core/Library.cpp
sources/core/Library.hpp
sources/core/Matrix.cpp
sources/core/Matrix.hpp
)
sources/core/Defines.hpp
sources/core/OptionsParser.hpp
sources/core/Exception.hpp
sources/core/Library.cpp
sources/core/Library.hpp
sources/core/Matrix.cpp
sources/core/Matrix.hpp)

set(SPBLA_CPU_SOURCES)
set(SPBLA_CUDA_SOURCES)
Expand All @@ -47,10 +56,10 @@ set(SPBLA_OPENCL_SOURCES)
# Specifics for SuiteSparse based backend
if (SPBLA_WITH_CPU_BACKEND)
set(SPBLA_CPU_SOURCES
sources/cpu/Matrix.cpp
sources/cpu/Matrix.hpp
sources/cpu/Backend.cpp
sources/cpu/Backend.hpp)
sources/cpu/Matrix.cpp
sources/cpu/Matrix.hpp
sources/cpu/Backend.cpp
sources/cpu/Backend.hpp)
endif()

# Specifics for Cuda (cuBool) based backend
Expand All @@ -64,12 +73,12 @@ if (SPBLA_WITH_OPENCL_BACKEND)
endif()

add_library(spbla SHARED
${SPBLA_SOURCES}
${SPBLA_C_API_SOURCES}
${SPBLA_BACKEND_SOURCES}
${SPBLA_CPU_SOURCES}
${SPBLA_CUDA_SOURCES}
${SPBLA_OPENCL_SOURCES})
${SPBLA_SOURCES}
${SPBLA_C_API_SOURCES}
${SPBLA_BACKEND_SOURCES}
${SPBLA_CPU_SOURCES}
${SPBLA_CUDA_SOURCES}
${SPBLA_OPENCL_SOURCES})

target_include_directories(spbla PUBLIC ${CMAKE_CURRENT_LIST_DIR}/include)
target_include_directories(spbla PRIVATE ${CMAKE_CURRENT_LIST_DIR}/sources)
Expand All @@ -82,10 +91,22 @@ set_target_properties(spbla PROPERTIES CXX_STANDARD 14)
set_target_properties(spbla PROPERTIES CXX_STANDARD_REQUIRED ON)

if (SPBLA_WITH_CPU_BACKEND)
# Add SuiteSparse dependency (fix link path in future)
add_library(SuiteSparse INTERFACE)
target_link_libraries(SuiteSparse INTERFACE graphblas)
target_link_directories(SuiteSparse INTERFACE /usr/local/lib)

target_link_libraries(spbla PRIVATE SuiteSparse)
target_compile_definitions(spbla PRIVATE SPBLA_WITH_CPU_BACKEND)
endif()

# Add unit tests for library cxx sources
if (SPBLA_WITH_TESTS)
add_library(testing INTERFACE)
target_include_directories(testing INTERFACE ${CMAKE_CURRENT_LIST_DIR}/utils/)
target_link_libraries(testing INTERFACE spbla)
target_link_libraries(testing INTERFACE gtest)

message(STATUS "Add spbla-cpp unit tests")
add_subdirectory(tests)
endif()
58 changes: 44 additions & 14 deletions spbla/include/spbla/spbla.h
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,38 @@ SPBLA_EXPORT typedef uint32_t spbla_Index;
SPBLA_EXPORT typedef struct spbla_Matrix_t* spbla_Matrix;

/**
* Initialize the library state before usage.
* No other library function must be called before this one.
* spbla_Finalize must be called as the last library function.
*
* @param backend
* Initialize function allows to provide hint to the library
* for preferred backend selection. Default backend selection strategy
* is following: cuda, opencl, cpu.
*
* @return
* Initialize function allows to pass init option directly to the
* backend. This options are formed as array of string.
* Prefix '-' used for options with value, '--' for options without values.
*
* @note Backend options:
* --CPU_IGNORE_FINALIZATION - do not finalize cpu backend (for testing purposes only)
*
* @param backend Preferred backend type. Pass SPBLA_BACKEND_DEFAULT as default value.
* @param optionsCount Number of the init options, passed to the backend
* @param options Actual array of the options, provided by the user
*
* @return Result info
*/
SPBLA_EXPORT SPBLA_API spbla_Info spbla_Initialize(
spbla_Backend backend
spbla_Backend backend,
spbla_Index optionsCount,
const char* const* options
);

/**
* Finalize the library state.
* Must be called as the last library function in the application.
*
* @return
* @return Result info
*/
SPBLA_EXPORT SPBLA_API spbla_Info spbla_Finalize(
);
Expand All @@ -125,7 +145,8 @@ SPBLA_EXPORT SPBLA_API spbla_Info spbla_Finalize(
* @param matrix
* @param nrows
* @param ncols
* @return
*
* @return Result info
*/
SPBLA_EXPORT SPBLA_API spbla_Info spbla_Matrix_New(
spbla_Matrix* matrix,
Expand All @@ -136,7 +157,8 @@ SPBLA_EXPORT SPBLA_API spbla_Info spbla_Matrix_New(
/**
*
* @param matrix
* @return
*
* @return Result info
*/
SPBLA_EXPORT SPBLA_API spbla_Info spbla_Matrix_Free(
spbla_Matrix* matrix
Expand All @@ -149,7 +171,8 @@ SPBLA_EXPORT SPBLA_API spbla_Info spbla_Matrix_Free(
* @param cols
* @param nvals
* @param hints
* @return
*
* @return Result info
*/
SPBLA_EXPORT SPBLA_API spbla_Info spbla_Matrix_Build(
spbla_Matrix matrix,
Expand All @@ -166,7 +189,8 @@ SPBLA_EXPORT SPBLA_API spbla_Info spbla_Matrix_Build(
* @param cols
* @param nvals
* @param hints
* @return
*
* @return Result info
*/
SPBLA_EXPORT SPBLA_API spbla_Info spbla_Matrix_Extract(
spbla_Matrix matrix,
Expand All @@ -180,7 +204,8 @@ SPBLA_EXPORT SPBLA_API spbla_Info spbla_Matrix_Extract(
*
* @param matrix
* @param nrows
* @return
*
* @return Result info
*/
SPBLA_EXPORT SPBLA_API spbla_Info spbla_Matrix_Nrows(
spbla_Matrix matrix,
Expand All @@ -191,7 +216,8 @@ SPBLA_EXPORT SPBLA_API spbla_Info spbla_Matrix_Nrows(
*
* @param matrix
* @param ncols
* @return
*
* @return Result info
*/
SPBLA_EXPORT SPBLA_API spbla_Info spbla_Matrix_Ncols(
spbla_Matrix matrix,
Expand All @@ -202,7 +228,8 @@ SPBLA_EXPORT SPBLA_API spbla_Info spbla_Matrix_Ncols(
*
* @param matrix
* @param nvals
* @return
*
* @return Result info
*/
SPBLA_EXPORT SPBLA_API spbla_Info spbla_Matrix_Nvals(
spbla_Matrix matrix,
Expand All @@ -214,7 +241,8 @@ SPBLA_EXPORT SPBLA_API spbla_Info spbla_Matrix_Nvals(
* @param result
* @param left
* @param right
* @return
*
* @return Result info
*/
SPBLA_EXPORT SPBLA_API spbla_Info spbla_Matrix_EWiseAdd(
spbla_Matrix result,
Expand All @@ -227,7 +255,8 @@ SPBLA_EXPORT SPBLA_API spbla_Info spbla_Matrix_EWiseAdd(
* @param result
* @param left
* @param right
* @return
*
* @return Result info
*/
SPBLA_EXPORT SPBLA_API spbla_Info spbla_MxM(
spbla_Matrix result,
Expand All @@ -240,7 +269,8 @@ SPBLA_EXPORT SPBLA_API spbla_Info spbla_MxM(
* @param result
* @param left
* @param right
* @return
*
* @return Result info
*/
SPBLA_EXPORT SPBLA_API spbla_Info spbla_Kronecker(
spbla_Matrix result,
Expand Down
4 changes: 2 additions & 2 deletions spbla/sources/backend/Backend.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@
#ifndef SPBLA_BACKEND_HPP
#define SPBLA_BACKEND_HPP

#include <string>
#include <core/OptionsParser.hpp>

namespace spbla {
namespace backend {
Expand All @@ -36,7 +36,7 @@ namespace spbla {
class Backend {
public:
virtual ~Backend() = default;
virtual void Initialize(uint32_t argc, const char* const *argv) = 0;
virtual void Initialize(const OptionsParser& options) = 0;
virtual bool IsInitialized() const = 0;
virtual void Finalize() = 0;
virtual class Matrix* CreateMatrix(size_t nrows, size_t ncols) = 0;
Expand Down
Loading

0 comments on commit ca5079c

Please sign in to comment.