Skip to content

Commit

Permalink
seperated from aiges
Browse files Browse the repository at this point in the history
  • Loading branch information
whybeyoung committed Jul 3, 2022
0 parents commit 8bc2499
Show file tree
Hide file tree
Showing 340 changed files with 93,298 additions and 0 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.vscode/
.idea/
10 changes: 10 additions & 0 deletions Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
PYLIB=$(shell python3-config --ldflags --embed)
PYINC=$(shell python3-config --cflags --embed )
wrapper:
echo $(PYLIB)
g++ -fPIC -shared -std=c++11 -Wno-attributes $(PYINC) -g -O0 -I. -I./include/spdlog/include -I./include/ -o libpyCallCommon.so pyCall_common.cpp -L. $(PYLIB)
g++ -fPIC -shared -std=c++11 -Wno-attributes $(PYINC) -g -O0 -I. -I./include/spdlog/include -I./include/ -o libpyCallOnce.so pyCall_once.cpp -L. -L /opt/conda/envs/loader/lib $(PYLIB)
g++ -fPIC -shared -std=c++11 -Wno-attributes $(PYINC) -g -O0 -I. -I./include/spdlog/include -I./include/ -o libpyCallStream.so pyCall_stream.cpp -L. -L /opt/conda/envs/loader/lib $(PYLIB)
g++ -Wall -pedantic -Wextra -fPIC -shared -std=c++11 -Wno-attributes $(PYINC) -g -O0 -I. -I./include/spdlog/include -I./include/ -o libwrapper.so wrapper.cpp -L. -L /opt/conda/envs/loader/lib -lboost_filesystem -lboost_system -lpyCallCommon -lpyCallOnce -lpyCallStream $(PYLIB)
mkdir -p wrapper_lib
cp libwrapper.so libpyCallCommon.so libpyCallOnce.so libpyCallStream.so ./wrapper_lib
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
# ai_cpython_wrapper

cpython插件,通过此插件完成加载器对python的支持
8 changes: 8 additions & 0 deletions build.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
#!/bin/bash
#export LD_LIBRARY_PATH=./lib:$LD_LIBRARY_PATH
echo $LD_LIBRARY_PATH
g++ -fPIC -shared -std=c++11 -Wno-attributes -g -O0 -I. -I./include/spdlog/include -I./include/ -o libpyCallCommon.so pyCall_common.cpp -L. -lpython
g++ -fPIC -shared -std=c++11 -Wno-attributes -g -O0 -I. -I./include/spdlog/include -I./include/ -o libpyCallOnce.so pyCall_once.cpp -L. -lpython
g++ -fPIC -shared -std=c++11 -Wno-attributes -g -O0 -I. -I./include/spdlog/include -I./include/ -o libpyCallStream.so pyCall_stream.cpp -L. -lpython
g++ -fPIC -shared -std=c++11 -Wno-attributes -g -O0 -I. -I./include/spdlog/include -I./include/ -L. -lpyCallCommon -lpyCallOnce -lpyCallStream -lboost_filesystem -lboost_system -o libwrapper.so wrapper.cpp
cp libwrapper.so libpyCallCommon.so libpyCallOnce.so libpyCallStream.so libpython.so ./wrapperlib/
7 changes: 7 additions & 0 deletions changelog.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# v1.0.0

1. 支持非会话的python实现

# v1.0.1

1. 移除了一些打印语句
100 changes: 100 additions & 0 deletions include/aiges/type.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
#ifndef __AIGES_TYPE_H__
#define __AIGES_TYPE_H__


///**
// * C/C++ wchar_t support
// */
//#ifdef __cplusplus
//# include <cwchar>
//#else /* c */
//# include <wchar.h>
//#endif /* wchar */


///**
// * Wrapper API type
// */
//#if defined(_MSC_VER) /* Microsoft Visual C++ */
// #if !defined(WrapperAPI)
// #define WrapperAPI __stdcall
// #endif
// #pragma pack(push, 8)
//#elif defined(__BORLANDC__) /* Borland C++ */
// #if !defined(WrapperAPI)
// #define WrapperAPI __stdcall
// #endif
// #pragma option -a8
//#elif defined(__WATCOMC__) /* Watcom C++ */
// #if !defined(WrapperAPI)
// #define WrapperAPI __stdcall
// #endif
// #pragma pack(push, 8)
//#else /* Any other including Unix */
// #if !defined(WrapperAPI)
#define WrapperAPI __attribute__ ((visibility("default")))
// #endif
//#endif


