pbootcms网站模板|日韩1区2区|织梦模板||网站源码|日韩1区2区|jquery建站特效-html5模板网

理解 TensorFlow 中的操作注冊和內核鏈接

Understand Op Registration and Kernel Linking in TensorFlow(理解 TensorFlow 中的操作注冊和內核鏈接)
本文介紹了理解 TensorFlow 中的操作注冊和內核鏈接的處理方法,對大家解決問題具有一定的參考價值,需要的朋友們下面隨著小編來一起學習吧!

問題描述

我對 TensorFlow 還很陌生,現在正在研究自定義操作開發.我已經閱讀了官方教程,但我覺得很多事情發生在幕后,我并不總是想將我的自定義操作放在 user_ops 目錄中.

I am fairly new to TensorFlow and right now looking into the custom op development. I have already read the official tutorial but I feel a lot of things happen behind the scenes and I do not always want to put my custom ops in user_ops directory.

因此,我使用了 示例 word2vec

As such, I took up an example word2vec

使用自定義Skipgram"操作,其注冊定義如下:
/word2vec_o??ps.cc
其內核實現在這里:
/word2vec_kernels.cc

which uses a custom "Skipgram" op whose registration is defined here:
/word2vec_ops.cc
and whose kernel implementation is here:
/word2vec_kernels.cc

查看構建文件,我嘗試構建單個目標

Looking at the build file, I tried to build individual targets

1) bazel build -c opt tensorflow/models/embedding:word2vec_o??ps
這會按預期生成一堆目標文件.

1) bazel build -c opt tensorflow/models/embedding:word2vec_ops
This generates bunch of object files as expected.

2) bazel build -c opt tensorflow/models/embedding:word2vec_kernels
同理.

3) bazel build -c opt tensorflow/models/embedding:word2vec_kernels:gen_word2vec

最后一個構建使用自定義規則,即 tf_op_gen_wrapper_pyhttps://github.com/tensorflow/tensorflow/blob/master/tensorflow/tensorflow.bzl#L197-L231

This last build uses a custom rule namely tf_op_gen_wrapper_py https://github.com/tensorflow/tensorflow/blob/master/tensorflow/tensorflow.bzl#L197-L231

有趣的是,這僅取決于操作注冊,而不取決于內核本身.

Interesting to note that this only depends on Op Registration and not on the kernel itself.

畢竟以上,如果我使用

bazel build -c opt tensorflow/models/embedding:word2vec

它工作正常,但我看不到內核 C++ 代碼鏈接的位置和方式?

it works fine, but I fail to see where and how the kernel c++ code linked?

此外,我還想了解 tf_op_gen_wrapper_py 規則以及 ops 注冊幕后的整個編譯/鏈接過程.

Additionally, I would also like to understand the tf_op_gen_wrapper_py rule and the whole compilation/linking procedure that goes behind the scenes for ops registration.

謝謝.

推薦答案

When 為 TensorFlow 添加一種新的操作,主要有兩個步驟:

When adding a new kind of operation to TensorFlow, there are two main steps:

  1. 注冊op",包括為操作定義一個接口,

  1. Registering the "op", which involves defining an interface for the operation, and

注冊一個或多個內核",這涉及為操作定義實現,可能具有針對不同數據類型或設備類型(如 CPU 或 GPU)的專門實現.

Registering one or more "kernels", which involves defining implementation(s) for the operation, perhaps with specialized implementations for different data types, or device types (like CPU or GPU).

這兩個步驟都涉及編寫 C++ 代碼.注冊操作使用 REGISTER_OP 宏,注冊內核使用 REGISTER_KERNEL_BUILDER() 宏.這些宏創建靜態初始化程序,在加載包含它們的模塊時運行.op和kernel注冊主要有兩種機制:

Both steps involve writing C++ code. Registering an op uses the REGISTER_OP() macro, and registering a kernel uses the REGISTER_KERNEL_BUILDER() macro. These macros create static initializers that run when the module containing them is loaded. There are two main mechanisms for op and kernel registration:

  1. 靜態鏈接到核心 TensorFlow 庫,以及靜態初始化.

  1. Static linking into the core TensorFlow library, and static initialization.

