Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
112 changes: 112 additions & 0 deletions include/infini/ops.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,120 @@
#ifndef INFINI_OPS_H_
#define INFINI_OPS_H_

#include <stddef.h>
#include <stdint.h>

#ifdef __cplusplus
#include <infini/functional_ops.h>

extern "C" {
#endif

#if defined(_WIN32)
#if defined(INFINI_OPS_BUILD_SHARED)
#define INFINI_OPS_API __declspec(dllexport)
#elif defined(INFINI_OPS_USE_SHARED)
#define INFINI_OPS_API __declspec(dllimport)
#else
#define INFINI_OPS_API
#endif
#else
#if defined(INFINI_OPS_BUILD_SHARED)
#define INFINI_OPS_API __attribute__((visibility("default")))
#else
#define INFINI_OPS_API
#endif
#endif

typedef enum InfiniOpsStatus {
INFINI_OPS_STATUS_SUCCESS = 0,
INFINI_OPS_STATUS_INVALID_ARGUMENT = 1,
INFINI_OPS_STATUS_NOT_SUPPORTED = 2,
INFINI_OPS_STATUS_OUT_OF_MEMORY = 3,
INFINI_OPS_STATUS_INTERNAL_ERROR = 4,
} InfiniOpsStatus;

typedef enum InfiniOpsDataType {
INFINI_OPS_DATA_TYPE_INVALID = 0,
INFINI_OPS_DATA_TYPE_FLOAT16 = 1,
INFINI_OPS_DATA_TYPE_FLOAT32 = 2,
INFINI_OPS_DATA_TYPE_FLOAT64 = 3,
INFINI_OPS_DATA_TYPE_BFLOAT16 = 4,
INFINI_OPS_DATA_TYPE_INT8 = 5,
INFINI_OPS_DATA_TYPE_INT16 = 6,
INFINI_OPS_DATA_TYPE_INT32 = 7,
INFINI_OPS_DATA_TYPE_INT64 = 8,
INFINI_OPS_DATA_TYPE_UINT8 = 9,
INFINI_OPS_DATA_TYPE_UINT16 = 10,
INFINI_OPS_DATA_TYPE_UINT32 = 11,
INFINI_OPS_DATA_TYPE_UINT64 = 12,
} InfiniOpsDataType;

typedef enum InfiniOpsDeviceType {
INFINI_OPS_DEVICE_TYPE_INVALID = 0,
INFINI_OPS_DEVICE_TYPE_CPU = 1,
INFINI_OPS_DEVICE_TYPE_NVIDIA = 2,
INFINI_OPS_DEVICE_TYPE_CAMBRICON = 3,
INFINI_OPS_DEVICE_TYPE_ASCEND = 4,
INFINI_OPS_DEVICE_TYPE_METAX = 5,
INFINI_OPS_DEVICE_TYPE_MOORE = 6,
INFINI_OPS_DEVICE_TYPE_ILUVATAR = 7,
INFINI_OPS_DEVICE_TYPE_KUNLUN = 8,
INFINI_OPS_DEVICE_TYPE_HYGON = 9,
INFINI_OPS_DEVICE_TYPE_QY = 10,
} InfiniOpsDeviceType;

typedef struct InfiniOpsTensor {
size_t structure_size;
void *data;
size_t byte_size;
InfiniOpsDataType data_type;
InfiniOpsDeviceType device_type;
int32_t rank;
const int64_t *shape;
const int64_t *stride;
uint64_t reserved[8];
} InfiniOpsTensor;

typedef struct InfiniOpsStreamPrivate *InfiniOpsStream;
typedef struct InfiniOpsHandlePrivate *InfiniOpsHandle;
typedef struct InfiniOpsConfigPrivate *InfiniOpsConfig;

typedef struct InfiniOpsHandleAttributes {
size_t structure_size;
InfiniOpsStream stream;
void *workspace;
size_t workspace_byte_size;
uint64_t reserved[8];
} InfiniOpsHandleAttributes;

typedef struct InfiniOpsConfigAttributes {
size_t structure_size;
size_t implementation_index;
uint64_t reserved[8];
} InfiniOpsConfigAttributes;

INFINI_OPS_API InfiniOpsStatus infiniOpsGetLastError(char *buffer,
size_t capacity,
size_t *required_size);

INFINI_OPS_API InfiniOpsStatus infiniOpsCreateHandle(
const InfiniOpsHandleAttributes *attributes, InfiniOpsHandle *handle);

INFINI_OPS_API InfiniOpsStatus infiniOpsDestroyHandle(InfiniOpsHandle handle);

INFINI_OPS_API InfiniOpsStatus infiniOpsCreateConfig(
const InfiniOpsConfigAttributes *attributes, InfiniOpsConfig *config);

INFINI_OPS_API InfiniOpsStatus infiniOpsDestroyConfig(InfiniOpsConfig config);

INFINI_OPS_API InfiniOpsStatus infiniOpsAdd(
InfiniOpsHandle handle, InfiniOpsConfig config,
const InfiniOpsTensor *input, const InfiniOpsTensor *other,
InfiniOpsTensor *output);

#ifdef __cplusplus
}
#endif

#endif // INFINI_OPS_H_
32 changes: 24 additions & 8 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,30 @@ add_library(infiniops SHARED)

file(GLOB BASE_SRCS CONFIGURE_DEPENDS "*.cc")
target_sources(infiniops PRIVATE ${BASE_SRCS})
target_sources(infiniops PRIVATE infini/ops.cc)
target_compile_definitions(infiniops PRIVATE INFINI_OPS_BUILD_SHARED=1)

target_include_directories(infiniops
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/generated/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

set_target_properties(infiniops PROPERTIES
VERSION 1.0.0
SOVERSION 1
)

if(UNIX AND NOT APPLE AND CMAKE_CXX_COMPILER_ID MATCHES "GNU|Clang")
target_link_options(infiniops PRIVATE
"LINKER:--version-script=${CMAKE_CURRENT_SOURCE_DIR}/infini/ops.map"
)
set_target_properties(infiniops PROPERTIES
LINK_DEPENDS "${CMAKE_CURRENT_SOURCE_DIR}/infini/ops.map"
)
endif()

set(DEVICE_LIST "")

Expand Down Expand Up @@ -446,14 +470,6 @@ if(WITH_TORCH)
endif()
endif()

target_include_directories(infiniops
PUBLIC
$<BUILD_INTERFACE:${CMAKE_CURRENT_SOURCE_DIR}>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/include>
$<BUILD_INTERFACE:${PROJECT_SOURCE_DIR}/generated/include>
$<INSTALL_INTERFACE:${CMAKE_INSTALL_INCLUDEDIR}>
)

if(GENERATE_CPP_OPERATOR_API OR GENERATE_PYTHON_BINDINGS)
find_package(Python COMPONENTS Interpreter REQUIRED)
# Always regenerate wrappers so the generated functional API and pybind11
Expand Down
Loading
Loading