CGraph
【A common used C++ & Python DAG framework】 一个通用的、无三方依赖的、跨平台的、收录于awesome-cpp的、基于流图的并行计算框架。欢迎star & fork & 交流
Install / Use
/learn @ChunelFeng/CGraphREADME
中文 | English Readme | deepwiki
<h1 align="center"> CGraph 说明文档 </h1> <img align="right" src="https://github.com/ChunelFeng/CGraph/blob/main/doc/image/CGraph%20Author.jpg" width="256px"><b>CGraph</b> is a cross-platform <b>D</b>irected <b>A</b>cyclic <b>G</b>raph framework based on pure C++ without any 3rd-party dependencies.</br></br> You, with it, can <b>build your own operators simply, and describe any running schedules</b> as you need, such as dependence, parallelling, aggregation, conditional and so on. <b>Python APIs</b> are also supported to build your pipeline.</br></br> Tutorials and contact information are shown as follows. Please <b>get in touch with us for free</b> if you need more about this repository.
一. 简介
CGraph中文名为【色丶图】,是一套无任何第三方依赖的跨平台图流程执行框架。通过GPipeline(流水线)底层调度,提供了包含依赖元素依次执行、非依赖元素并发执行,支持暂停、恢复、超时设定的 eDAG 调度功能。
使用者只需继承GNode(节点)类,实现子类的run()方法,并根据需要设定依赖关系,即可实现任务的图化执行或流水线执行。还可以通过设定各种包含多节点信息的GGroup(组),自行控制图的条件判断、循环和并发执行逻辑。
<br>
本工程使用纯C++11标准库编写,无任何第三方依赖,兼容MacOS、Linux、Windows和Android系统。支持本地编译和二次开发,并且提供Python版本:pycgraph。编译和安装方法,请参考 CGraph 编译说明 <br>
详细功能介绍和用法,请参考 一面之猿网 中的文章内容。相关视频在B站持续更新中,欢迎观看和交流:<br>
- 【B站视频】CGraph 入门篇 <br>
- 【B站视频】CGraph 功能篇 <br>
- 全面介绍CGraph项目中,所有的名词术语和功能模块
- 结合实际coding过程,详细介绍了每个功能的具体的使用场景、用法、以及解决的问题
- 适合想要全面了解功能和快速上手使用CGraph的童鞋
- 适合对多线程编程感兴趣的童鞋
- 【B站视频】CGraph 应用篇 <br>
- 【B站视频】CGraph 分享篇 <br>
二. 入门Demo
<b>C++ 版本</b>
#include "CGraph.h"
using namespace CGraph;
class MyNode1 : public GNode {
public:
CStatus run() override {
printf("[%s], sleep for 1 second ...\n", this->getName().c_str());
CGRAPH_SLEEP_SECOND(1)
return CStatus();
}
};
class MyNode2 : public GNode {
public:
CStatus run() override {
printf("[%s], sleep for 2 second ...\n", this->getName().c_str());
CGRAPH_SLEEP_SECOND(2)
return CStatus();
}
};
int main() {
/* 创建一个流水线,用于设定和执行流图信息 */
GPipelinePtr pipeline = GPipelineFactory::create();
GElementPtr a, b, c, d = nullptr;
/* 注册节点之间的依赖关系 */
pipeline->registerGElement<MyNode1>(&a, {}, "nodeA");
pipeline->registerGElement<MyNode2>(&b, {a}, "nodeB");
pipeline->registerGElement<MyNode1>(&c, {a}, "nodeC");
pipeline->registerGElement<MyNode2>(&d, {b, c}, "nodeD");
/* 执行流图框架 */
pipeline->process();
/* 清空流水线中所有的资源 */
GPipelineFactory::remove(pipeline);
return 0;
}
<br>
如上图所示,图结构执行的时候,首先执行a节点。a节点执行完毕后,并行执行b和c节点。b和c节点全部执行完毕后,再执行d节点。
<b>Python 版本</b>
import time
from datetime import datetime
from pycgraph import GNode, GPipeline, CStatus
class MyNode1(GNode):
def run(self):
print("[{0}] {1}, enter MyNode1 run function. Sleep for 1 second ... ".format(datetime.now(), self.getName()))
time.sleep(1)
return CStatus()
class MyNode2(GNode):
def run(self):
print("[{0}] {1}, enter MyNode2 run function. Sleep for 2 second ... ".format(datetime.now(), self.getName()))
time.sleep(2)
return CStatus()
if __name__ == '__main__':
pipeline = GPipeline()
a, b, c, d = MyNode1(), MyNode2(), MyNode1(), MyNode2()
pipeline.registerGElement(a, set(), "nodeA")
pipeline.registerGElement(b, {a}, "nodeB")
pipeline.registerGElement(c, {a}, "nodeC")
pipeline.registerGElement(d, {b, c}, "nodeD")
pipeline.process()
<b>其他版本</b>
- CsCGraph : A CSharp native, CGraph-API-liked DAG project
- JaCGraph : A Java native, CGraph-API-liked DAG project
- GoCGraph : A Go native, CGraph-API-liked DAG project
- CGraph-lite : A one-header-only, CGraph-API-liked DAG project, lite version by C++
三. 推荐阅读
- 纯序员给你介绍图化框架的简单实现——执行逻辑
- 纯序员给你介绍图化框架的简单实现——循环逻辑
- 纯序员给你介绍图化框架的简单实现——参数传递
- 纯序员给你介绍图化框架的简单实现——条件判断
- 纯序员给你介绍图化框架的简单实现——面向切面
- 纯序员给你介绍图化框架的简单实现——函数注入
- 纯序员给你介绍图化框架的简单实现——消息机制
- 纯序员给你介绍图化框架的简单实现——事件触发
- 纯序员给你介绍图化框架的简单实现——超时机制
- 纯序员给你介绍图化框架的简单实现——线程池优化(一)
- 纯序员给你介绍图化框架的简单实现——线程池优化(二)
- 纯序员给你介绍图化框架的简单实现——线程池优化(三)
- 纯序员给你介绍图化框架的简单实现——线程池优化(四)
- 纯序员给你介绍图化框架的简单实现——线程池优化(五)
- 纯序员给你介绍图化框架的简单实现——线程池优化(六)
- 纯序员给你介绍图化框架的简单实现——性能优化(一)
- 纯序员给你介绍图化框架的简单实现——性能优化(二)
- 纯序员给你介绍图化框架的简单实现——距离计算 <br><br>
- CGraph 主打歌——《听码农的话》
- 聊聊我写CGraph的这一年
- 从零开始主导一款收录于awesome-cpp的项目,是一种怎样的体验?
- 炸裂!CGraph性能全面超越taskflow之后,作者却说他更想...
- 以图优图:CGraph中计算dag最大并发度思路总结
- 一文带你了解练习时长两年半的CGraph
- CGraph作者想知道,您是否需要一款eDAG调度框架
- 降边增效:CGraph中冗余边剪裁思路总结
- 最新码坛爽文:重生之我在国外写CGraph(python版本)
- 做之前不敢想的 CGraph <br>
四. 关联项目
- GraphANNS : Graph-based Approximate Nearest Neighbor Search Working off CGraph
- CThreadPool : 一个简单好用、功能强大、性能优异、跨平台的C++线程池
- PyCGraph-example : A useful list of how cool to use PyCGraph
- awesome-cpp : A curated list of awesome C++ (or C) frameworks, libraries, resources, and shiny things. Inspired by awesome-... stuff.
- awesome-workflow-engines : A curated list of awesome open source workflow engines
- taskflow : A General-purpose Parallel and Heterogeneous Task Programming System
- torchpipe : Serving Inside Pytorch
- nndeploy : Easy-to-use, high-performance, multi-platform inference deployment framework
- KuiperInfer : 带你从零实现一个高性能的深度学习推理库,支持大模型 llama2 、Unet、Yolov5、Resnet等模型的推理。Implement a high-performance deep learning inference library step by step
- OGraph : A simple way to build a pipeline with Go.
- [【B站视频】听阿里云大佬分享:OGraph——基于Go的流图调度二三事](https://www.bili