運行時動態鏈接,使用 tf.load_op_library() 函數.

Dynamic linking at runtime, using the tf.load_op_library() function.

"Skipgram" 的情況下,我們使用選項 1(靜態鏈接).操作鏈接到核心 TensorFlow 庫此處內核鏈接在這里.(請注意,這并不理想:word2vec 操作是在我們擁有 tf.load_op_library() 之前創建的,因此沒有動態鏈接它們的機制.)因此首次加載 TensorFlow 時會注冊操作和內核(在 import tensorflow as tf 中).如果它們是今天創建的,它們將被動態加載,這樣它們只會在需要時才被注冊.(SyntaxNet 代碼有一個示例.)

In the case of "Skipgram", we use option 1 (static linking). The ops are linked into the core TensorFlow library here, and the kernels are linked in here. (Note that this is not ideal: the word2vec ops were created before we had tf.load_op_library(), and so there was no mechanism for linking them dynamically.) Hence the ops and kernels are registered when you first load TensorFlow (in import tensorflow as tf). If they were created today, they would be dynamically loaded, such that they would only be registered if they were needed. (The SyntaxNet code has an example of dynamic loading.)

tfper_op()op 庫依賴項列表,并為這些操作生成 Python 包裝器.該規則僅取決于 op 注冊的原因是 Python 包裝器完全由 op 的接口決定,該接口在 op 注冊中定義.值得注意的是,Python 接口不知道是否有針對特定類型或設備的專用內核.包裝器生成器將 op 注冊鏈接到 簡單的 C++ 二進制文件/a> 為每個注冊的操作生成 Python 代碼.請注意,如果使用tf.load_op_library(),則不需要自己調用包裝器生成器,因為tf.load_op_library() 會在運行時生成必要的代碼.

The tf_op_gen_wrapper_py() rule in Bazel takes a list of op-library dependencies and generates Python wrappers for those ops. The reason that this rule depends only on the op registration is that the Python wrappers are determined entirely by the interface of the op, which is defined in the op registration. Notably, the Python interface has no idea whether there are specialized kernels for a particular type or device. The wrapper generator links the op registrations into a simple C++ binary that generates Python code for each of the registered ops. Note that, if you use tf.load_op_library(), you do not need to invoke the wrapper generator yourself, because tf.load_op_library() will generate the necessary code at runtime.

這篇關于理解 TensorFlow 中的操作注冊和內核鏈接的文章就介紹到這了,希望我們推薦的答案對大家有所幫助,也希望大家多多支持html5模板網!

【網站聲明】本站部分內容來源于互聯網,旨在幫助大家更快的解決問題,如果有圖片或者內容侵犯了您的權益,請聯系我們刪除處理,感謝您的支持!

相關文檔推薦