///**
// * True and false
// */
//#ifndef FALSE
//#define FALSE 0
//#endif /* FALSE */
//
//#ifndef TRUE
//#define TRUE 1
//#endif /* TRUE */

typedef enum{
CTMeterCustom = 0, // 自定义计量接口
CTMetricsLog = 1, // 自定义metrics日志接口
CTTraceLog = 2, // 自定义trace日志接口

} CtrlType;

typedef enum{
DataText = 0, // 文本数据
DataAudio = 1, // 音频数据
DataImage = 2, // 图像数据
DataVideo = 3, // 视频数据
DataPer = 4, // 个性化数据
} DataType;

typedef enum{
DataBegin = 0, // 首数据
DataContinue = 1, // 中间数据
DataEnd = 2, // 尾数据
DataOnce = 3, // 非会话单次输入输出
} DataStatus;

typedef struct ParamList{
char* key;
char* value;
unsigned int vlen;
struct ParamList* next;
}* pParamList, *pConfig, *pDescList; // 配置对复用该结构定义

typedef struct DataList{
char* key; // 数据标识
void* data; // 数据实体
unsigned int len; // 数据长度
DataType type; // 数据类型
DataStatus status; // 数据状态
pDescList desc; // 数据描述
struct DataList* next; // 链表指针
}* pDataList;


///* Reset the structure packing alignments for different compilers. */
//#if defined(_MSC_VER) /* Microsoft Visual C++ */
// #pragma pack(pop)
//#elif defined(__BORLANDC__) /* Borland C++ */
// #pragma option -a.
//#elif defined(__WATCOMC__) /* Watcom C++ */
// #pragma pack(pop)
//#endif

#endif
169 changes: 169 additions & 0 deletions include/aiges/wrapper.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
#ifndef __AIGES_WRAPPER_H__
#define __AIGES_WRAPPER_H__

#include "type.h"

