Skip to content

Commit

Permalink
gh-213: impl new array primitive for data exchange
Browse files Browse the repository at this point in the history
  • Loading branch information
EgorOrachyov committed Aug 27, 2023
1 parent 1734621 commit ea2c4f3
Show file tree
Hide file tree
Showing 50 changed files with 787 additions and 198 deletions.
5 changes: 4 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -271,6 +271,7 @@ add_library(spla SHARED
# C++ core
include/spla.hpp
include/spla/algorithm.hpp
include/spla/array.hpp
include/spla/config.hpp
include/spla/descriptor.hpp
include/spla/exec.hpp
Expand All @@ -293,6 +294,7 @@ add_library(spla SHARED
src/core/logger.hpp
src/core/registry.cpp
src/core/registry.hpp
src/core/tarray.hpp
src/core/tdecoration.hpp
src/core/tmatrix.hpp
src/core/top.hpp
Expand Down Expand Up @@ -331,12 +333,13 @@ add_library(spla SHARED
src/util/pair_hash.hpp
src/profiling/time_profiler.cpp
src/profiling/time_profiler.hpp
src/algorithm.cpp
src/array.cpp
src/descriptor.cpp
src/io.cpp
src/exec.cpp
src/library.cpp
src/matrix.cpp
src/algorithm.cpp
src/op.cpp
src/scalar.cpp
src/schedule.cpp
Expand Down
2 changes: 1 addition & 1 deletion examples/convert.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/**********************************************************************************/
/* MIT License */
/* */
/* Copyright (c) 2021 JetBrains-Research */
/* Copyright (c) 2023 SparseLinearAlgebra */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining a copy */
/* of this software and associated documentation files (the "Software"), to deal */
Expand Down
2 changes: 1 addition & 1 deletion examples/pi.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
/**********************************************************************************/
/* MIT License */
/* */
/* Copyright (c) 2021 JetBrains-Research */
/* Copyright (c) 2023 SparseLinearAlgebra */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining a copy */
/* of this software and associated documentation files (the "Software"), to deal */
Expand Down
199 changes: 68 additions & 131 deletions include/spla.h
Original file line number Diff line number Diff line change
Expand Up @@ -30,20 +30,9 @@

/**
* @file spla.h
* @author Egor Orachev
*
* @brief Spla library C++ API bindings for C language
*
* This file contains:
*
* - Status and error codes
* - Optional functions hint flags
* - Library initialization/finalization API
* - Accelerator API
* - Matrix manipulation API
* - Vector manipulation API
* - Schedule operations API
*
* @see Source code: https://github.com/SparseLinearAlgebra/spla
* @see Python Reference API: https://SparseLinearAlgebra.github.io/spla/docs-python/spla
* @see C/C++ Reference API: https://SparseLinearAlgebra.github.io/spla/docs-cpp
Expand All @@ -69,148 +58,96 @@
extern "C" {
#endif

/**
* @brief Status of library operation execution
*/
typedef enum spla_Status {
/** No error */
SPLA_STATUS_OK = 0,
/** Some error occurred */
SPLA_STATUS_ERROR = 1,
/** Library has no configured accelerator for computations */
SPLA_STATUS_NO_ACCELERATION = 2,
/** Accelerator platform not found */
SPLA_STATUS_OK = 0,
SPLA_STATUS_ERROR = 1,
SPLA_STATUS_NO_ACCELERATION = 2,
SPLA_STATUS_PLATFORM_NOT_FOUND = 3,
/** Accelerator device not found */
SPLA_STATUS_DEVICE_NOT_FOUND = 4,
/** Call of the function is not possible for some context */
SPLA_STATUS_INVALID_STATE = 5,
/** Passed invalid argument for some function */
SPLA_STATUS_INVALID_ARGUMENT = 6,
/** No such requested value in matrix, vector or scalar storage */
SPLA_STATUS_NO_VALUE = 7,
/** Some library feature is not implemented */
SPLA_STATUS_NOT_IMPLEMENTED = 1024
SPLA_STATUS_DEVICE_NOT_FOUND = 4,
SPLA_STATUS_INVALID_STATE = 5,
SPLA_STATUS_INVALID_ARGUMENT = 6,
SPLA_STATUS_NO_VALUE = 7,
SPLA_STATUS_NOT_IMPLEMENTED = 1024
} spla_Status;

/**
* @brief Types of supported accelerators for computations
*/
typedef enum spla_AcceleratorType {
/** No acceleration to be used */
SPLA_ACCELERATOR_TYPE_NONE = 0,
/** OpenCL-based single device acceleration */
SPLA_ACCELERATOR_TYPE_NONE = 0,
SPLA_ACCELERATOR_TYPE_OPENCL = 1
} spla_AcceleratorType;

/**
* @brief Null handle, used to mark empty spla object
*/
#define SPLA_NULL_HND NULL

/**
* @brief Handle to any spla object
*/
typedef struct spla_Object_t* spla_Object;

/**
* @brief Handle to spla descriptor object
*/
typedef struct spla_Descriptor_t* spla_Descriptor;

/**
* @brief Handle to spla matrix primitive
*/
typedef struct spla_Matrix_t* spla_Matrix;
typedef uint32_t spla_uint;

/**
* @brief Handle to spla vector primitive
*/
typedef struct spla_Vector_t* spla_Vector;

/**
* @brief Handle to spla schedule object
*/
typedef struct spla_Schedule_t* spla_Schedule;

/**
* @brief Handle to spla schedule node object
*/
typedef struct spla_Object_t* spla_Object;
typedef struct spla_Type_t* spla_Type;
typedef struct spla_Descriptor_t* spla_Descriptor;
typedef struct spla_Matrix_t* spla_Matrix;
typedef struct spla_Vector_t* spla_Vector;
typedef struct spla_Array_t* spla_Array;
typedef struct spla_Scalar_t* spla_Scalar;
typedef struct spla_Schedule_t* spla_Schedule;
typedef struct spla_ScheduleTask_t* spla_ScheduleTask;
typedef struct spla_OpUnary_t* spla_OpUnary;
typedef struct spla_OpBinary_t* spla_OpBinary;
typedef struct spla_OpSelect_t* spla_OpSelect;

/**
* @brief Callback function called on library message event
*/
typedef void(spla_MessageCallback)(spla_Status, const char* message, const char* file, const char* function, int line, void* p_user_data);

/**
* @brief Finalize library execution
*
* Finalize method must be called at the end after application
* to correctly shutdown global library state, release any
* enabled acceleration device and release any pending device resources.
*
* @warning Must be called after application execution
* @warning After this call no other library function call is allowed
*/
SPLA_API void spla_Library_finalize();

/**
* @brief Set accelerator to be used in library computations
*
* Sets type of the accelerator to be used in library computations.
* By default library attempts automatically init OpenCL accelerator
* if OpenCL runtime present in the system. Set `None` to disable acceleration.
*
* @param accelerator Accelerate type
*
* @return Function call status
*/
SPLA_API void spla_Library_finalize();
SPLA_API spla_Status spla_Library_set_accelerator(spla_AcceleratorType accelerator);

/**
* @brief Selects platform for computations for current accelerator
*
* @param index Platform index to select in current PC supported list.
*
* @return Function call status
*/
SPLA_API spla_Status spla_Library_set_platform(int index);

/**
* @brief Selects device for computations for current accelerator
*
* @param index Device index in current platform devices
*
* @return Function call status
*/
SPLA_API spla_Status spla_Library_set_device(int index);

/**
* @brief Set number of GPU queues for parallel ops execution
*
* @param count Number of queues to set
*
* @return Function call status
*/
SPLA_API spla_Status spla_Library_set_queues_count(int count);

/**
* @brief Set callback function called on library message event
*
* @param callback Function to be called
*
* @return Function call status
*/
SPLA_API spla_Status spla_Library_set_message_callback(spla_MessageCallback callback, void* p_user_data);

/**
* @brief Sets default library callback to log messages to console
*
* @return Function call status
*/
SPLA_API spla_Status spla_Library_set_default_callback();

SPLA_API spla_Type spla_Type_int();
SPLA_API spla_Type spla_Type_uint();
SPLA_API spla_Type spla_Type_float();

SPLA_API spla_Status spla_Object_ref(spla_Object object);
SPLA_API spla_Status spla_Object_unref(spla_Object object);

SPLA_API spla_Status spla_Scalar_make(spla_Scalar* scalar, spla_Type type);
SPLA_API spla_Status spla_Scalar_set_int(spla_Scalar s, int value);
SPLA_API spla_Status spla_Scalar_set_uint(spla_Scalar s, unsigned int value);
SPLA_API spla_Status spla_Scalar_set_float(spla_Scalar s, float value);
SPLA_API spla_Status spla_Scalar_get_int(spla_Scalar s, int* value);
SPLA_API spla_Status spla_Scalar_get_uint(spla_Scalar s, unsigned int* value);
SPLA_API spla_Status spla_Scalar_get_float(spla_Scalar s, float* value);

SPLA_API spla_Status spla_Array_make(spla_Array* v, spla_uint n_values, spla_Type type);
SPLA_API spla_Status spla_Array_set_int(spla_Array a, spla_uint i, int value);
SPLA_API spla_Status spla_Array_set_uint(spla_Array a, spla_uint i, unsigned int value);
SPLA_API spla_Status spla_Array_set_float(spla_Array a, spla_uint i, float value);
SPLA_API spla_Status spla_Array_get_int(spla_Array a, spla_uint i, int* value);
SPLA_API spla_Status spla_Array_get_uint(spla_Array a, spla_uint i, unsigned int* value);
SPLA_API spla_Status spla_Array_get_float(spla_Array a, spla_uint i, float* value);
SPLA_API spla_Status spla_Array_clear(spla_Array a);

SPLA_API spla_Status spla_Vector_make(spla_Vector* v, spla_uint n_rows, spla_Type type);
SPLA_API spla_Status spla_Vector_set_fill_value(spla_Vector v, spla_Scalar value);
SPLA_API spla_Status spla_Vector_set_reduce(spla_Vector v, spla_OpBinary reduce);
SPLA_API spla_Status spla_Vector_set_int(spla_Vector v, spla_uint row_id, int value);
SPLA_API spla_Status spla_Vector_set_uint(spla_Vector v, spla_uint row_id, unsigned int value);
SPLA_API spla_Status spla_Vector_set_float(spla_Vector v, spla_uint row_id, float value);
SPLA_API spla_Status spla_Vector_get_int(spla_Vector v, spla_uint row_id, int* value);
SPLA_API spla_Status spla_Vector_get_uint(spla_Vector v, spla_uint row_id, unsigned int* value);
SPLA_API spla_Status spla_Vector_get_float(spla_Vector v, spla_uint row_id, float* value);
SPLA_API spla_Status spla_Vector_clear(spla_Vector v);

SPLA_API spla_Status spla_Matrix_make(spla_Matrix* M, spla_uint n_rows, spla_Type type);
SPLA_API spla_Status spla_Matrix_set_fill_value(spla_Matrix M, spla_Scalar value);
SPLA_API spla_Status spla_Matrix_set_reduce(spla_Matrix M, spla_OpBinary reduce);
SPLA_API spla_Status spla_Matrix_set_int(spla_Matrix M, spla_uint row_id, spla_uint col_id, int value);
SPLA_API spla_Status spla_Matrix_set_uint(spla_Matrix M, spla_uint row_id, spla_uint col_id, unsigned int value);
SPLA_API spla_Status spla_Matrix_set_float(spla_Matrix M, spla_uint row_id, spla_uint col_id, float value);
SPLA_API spla_Status spla_Matrix_get_int(spla_Matrix M, spla_uint row_id, spla_uint col_id, int* value);
SPLA_API spla_Status spla_Matrix_get_uint(spla_Matrix M, spla_uint row_id, spla_uint col_id, unsigned int* value);
SPLA_API spla_Status spla_Matrix_get_float(spla_Matrix M, spla_uint row_id, spla_uint col_id, float* value);
SPLA_API spla_Status spla_Matrix_clear(spla_Matrix M);

#if defined(__cplusplus)
}
#endif
Expand Down
1 change: 1 addition & 0 deletions include/spla.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
#define SPLA_SPLA_HPP

#include "spla/algorithm.hpp"
#include "spla/array.hpp"
#include "spla/config.hpp"
#include "spla/descriptor.hpp"
#include "spla/exec.hpp"
Expand Down
68 changes: 68 additions & 0 deletions include/spla/array.hpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
/**********************************************************************************/
/* This file is part of spla project */
/* https://github.com/JetBrains-Research/spla */
/**********************************************************************************/
/* MIT License */
/* */
/* Copyright (c) 2023 SparseLinearAlgebra */
/* */
/* Permission is hereby granted, free of charge, to any person obtaining a copy */
/* of this software and associated documentation files (the "Software"), to deal */
/* in the Software without restriction, including without limitation the rights */
/* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell */
/* copies of the Software, and to permit persons to whom the Software is */
/* furnished to do so, subject to the following conditions: */
/* */
/* The above copyright notice and this permission notice shall be included in all */
/* copies or substantial portions of the Software. */
/* */
/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR */
/* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, */
/* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE */
/* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER */
/* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, */
/* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE */
/* SOFTWARE. */
/**********************************************************************************/

#ifndef SPLA_ARRAY_HPP
#define SPLA_ARRAY_HPP

#include "config.hpp"
#include "object.hpp"
#include "type.hpp"

namespace spla {

/**
* @class Array
* @brief One-dimensional dense tightly packed array of typed values
*
* Represents typed array of elements, which can be queried and modified.
* An array may be used to construct some collection from user data,
* store it, pass around, and use for Vector or Matrix construction.
*
* Also an array may be used to inspect internal storage of a particular
* Vector or Matrix, allowing to extract arrays of COO, CSR, etc. formats.,
* including their Acc (OpenCL) representation.
*/
class Array : public Object {
public:
SPLA_API ~Array() override = default;
SPLA_API virtual uint get_n_values() = 0;
SPLA_API virtual ref_ptr<Type> get_type() = 0;
SPLA_API virtual Status set_int(uint i, T_INT value) = 0;
SPLA_API virtual Status set_uint(uint i, T_UINT value) = 0;
SPLA_API virtual Status set_float(uint i, T_FLOAT value) = 0;
SPLA_API virtual Status get_int(uint i, T_INT& value) = 0;
SPLA_API virtual Status get_uint(uint i, T_UINT& value) = 0;
SPLA_API virtual Status get_float(uint i, T_FLOAT& value) = 0;
SPLA_API virtual Status resize(uint n_values) = 0;

SPLA_API static ref_ptr<Array> make(uint n_values, const ref_ptr<Type>& type);
};


}// namespace spla

#endif//SPLA_ARRAY_HPP
Loading

0 comments on commit ea2c4f3

Please sign in to comment.