Assertion failed (size.widthgt;0 amp;amp; size.heightgt;0)(斷言失敗(size.width0 amp;amp; size.height0))
Rotate an image in C++ without using OpenCV functions(在 C++ 中旋轉圖像而不使用 OpenCV 函數)
OpenCV: process every frame(OpenCV:處理每一幀)
Why can#39;t I open avi video in openCV?(為什么我不能在 openCV 中打開 avi 視頻?)
OpenCV unable to set up SVM Parameters(OpenCV 無法設置 SVM 參數)
Convert a single color with cvtColor(使用 cvtColor 轉換單一顏色)
主站蜘蛛池模板: 二次元影像仪|二次元测量仪|拉力机|全自动影像测量仪厂家_苏州牧象仪器 | 布袋除尘器|除尘器设备|除尘布袋|除尘设备_诺和环保设备 | 升降机-高空作业车租赁-蜘蛛车-曲臂式伸缩臂剪叉式液压升降平台-脚手架-【普雷斯特公司厂家】 | 杭州厂房降温,车间降温设备,车间通风降温,厂房降温方案,杭州嘉友实业爽风品牌 | 吸污车_吸粪车_抽粪车_电动三轮吸粪车_真空吸污车_高压清洗吸污车-远大汽车制造有限公司 | 双能x射线骨密度检测仪_dxa骨密度仪_双能x线骨密度仪_品牌厂家【品源医疗】 | 蓝鹏测控平台 - 智慧车间系统 - 车间生产数据采集与分析系统 | 多物理场仿真软件_电磁仿真软件_EDA多物理场仿真软件 - 裕兴木兰 | 青岛侦探_青岛侦探事务所_青岛劝退小三_青岛婚外情取证-青岛王军侦探事务所 | 乐之康护 - 专业护工服务平台,提供医院陪护-居家照护-居家康复 | 体检车_移动CT车_CT检查车_CT车_深圳市艾克瑞电气有限公司移动CT体检车厂家-深圳市艾克瑞电气有限公司 | LNG鹤管_内浮盘价格,上装鹤管,装车撬厂家-连云港赛威特机械 | 台式核磁共振仪,玻璃软化点测定仪,旋转高温粘度计,测温锥和测温块-上海麟文仪器 | 高低温老化试验机-步入式/低温恒温恒湿试验机-百科 | 干式变压器厂_干式变压器厂家_scb11/scb13/scb10/scb14/scb18干式变压器生产厂家-山东科锐变压器有限公司 | 合肥弱电工程_安徽安防工程_智能化工程公司-合肥雷润 | 中高频感应加热设备|高频淬火设备|超音频感应加热电源|不锈钢管光亮退火机|真空管烤消设备 - 郑州蓝硕工业炉设备有限公司 | 24位ADC|8位MCU-芯易德科技有限公司 | 连栋温室大棚建造厂家-智能玻璃温室-薄膜温室_青州市亿诚农业科技 | 制丸机,小型中药制丸机,全自动制丸机价格-甘肃恒跃制药设备有限公司 | 超声波分散机-均质机-萃取仪-超声波涂料分散设备-杭州精浩 | 滚筒烘干机_转筒烘干机_滚筒干燥机_转筒干燥机_回转烘干机_回转干燥机-设备生产厂家 | 跨境物流_美国卡派_中大件运输_尾程派送_海外仓一件代发 - 广州环至美供应链平台 | 精密光学实验平台-红外粉末压片机模具-天津博君 | 广州小程序开发_APP开发公司_分销商城系统定制_小跑科技 | 浙江建筑资质代办_二级房建_市政_电力_安许_劳务资质办理公司 | 深圳市源和塑胶电子有限公司-首页 | 啤酒设备-小型啤酒设备-啤酒厂设备-济南中酿机械设备有限公司 | POM塑料_PBT材料「进口」聚甲醛POM杜邦原料、加纤PBT塑料报价格找利隆塑料 | 企业微信营销_企业微信服务商_私域流量运营_艾客SCRM官网 | 聚合氯化铝价格_聚合氯化铝厂家_pac絮凝剂-唐达净水官网 | 步入式高低温测试箱|海向仪器| 水厂污泥地磅|污泥处理地磅厂家|地磅无人值守称重系统升级改造|地磅自动称重系统维修-河南成辉电子科技有限公司 | 皮带机_移动皮带机_大倾角皮带机_皮带机厂家 - 新乡市国盛机械设备有限公司 | 出国劳务公司_正规派遣公司[严海]| RFID电子标签厂家-上海尼太普电子有限公司 | 税筹星_灵活用工平台_企业财务顾问_财税法薪综合服务平台 | 软启动器-上海能曼电气有限公司 真空搅拌机-行星搅拌机-双行星动力混合机-广州市番禺区源创化工设备厂 | 江苏全风,高压风机,全风环保风机,全风环形高压风机,防爆高压风机厂家-江苏全风环保科技有限公司(官网) | 光栅尺_Magnescale探规_磁栅尺_笔式位移传感器_苏州德美达 | T恤衫定做,企业文化衫制作订做,广告T恤POLO衫定制厂家[源头工厂]-【汉诚T恤定制网】 |