#ifdef __cplusplus
extern "C" {
#endif

/*
服务回调接口设置,用于设置服务回调接口至插件,插件可按需调用各类服务接口:
1. 自定义计量接口:wrapperMeterCustom
2. 自定义日志接口:wrapperTraceLog
*/
int WrapperAPI wrapperSetCtrl(CtrlType type, void* func);
typedef int (WrapperAPI *wrapperSetCtrlPtr)(CtrlType type, void* func);

/*
wrapper服务层初始化
@param cfg 服务层配置对
*/
int WrapperAPI wrapperInit(pConfig cfg);
typedef int (WrapperAPI *wrapperInitPtr)(pConfig cfg);

/*
wrapper服务层逆初始化
*/
int WrapperAPI wrapperFini();
typedef int (WrapperAPI *wrapperFiniPtr)();

/*
获取服务错误信息
@param errNum 服务层异常错误码
@return 错误码对应的错误描述信息
*/
const char* WrapperAPI wrapperError(int errNum);
typedef const char* (WrapperAPI *wrapperErrorPtr)(int errNum);

/*
获取服务版本信息
@return 服务版本信息
*/
const char* WrapperAPI wrapperVersion();
typedef const char* (WrapperAPI *wrapperVersionPtr)();


/// 以下接口为会话模式请求调用接口;
/// 1. 包含个性化资源加载/卸载接口;
/// 2. 包含会话模式上下文相关接口:create/write/read/destroy;
/// 3. 包含同步模式/异步模式接口;

/*
个性化数据加载
@param perData 个性化加载数据
@param resId 个性化数据标记,由框架层生成传入
@return 接口错误码
*/

int WrapperAPI wrapperLoadRes(pDataList perData, unsigned int resId);
typedef int (WrapperAPI *wrapperLoadResPtr)(pDataList perData, unsigned int resId);

/*
个性化数据卸载
@param resId 个性化数据标记
@return 接口错误码
*/
int WrapperAPI wrapperUnloadRes(unsigned int resId);
typedef int (WrapperAPI *wrapperUnloadResPtr)(unsigned int resId);

/*
回调接口定义
@param usrTag 用户数据,用于关联异步请求
@param respData 异步计算结果,通过回调返回框架层
@return ret 异步返回值,异常则返回非0值.
@note 无需集成方实现(框架实现),由集成方于请求数据计算完毕后调用;
*/
typedef int(*wrapperCallback)(const void* usrTag, pDataList respData, int ret);

/*
创建计算资源
@param params 会话参数对
@param cb 异步回调:若同步响应则cb为null,通过wrapperRead获取结果
若异步响应则传入cb,通过回调cb返回结果至框架;
@param usrTag 用户tag,用于异步关联用户请求;
@param psrIds 会话所需个性化资源id
@param psrCnt 会话个性化资源Count
@param errNum 接口错误码[in/out]
@return 引擎服务实例句柄,用于关联上下文;
*/
const void* WrapperAPI wrapperCreate(const char* usrTag, pParamList params, wrapperCallback cb, unsigned int psrIds[], int psrCnt, int* errNum);
typedef const void* (WrapperAPI *wrapperCreatePtr)(const char* usrTag, pParamList params, wrapperCallback cb, unsigned int psrIds[], int psrCnt, int* errNum);

/*
写入计算数据
@param handle 实例句柄,用于关联上下文;
@param reqData 写入数据实体
@return 接口错误码
*/
int WrapperAPI wrapperWrite(const void* handle, pDataList reqData);
typedef int (WrapperAPI *wrapperWritePtr)(const void* handle, pDataList reqData);

/*
读取计算结果
@param handle 实例句柄,用于关联上下文;
@param respData 同步读取结果实体
@return 接口错误码
@note respData内存由底层自行维护,在destroy阶段销毁
*/
int WrapperAPI wrapperRead(const void* handle, pDataList* respData);
typedef int (WrapperAPI *wrapperReadPtr)(const void* handle, pDataList* respData);

/*
释放计算资源
@param handle 会话句柄,用于关联上下文;
*/
int WrapperAPI wrapperDestroy(const void* handle);
typedef int (WrapperAPI *wrapperDestroyPtr)(const void* handle);


/// 以下接口为非会话模式请求调用接口,对应引擎框架oneShot协议消息;
/// 1. 其中wrapperExec()为同步阻塞接口,要求引擎服务阻塞带计算完成返回计算结果;
/// 2. wrapperExecFree()为同步临时资源释放接口,用于释放wrapperExec产生的临时结果数据;
/// 3. wrapperExec()为异步非阻塞接口,要求引擎服务即时返回,异步计算结果通过回调callback返回;

/*
非会话模式计算接口,对应oneShot请求
@param reqData 写入数据实体
@param respData 返回结果实体,内存由底层服务层申请维护,通过execFree()接口释放
@param psrIds 需要使用的个性化资源标识
@param psrCnt 需要使用个性化资源个数
@return 接口错误码
@note 同步操作接口, 需考虑上层并发调用可能
*/
int WrapperAPI wrapperExec(const char* usrTag, pParamList params, pDataList reqData, pDataList* respData, unsigned int psrIds[], int psrCnt);
typedef int (WrapperAPI *wrapperExecPtr)(const char* usrTag, pParamList params, pDataList reqData, pDataList* respData, unsigned int psrIds[], int psrCnt);


/*
同步接口响应数据缓存释放接口
@param respData 由同步接口exec获取的响应结果数据
*/
int WrapperAPI wrapperExecFree(const char* usrTag, pDataList* respData);
typedef int (WrapperAPI *wrapperExecFreePtr)(const char* usrTag, pDataList* respData);

/*
非会话模式计算接口,对应oneShot请求
@param usrTag 用户数据,关联异步连接
@param reqData 写入数据实体
@param callback 异步回调接口,用于异步返回计算结果(框架实现)
@param timeout 异步超时时间,集成方实现该超时控制,ms;
@note 异步操作接口, 需考虑上层并发调用可能
*/
int WrapperAPI wrapperExecAsync(const char* usrTag, pParamList params, pDataList reqData, wrapperCallback callback, int timeout, unsigned int psrIds[], int psrCnt);
typedef int (WrapperAPI *wrapperExecAsyncPtr)(const char* usrTag, pParamList params, pDataList reqData, wrapperCallback callback, int timeout, unsigned int psrIds[], int psrCnt);

/*
调试信息输出接口
@return 会话调试信息;
@note 单次会话destroy前调用一次;
*/
const char* WrapperAPI wrapperDebugInfo(const void* handle);
typedef const char* (WrapperAPI *wrapperDebugInfoPtr)(const void* handle);


#ifdef __cplusplus
}
#endif

#endif
Loading

0 comments on commit 8bc2499

Please sign in to comment.