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

银行门户网站建设方案南宁seo专员

银行门户网站建设方案,南宁seo专员,个人做百度云下载网站吗,长沙百度优化1 源码下载 Ascend对pytorch代码的适配,可从以下链接中获取。 Ascend/pytorch 执行如下命令即可。 git clone https://gitee.com/ascend/pytorch.git2 目录结构解析 源码下载后,如果需要编译torch-npu,最好保持pytorch的源码版本匹配&…

1 源码下载

Ascend对pytorch代码的适配,可从以下链接中获取。
Ascend/pytorch
执行如下命令即可。

git clone https://gitee.com/ascend/pytorch.git

2 目录结构解析

源码下载后,如果需要编译torch-npu,最好保持pytorch的源码版本匹配,以及其编译环境的gcc,g++等与torch-npu的版本匹配,否则会出现各种乱起八糟的问题。

执行编译命令:bash ci/build.sh --python=3.x

如:


csrc/aten/AutoCastOps.cpp:28:70: error: macro "KERNEL_PRIVATEUSEONE" passed 3 arguments, but takes just 2
KERNEL_PRIVATEUSEONE(_convolution, deprecated, lower_precision_fp)

在torch-npu编译成功之后,通过generate_code.sh会生成如下文件:

    torch_npu/csrc/aten/ADInplaceOrViewTypeEverything.cpptorch_npu/csrc/aten/ADInplaceOrViewType_0.cpptorch_npu/csrc/aten/ADInplaceOrViewType_1.cpptorch_npu/csrc/aten/CustomFunctions.cpptorch_npu/csrc/aten/CustomFunctions.htorch_npu/csrc/aten/CustomRedispatch.cpptorch_npu/csrc/aten/CustomRedispatch.htorch_npu/csrc/aten/CustomRegisterSchema.cpptorch_npu/csrc/aten/ForeachRegister.cpptorch_npu/csrc/aten/Functions.cpptorch_npu/csrc/aten/Functions.htorch_npu/csrc/aten/NPUOpApiNativeFunctions.htorch_npu/csrc/aten/QuantizedRegister.cpptorch_npu/csrc/aten/RegisterFunctionalizationEverything.cpptorch_npu/csrc/aten/RegisterFunctionalization_0.cpptorch_npu/csrc/aten/RegisterFunctionalization_1.cpptorch_npu/csrc/aten/RegisterSparseCsrNPU.cpptorch_npu/csrc/aten/RegisterSparseNPU.cpptorch_npu/csrc/aten/VariableType.htorch_npu/csrc/aten/VariableTypeEverything.cpptorch_npu/csrc/aten/VariableType_0.cpptorch_npu/csrc/aten/npu_native_functions_by_codegen.yamltorch_npu/csrc/aten/python_functions.htorch_npu/csrc/aten/python_functionsEverything.cpptorch_npu/csrc/aten/python_functions_0.cpptorch_npu/csrc/aten/python_functions_1.cpptorch_npu/csrc/aten/variable_factories.htorch_npu/testing/_npu_testing_utils.pytorch_npu/utils/custom_ops.pytorch_npu/utils/exposed_api.py

上述文件生成路径默认的是torch_npu/csrc/aten。算子编译信息的yaml文件:torch_npu/csrc/aten/npu_native_functions.yaml

打开上述的的文件中,从中分析可知大概有3种方式实现昇腾npu算子的调用。

3. 算子注册方式

本质上,ascend上对pytroch框架的适配代码,主要是将npu上的算子库对接起来。如何对接这些算子,是一套机制的问题,本身应该不复杂。

3.1 通过torch的regsiter方式

直接调用npu的算子。torch_npu/csrc/aten/RegisterSparseNPU.cpp

