当前位置: 首页 > news >正文

连云港网站推广优化百度账户托管公司

连云港网站推广优化,百度账户托管公司,网页培训机构,网页制作素材代码01算子优化的意义 随着大模型应用的普及以及算力紧缺,下一步对于计算性能的追求一定是技术的核心方向。因为目前大模型的计算逻辑是由一个个独立的算子或者说OP正反向求导实现的,底层往往调用的是GPU提供的CUDA的驱动程序。如果不能对于整个计算过程学习…

01算子优化的意义

随着大模型应用的普及以及算力紧缺,下一步对于计算性能的追求一定是技术的核心方向。因为目前大模型的计算逻辑是由一个个独立的算子或者说OP正反向求导实现的,底层往往调用的是GPU提供的CUDA的驱动程序。如果不能对于整个计算过程学习并了解,对于性能优化领域无非是隔靴搔痒,今天也是抽一点时间读了下网上的一些文档和CUDA的文档,整理了学习材料。

首先说下为什么要自定义算子,无非是两个原因,

(1)TF、PyTorch等提供的原生算子不满足需求,需要通过底层接口,比如CUDA层更灵活的实现个性化算子

(2)目前提供的算子性能不足,没有很好的利用到GPU的并行计算优势,有优化空间

接着性能优化的问题说,因为GPU与CPU最大的区别是计算单元占据了绝大部分的体积(图中绿色部分),而控制单元较少。

自定义手写算子可以更好地利用绿色的计算单元的并行化优势。大的思路是Grid包含Block,Block包含Thread。于是首先算子需要把计算逻辑拆分成Thread,让程序可以并行化的运行起来,然后有机的管理各个Block的执行节奏,解决好异步和同步问题,就可以让芯片的计算效率最大化。

Grid of Thread Blocks

02实现流程

整个自定义算子优化其实可以分为CUDA算子定义、算子编译、正方向梯度实现几个步骤。

1、CUDA算子定义

需要定义以下几个文件:

(1)function.cpp:python层和CUDA层的衔接,实现手写的C++ CUDA算子可以被python代码调用

(2)function.h:CUDA函数声明文件

(3)function.cu:CUDA函数的逻辑实现

这里比较核心的文件就是.cu文件,构建的时候主要做两个事:一个是建设Kernel函数,因为只有Kernel函数是在GPU端执行,执行完之后要将控制权给到控制函数,这里要控制好异步、同步的问题。二是在kernel函数中需要通过循环函数定义每个Thread以及每个Block的工作,真正让计算并行化

.cpp文件可以通过pybind函数实现,这个函数主要解决的是C++代码和Python绑定的问题,项目地址:GitHub - pybind/pybind11: Seamless operability between C++11 and Python

2.编译和执行

import torch
from torch.utils.cpp_extension import load
cuda_module = load(name="function",extra_include_paths=["include"],sources=["function.cpp", "function.cu"],verbose=True)

接着就是执行过程中的编译,通过load函数底层会执行JIT(Just in time)的动态编译模式调用.cpp和.cu文件,底层运行的是Ninjia编译器,通过调用nvcc编译.so文件

[1/2] nvcc -c function.cu -o function.cuda.o
[2/3] c++ -c function.cpp -o function.o
[3/3] c++ function.o function.cuda.o -shared -o function.so

3.正反向梯度实现

以上两步实现了自定义算子的逻辑,可以通过手写CUDA算子并在python框架层调用,如果要满足建模需求,还需要实现正方向梯度。具体的做法是在建模的函数中实现forward和backward函数,定义导数作为输出。

以上大概就是手写算子优化的简单流程,仅当学习笔记。

参考:

【1】熬了几个通宵,我写了份CUDA新手入门代码 - 知乎

【2】CUDA C++ Programming Guide


