数据与计算发展前沿 ›› 2022, Vol. 4 ›› Issue (3): 19-29.

CSTR: 32002.14.jfdc.CN10-1649/TP.2022.03.002

doi: 10.11871/jfdc.issn.2096-742X.2022.03.002

• 专刊:先进智能计算平台及应用(下) • 上一篇    下一篇

基于OpenCL的TensorFlow框架中Element-Wise算子实现

隋轶丞1(),石昌青1(),孙羽菲1,2,*(),张玉志1,2(),陈禹乔1(),张宇哲1()   

  1. 1.南开大学,软件学院,天津 300350
    2.先进计算与关键软件海河实验室,天津 300350
  • 收稿日期:2022-03-04 出版日期:2022-06-20 发布日期:2022-06-20
  • 通讯作者: 孙羽菲
  • 作者简介:隋轶丞,南开大学,软件学院,博士研究生,主要研究方向为人工智能。
    本文中负责方法设计、代码实现与论文撰写。
    SUI Yicheng is a Ph.D. student in Colle-ge of Software at Nankai Univer-sity. His research interests include artificial intelligence.
    In this article, he is responsible for method design, code imp-lementation, and paper writing.
    E-mail: suiyicheng@mail.nankai.edu.cn|石昌青,南开大学,软件学院,硕士研究生,主要研究方向为深度学习与高性能计算。
    本文中他参与方法设计与承担实验测试。
    SHI Changqing is a master’s student in College of Software at Nankai University. His research interests include deep learning and high-performance computing.
    In this paper, he participated in method design and undertook experimental tests.
    E-mail: shichangqing@mail.nankai.edu.cn|孙羽菲,南开大学,软件学院,特聘研究员,博士,先进计算与关键软件海河实验室研究员,主要研究方向为深度学习、异构计算、人工智能等。
    本文主要承担论文指导和修改工作。
    SUN Yufei, Ph.D., is a professor at College of Software, Nan-kai University and a professor at HaiHe Lab of ITAI. Her resea-rch interests include deep learning, heterogeneous computing, artificial intelligence, etc.
    In this paper, she is mainly responsible for the paper guidance and paper revision.
    E-mail: yufei_sun@sina.com|张玉志,南开大学,讲席教授,软件学院,院长,先进计算与关键软件海河实验室顶尖人才,主要研究方向为人工智能、模式识别、自然语言处理等。
    本文主要承担文献调研及指导。
    ZHANG Yuzhi is the chair professor and the Dean of Software College in Nankai University. He is the top-level Expert in HaiHe Lab of ITAI. His research interests focus on artificial intelligence, pattern recognition, natural language processing, etc.
    In this paper, he is mainly responsible for the related work investigation and guidance.
    E-mail: zyz@nankai.edu.cn|陈禹乔,南开大学,软件学院,硕士研究生,主要研究方向为深度学习框架移植与高性能计算。
    本文主要参与方案设计与实验。
    CHEN Yuqiao is currently a master’s student in the College of Software at Nan-kai University, Tianjin, China. His research interests include deep learning framework transplantation and high-performance computing.
    In this paper, he participated in scheme design and experim-ent.
    E-mail: ujoenk@mail.nankai.edu.cn|张宇哲,南开大学,软件学院,硕士研究生,主要研究方向为人工智能。
    本文主要参与方案设计与实验。
    ZHANG Yuzhe is currently a master’s student in the College of Software at Na-nkai University, Tianjin, China. His rese-arch interests include artificial intelligence.
    In this paper, he participated in scheme design and experiment.
    E-mail: zyzcs@mail.nankai.edu.cn
  • 基金资助:
    国家重点研发计划(2021YFB0300104)

Implementation of Element-Wise Operator in TensorFlow Framework Based on OpenCL

SUI Yicheng1(),SHI Changqing1(),SUN Yufei1,2,*(),ZHANG Yuzhi1,2(),CHEN Yuqiao1(),ZHANG Yuzhe1()   

  1. 1. College of software, Nankai University, Tianjin 300350, China
    2. Haihe Lab of ITAI, Tianjin 300350, China
  • Received:2022-03-04 Online:2022-06-20 Published:2022-06-20
  • Contact: SUN Yufei

摘要:

【目的】深度学习模型以较强的建模性能和优秀的多场景适应能力被广泛应用于各类典型人工智能领域。目前通常采用异构并行计算技术满足深度学习模型的算力需求,然而目前深度学习框架普遍使用CUDA或ROCm等编程模型,仅能支持特定厂商设备;对于通用异构计算设备,需要通过OpenCL编程标准实现支持,因此我们着力于实现TensorFlow框架的OpenCL版本。【方法】本文对TensorFlow框架中主要基于Eigen库提供的接口实现的Element-Wise算子进行代码分析,拆解对应结构体和类的封装方式,并基于OpenCL的编程标准对Element-Wise算子进行实现和封装,确保了代码的规范性和可扩展性。【结果】本文以CUDA算子为基准,对OpenCL的Element-Wise算子进行测试和对比,实验结果分别从正确性和计算效率两方面验证了本文OpenCL版本算子实现的可行性。【结论】作为实现OpenCL版本的TensorFlow框架这一工作的重要组成部分,本文成功实现了TensorFlow框架中Element-Wise算子的OpenCL版本,并经过实验验证了本文实现的算子的计算准确性和计算效率。

关键词: OpenCL, TensorFlow, 核函数

Abstract:

[Objective] Deep learning models are widely used in various typical artificial intelligence fields with strong modeling performance and excellent multi-scene adaptability. At present, heterogeneous parallel computing technology is usually used to meet the computing power requirements of deep learning models. However, current deep learning frameworks generally use programming models such as CUDA or ROCm, which can only support equipment of specific manufacturers. It is necessary to support general heterogeneous computing equipment by the OpenCL programming standard. So we focused on implementing the OpenCL version of the TensorFlow framework. [Methods] This paper analyzes the code of the Element-Wise operator implemented mainly based on the interface provided by the Eigen library in the TensorFlow framework, disassembles the encapsulation method of the corresponding structure and class, and implements the Element-Wise operator based on the OpenCL programming standard. Implementation and encapsulation ensure the specification and extensibility of the code. [Results] This paper tests and compares the Element-Wise operator of OpenCL with the CUDA operator. The experimental results verify the feasibility of the implementation of the operator with OpenCL in terms of correctness and computational efficiency. [Conclusions] As an essential part of implementing the TensorFlow framework with OpenCL, the work presented in paper successfully implement the OpenCL version of the Element-Wise operator in the TensorFlow framework. The computational accuracy and calculation efficiency of the operator implemented in this paper is also verified by experiments.

Key words: OpenCL, TensorFlow, Kernel Function