TORCH_LIBRARY_IMPL(aten, SparsePrivateUse1, m) {
m.impl("abs", TORCH_FN(wrap_SparseNPU_abs_));
m.impl("abs_", TORCH_FN(wrap_SparseNPU_abs__));
m.impl("abs.out", TORCH_FN(wrap_SparseNPU_abs_out));
m.impl("sgn", TORCH_FN(wrap_SparseNPU_sgn_));
m.impl("sgn_", TORCH_FN(wrap_SparseNPU_sgn__));
m.impl("sgn.out", TORCH_FN(wrap_SparseNPU_sgn_out));

3.2 通过定义算子方式

参考文件:torch_npu/csrc/aten/CustomFunctions.cpp

#include <ATen/core/dispatch/Dispatcher.h>#include "torch_npu/csrc/aten/CustomFunctions.h"namespace at_npu {
namespace native {
namespace custom_ops {int64_t npu_change_data_ptr(const at::Tensor & dst, const at::Tensor & src, int64_t index) {static auto op = c10::Dispatcher::singleton().findSchemaOrThrow("npu::npu_change_data_ptr", "").typed<int64_t (const at::Tensor &, const at::Tensor &, int64_t)>();return op.call(dst, src, index);
}
int64_t get_npu_format(const at::Tensor & self) {static auto op = c10::Dispatcher::singleton().findSchemaOrThrow("npu::get_npu_format", "").typed<int64_t (const at::Tensor &)>();return op.call(self);
}
at::Tensor npu_format_cast(const at::Tensor & self, const at::Tensor & dst) {static auto op = c10::Dispatcher::singleton().findSchemaOrThrow("npu::npu_format_cast", "Tensor").typed<at::Tensor (const at::Tensor &, const at::Tensor &)>();return op.call(self, dst);
}
at::Tensor & npu_format_cast_(at::Tensor & self, int64_t acl_format) {static auto op = c10::Dispatcher::singleton().findSchemaOrThrow("npu::npu_format_cast_", "acl_format").typed<at::Tensor & (at::Tensor &, int64_t)>();return op.call(self, acl_format);at::Tensor & npu_format_cast_(at::Tensor & self, const at::Tensor & src) {static auto op = c10::Dispatcher::singleton().findSchemaOrThrow("npu::npu_format_cast_", "").typed<at::Tensor & (at::Tensor &, const at::Tensor &)>();return op.call(self, src);
}
at::Tensor empty_with_format(at::IntArrayRef size, ::std::optional<at::ScalarType> dtype, ::std::optional<at::Layout> layout, ::std::optional<at::Device> device, ::std::optional<bool> pin_memory, int64_t acl_format) {static auto op = c10::Dispatcher::singleton().findSchemaOrThrow("npu::empty_with_format", "").typed<at::Tensor (at::IntArrayRef, ::std::optional<at::ScalarType>, ::std::optional<at::Layout>, ::std::optional<at::Device>, ::std::optional<bool>, int64_t)>();return op.call(size, dtype, layout, device, pin_memory, acl_format);
}
at::Tensor unsafe_empty_with_format(at::IntArrayRef size, ::std::optional<at::ScalarType> dtype, ::std::optional<at::Layout> layout, ::std::optional<at::Device> device, ::std::optional<bool> pin_memory, int64_t acl_format, bool keep_format) {static auto op = c10::Dispatcher::singleton().findSchemaOrThrow("npu::unsafe_empty_with_format", "").typed<at::Tensor (at::IntArrayRef, ::std::optional<at::ScalarType>, ::std::optional<at::Layout>, ::std::optional<at::Device>, ::std::optional<bool>, int64_t, bool)>();return op.call(size, dtype, layout, device, pin_memory, acl_format, keep_format);
}~/pytorch-ascend/torch_npu/csrc/aten/CustomFunctions.cpp[1,RO]  ...}
}
}

3.3 通过API重定向映射的方式

参考文件:torch_npu/utils/custom_ops.py

torch_npu.npu_layer_norm_eval = torch.ops.npu.npu_layer_norm_eval
torch_npu.npu_fused_attention_score_grad = torch.ops.npu.npu_fused_attention_score_grad
torch_npu.npu_quant_conv2d = torch.ops.npu.npu_quant_conv2d
torch_npu.npu_view_copy = torch.ops.npu.npu_view_copy
torch_npu.npu_fast_gelu = torch.ops.npu.npu_fast_gelu
torch_npu.npu_fused_attention_layernorm_qkv_fwd = torch.ops.npu.npu_fused_attention_layernorm_qkv_fwd
torch_npu.npu_fast_gelu_backward = torch.ops.npu.npu_fast_gelu_backward
torch_npu.npu_bmm_v2_mat1_backward = torch.ops.npu.npu_bmm_v2_mat1_backward

以上属于个人理解,如有错误敬请指正。

http://www.khdw.cn/news/40187.html

相关文章:

  • 空间设计师网站推广普通话宣传周
  • 网页布局设计框架图表杭州优化外包哪里好
  • 网站注销主体填写原因长沙网站se0推广优化公司
  • 专业生产车间设计图纸网站nba赛程排名
  • 织梦网站如何做移动端江门网站开发多少钱
  • 简述网站的制作流程青岛官网seo
  • 腾讯做网站上传pc端百度
  • 微信小程序制作成本手机网站seo免费软件
  • 个人怎么做电影相关的网站线上招生引流推广方法
  • h5网站怎么做的计算机培训机构排名前十
  • 怎么做公司门户网站网址查询ip地址
  • 让网站对搜索引擎友好新闻10条摘抄大全
  • dede网站模板怎么安装百度收录推广
  • 002822中装建设股吧seo 优化案例
  • 鞍山网站页设计制作磁力天堂torrentkitty
  • wordpress栏目文章自定义标题seo排名优化工具
  • 天津网站制作费用买外链有用吗
  • 用织梦的网站怎么做推广给你一个网站怎么优化
  • 免费建自己的网站赚钱如何用html制作网页
  • 网站建设收费标准效果营销案例100例小故事
  • 自己做网站语言构建服务器关键词怎样做优化排名
  • 中小企业网站建设 网络营销百度推广的价格表
  • 大连网站建设公司哪些网站可以免费推广
  • 无锡专业做网站的公司整站seo定制
  • 购物平台推荐引擎搜索优化
  • 做自己的首席安全官的网站域名查询网站入口
  • 整站排名服务上海网站快速排名优化
  • 软件开发需求分析常用的工具福建优化seo
  • 网站管理怎么做江苏网站推广公司
  • 英文网站建设360优化大师