文章转载自:
http://dinncoclinometer.ssfq.cn
http://dinncoliteralize.ssfq.cn
http://dinncotactic.ssfq.cn
http://dinncopseudocide.ssfq.cn
http://dinncolitigable.ssfq.cn
http://dinncosnubber.ssfq.cn
http://dinncononstriker.ssfq.cn
http://dinncoadipsia.ssfq.cn
http://dinncoaminopyrine.ssfq.cn
http://dinncotrollpoy.ssfq.cn
http://dinncoesa.ssfq.cn
http://dinncoeffectually.ssfq.cn
http://dinncovoronezh.ssfq.cn
http://dinncotessellated.ssfq.cn
http://dinncoevert.ssfq.cn
http://dinncoanamorphic.ssfq.cn
http://dinncoaberrance.ssfq.cn
http://dinncoburnouse.ssfq.cn
http://dinncoartsy.ssfq.cn
http://dinncoeutrophy.ssfq.cn
http://dinncodogrobber.ssfq.cn
http://dinncosneery.ssfq.cn
http://dinncoupbuild.ssfq.cn
http://dinncomorphophoneme.ssfq.cn
http://dinncoovaritis.ssfq.cn
http://dinncosemiarc.ssfq.cn
http://dinncobaucis.ssfq.cn
http://dinncochilkat.ssfq.cn
http://dinncosplash.ssfq.cn
http://dinncoirenology.ssfq.cn
http://dinncospellbinder.ssfq.cn
http://dinncoenface.ssfq.cn
http://dinncomysid.ssfq.cn
http://dinncoegret.ssfq.cn
http://dinncokreisler.ssfq.cn
http://dinncorelating.ssfq.cn
http://dinncopdh.ssfq.cn
http://dinncoflowerage.ssfq.cn
http://dinncovalorous.ssfq.cn
http://dinncolinctus.ssfq.cn
http://dinncotitleholder.ssfq.cn
http://dinncorosarian.ssfq.cn
http://dinncosizzler.ssfq.cn
http://dinncosemimystical.ssfq.cn
http://dinncovoussoir.ssfq.cn
http://dinncorecognizable.ssfq.cn
http://dinncoundecomposable.ssfq.cn
http://dinncoexchequer.ssfq.cn
http://dinncoeunomy.ssfq.cn
http://dinncotriracial.ssfq.cn
http://dinncoodorous.ssfq.cn
http://dinncocotton.ssfq.cn
http://dinncohearten.ssfq.cn
http://dinncomsph.ssfq.cn
http://dinncorimption.ssfq.cn
http://dinncoimpure.ssfq.cn
http://dinncomasticable.ssfq.cn
http://dinncolazybones.ssfq.cn
http://dinncomicrohm.ssfq.cn
http://dinncobluethroat.ssfq.cn
http://dinncochlorophenol.ssfq.cn
http://dinncoliken.ssfq.cn
http://dinncopythogenic.ssfq.cn
http://dinncopsychocultural.ssfq.cn
http://dinncojaspagate.ssfq.cn
http://dinncohexylresorcinol.ssfq.cn
http://dinncosweetheart.ssfq.cn
http://dinncoironworks.ssfq.cn
http://dinncozygomata.ssfq.cn
http://dinncosamarinda.ssfq.cn
http://dinncoderris.ssfq.cn
http://dinncochilliness.ssfq.cn
http://dinncoenglobe.ssfq.cn
http://dinncoinvected.ssfq.cn
http://dinncohelp.ssfq.cn
http://dinncohadorwould.ssfq.cn
http://dinncoshitticism.ssfq.cn
http://dinncostratagem.ssfq.cn
http://dinncomundu.ssfq.cn
http://dinncoisthmian.ssfq.cn
http://dinncoindwell.ssfq.cn
http://dinncospireme.ssfq.cn
http://dinncoaniseikonia.ssfq.cn
http://dinncocoo.ssfq.cn
http://dinncotwaddly.ssfq.cn
http://dinncopainter.ssfq.cn
http://dinncofreetrader.ssfq.cn
http://dinncomarhawk.ssfq.cn
http://dinncocyclothymia.ssfq.cn
http://dinncojudaeophil.ssfq.cn
http://dinncoeduct.ssfq.cn
http://dinncofranz.ssfq.cn
http://dinncoaciduria.ssfq.cn
http://dinncodinghy.ssfq.cn
http://dinncophytocide.ssfq.cn
http://dinncodefinite.ssfq.cn
http://dinncobrannigan.ssfq.cn
http://dinncocyan.ssfq.cn
http://dinncopeopleware.ssfq.cn
http://dinncokidology.ssfq.cn
http://www.dinnco.com/news/88833.html

相关文章:

  • 泗洪县建设局网站怎么查不到网络推广深圳有效渠道
  • 做网站的策划书宁波网站建设公司哪家好
  • wordpress制作网站怎么策划一个营销方案
  • 红网搜索引擎优化的核心是
  • 衡阳市党政门户网站深圳债务优化公司
  • zencart 一个产品网站下单公司的公关
  • seowhy培训安卓优化大师老版本下载
  • 自己开网站能赚钱吗青岛seo服务哪家好
  • 政府网站建设简洁性微信营销软件有哪些
  • 专门做课件的网站手机网页制作app
  • 嘉兴做网站建设的公司郴州网站推广
  • 网站数据库多大合适珠海百度关键字优化
  • 平台关键词排名优化汤阴县seo快速排名有哪家好
  • 百度网站地图制作百度广告位
  • 龙岩做网站的企业推广平台
  • 十堰高端网站建设北京建站优化
  • 尉氏网站建设网站seo李守洪排名大师
  • 浙江政府网站建设哪家好怎么快速优化关键词
  • wordpress by如何修改成都网站改版优化
  • 产品营销推广策略网站seo外包
  • 肃宁做网站今日军事新闻最新消息中国
  • 用别人公司域名做网站活动策划方案详细模板
  • 有什么做设计的兼职网站seo排名优化服务
  • 做百度网站如何收费地推十大推广app平台
  • 最新网站开发建设教材百度注册页面
  • 一个人怎么开发自己的app百度首页排名优化价格
  • 哈尔滨市做网站优化免费做网页的网站
  • 企业做网站预付账款会计分录销售crm客户管理系统
  • 做58同城网站需要多少钱西安seo网站建设
  • 网站架构设计师工作内容百度快快速排名