Tensorflow tf.matmul不利用Nvidia Tensor Cores

如何解决Tensorflow tf.matmul不利用Nvidia Tensor Cores

有人在Nvidia RTX 2080 Ti中使用Tensor Core运行tf.matmul()吗?如果是这样,请告诉我如何。我正在使用以下版本:

tensorboard                   2.2.2              
tensorboard-plugin-wit        1.7.0              
tensorflow                    2.2.0              
tensorflow-estimator          2.2.0  

得到以下Python脚本:

import tensorflow as tf
import argparse
import logging
from time import perf_counter

parser = argparse.ArgumentParser(description='Process some integers.')
parser.add_argument('--number',dest='number',action='store',type=int,default=1024,help='Optional,integer')
parser.add_argument('--dtype',dest='dtype',type=str,default='float32',choices=['float64','float32','float16','bfloat16','int64','int32','int16','int8','uint64','uint32','uint16','uint8'],dtype')

args = parser.parse_args()

size = args.number;

print("Num GPUs Available: ",len(tf.config.experimental.list_physical_devices('GPU')))

tf.debugging.set_log_device_placement(True)

logging.info("Generating a %dx%d randomUniform matrix,please standby",size,size);
t1_start = perf_counter()
matrix = tf.random_uniform_initializer(minval=0,maxval=1,seed=2)(shape=[size,size],dtype=args.dtype);
t1_stop = perf_counter()
print("Generating a ","x"," matrix took: ",(t1_stop - t1_start),'s')

# Initialize cuBLAS....
temp = tf.constant([0.0,1.0,2.0,3.0],shape=[2,2],dtype="float32");
temp2 = tf.matmul(temp,temp,transpose_a=False,transpose_b=True);

t1_start = perf_counter()
result = tf.matmul(matrix,matrix,transpose_b=True);
t1_stop = perf_counter()
print("Multiplying a ",'s')

我运行了两次,每次运行都为Tensor Core设置了不同的环境变量。

编辑: 我以前使用数据类型 float32 进行了此测试。但是,tensorflow 2.3.0只能使用 float16 ,更具体地说是 CUDA_R_16F 的Tensor Core。

从tensorflow 2.3.0开始,已删除对环境变量TF_DISABLE_CUBLAS_TENSOR_OP_MATH的使用(请参见commit)。

所以我在Tensorflow 2.2.0上使用数据类型float16重新运行了测试

张量芯已禁用:

TF_DISABLE_CUBLAS_TENSOR_OP_MATH=1
TF_ENABLE_CUBLAS_TENSOR_OP_MATH_FP32=0
TF_ENABLE_CUDNN_TENSOR_OP_MATH_FP32=0
TF_ENABLE_CUDNN_RNN_TENSOR_OP_MATH_FP32=0
NUMBER=16384
DTYPE=float16            
2020-08-21 12:44:28.189777: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcuda.so.1
2020-08-21 12:44:32.243417: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties: 
pciBusID: 0000:5a:00.0 name: GeForce RTX 2080 Ti computeCapability: 7.5
coreClock: 1.545GHz coreCount: 68 deviceMemorySize: 10.76GiB deviceMemoryBandwidth: 573.69GiB/s
2020-08-21 12:44:32.243729: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2020-08-21 12:44:32.246376: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10
2020-08-21 12:44:32.249129: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10
2020-08-21 12:44:32.249554: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcurand.so.10
2020-08-21 12:44:32.252491: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusolver.so.10
2020-08-21 12:44:32.254002: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusparse.so.10
2020-08-21 12:44:32.259926: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
2020-08-21 12:44:32.281312: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0
2020-08-21 12:44:32.282146: I tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 AVX512F FMA
2020-08-21 12:44:32.291868: I tensorflow/core/platform/profile_utils/cpu_utils.cc:102] CPU Frequency: 2600000000 Hz
2020-08-21 12:44:32.292063: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x3547ca0 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-08-21 12:44:32.292081: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host,Default Version
2020-08-21 12:44:32.694055: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x35ba180 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:
2020-08-21 12:44:32.694078: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): GeForce RTX 2080 Ti,Compute Capability 7.5
2020-08-21 12:44:32.696876: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties: 
pciBusID: 0000:5a:00.0 name: GeForce RTX 2080 Ti computeCapability: 7.5
coreClock: 1.545GHz coreCount: 68 deviceMemorySize: 10.76GiB deviceMemoryBandwidth: 573.69GiB/s
2020-08-21 12:44:32.696914: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2020-08-21 12:44:32.696931: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10
2020-08-21 12:44:32.696947: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10
2020-08-21 12:44:32.696957: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcurand.so.10
2020-08-21 12:44:32.696967: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusolver.so.10
2020-08-21 12:44:32.696976: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusparse.so.10
2020-08-21 12:44:32.696985: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
2020-08-21 12:44:32.715821: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0
2020-08-21 12:44:32.715858: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2020-08-21 12:44:32.718333: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-08-21 12:44:32.718348: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1108]      0 
2020-08-21 12:44:32.718356: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1121] 0:   N 
2020-08-21 12:44:32.723419: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1247] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 10204 MB memory) -> physical GPU (device: 0,name: GeForce RTX 2080 Ti,pci bus id: 0000:5a:00.0,compute capability: 7.5)
2020-08-21 12:44:32.725151: I tensorflow/core/common_runtime/eager/execute.cc:501] Executing op StatelessRandomUniform in device /job:localhost/replica:0/task:0/device:GPU:0
2020-08-21 12:44:41.983001: I tensorflow/core/common_runtime/eager/execute.cc:501] Executing op Sub in device /job:localhost/replica:0/task:0/device:GPU:0
2020-08-21 12:44:41.984023: I tensorflow/core/common_runtime/eager/execute.cc:501] Executing op Mul in device /job:localhost/replica:0/task:0/device:GPU:0
2020-08-21 12:44:42.230340: I tensorflow/core/common_runtime/eager/execute.cc:501] Executing op Add in device /job:localhost/replica:0/task:0/device:GPU:0
2020-08-21 12:44:42.231872: I tensorflow/core/common_runtime/eager/execute.cc:501] Executing op MatMul in device /job:localhost/replica:0/task:0/device:GPU:0
2020-08-21 12:44:42.232362: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10
Num GPUs Available:  1
Generating a  16384 x 16384  matrix took:  0.0007753130048513412 s
Multiplying a  16384 x 16384  matrix took:  0.00017198268324136734 s

已启用张量核心:

TF_DISABLE_CUBLAS_TENSOR_OP_MATH=0
TF_ENABLE_CUBLAS_TENSOR_OP_MATH_FP32=1
TF_ENABLE_CUDNN_TENSOR_OP_MATH_FP32=1
TF_ENABLE_CUDNN_RNN_TENSOR_OP_MATH_FP32=1
NUMBER=16384
DTYPE=float16      
2020-08-21 12:44:28.189996: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcuda.so.1
2020-08-21 12:44:32.153926: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties: 
pciBusID: 0000:62:00.0 name: GeForce RTX 2080 Ti computeCapability: 7.5
coreClock: 1.545GHz coreCount: 68 deviceMemorySize: 10.76GiB deviceMemoryBandwidth: 573.69GiB/s
2020-08-21 12:44:32.155894: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2020-08-21 12:44:32.173061: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10
2020-08-21 12:44:32.177611: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10
2020-08-21 12:44:32.179239: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcurand.so.10
2020-08-21 12:44:32.184143: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusolver.so.10
2020-08-21 12:44:32.186975: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusparse.so.10
2020-08-21 12:44:32.195284: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
2020-08-21 12:44:32.211230: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0
2020-08-21 12:44:32.212211: I tensorflow/core/platform/cpu_feature_guard.cc:143] Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX2 AVX512F FMA
2020-08-21 12:44:32.223121: I tensorflow/core/platform/profile_utils/cpu_utils.cc:102] CPU Frequency: 2600000000 Hz
2020-08-21 12:44:32.223348: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x3547d60 initialized for platform Host (this does not guarantee that XLA will be used). Devices:
2020-08-21 12:44:32.223367: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): Host,Default Version
2020-08-21 12:44:32.658935: I tensorflow/compiler/xla/service/service.cc:168] XLA service 0x35ba260 initialized for platform CUDA (this does not guarantee that XLA will be used). Devices:
2020-08-21 12:44:32.658973: I tensorflow/compiler/xla/service/service.cc:176]   StreamExecutor device (0): GeForce RTX 2080 Ti,Compute Capability 7.5
2020-08-21 12:44:32.660135: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1561] Found device 0 with properties: 
pciBusID: 0000:62:00.0 name: GeForce RTX 2080 Ti computeCapability: 7.5
coreClock: 1.545GHz coreCount: 68 deviceMemorySize: 10.76GiB deviceMemoryBandwidth: 573.69GiB/s
2020-08-21 12:44:32.660175: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2020-08-21 12:44:32.660187: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10
2020-08-21 12:44:32.660197: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcufft.so.10
2020-08-21 12:44:32.660206: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcurand.so.10
2020-08-21 12:44:32.660215: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusolver.so.10
2020-08-21 12:44:32.660225: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcusparse.so.10
2020-08-21 12:44:32.660235: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudnn.so.7
2020-08-21 12:44:32.662855: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1703] Adding visible gpu devices: 0
2020-08-21 12:44:32.662896: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcudart.so.10.1
2020-08-21 12:44:32.664538: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1102] Device interconnect StreamExecutor with strength 1 edge matrix:
2020-08-21 12:44:32.664554: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1108]      0 
2020-08-21 12:44:32.664564: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1121] 0:   N 
2020-08-21 12:44:32.694148: I tensorflow/core/common_runtime/gpu/gpu_device.cc:1247] Created TensorFlow device (/job:localhost/replica:0/task:0/device:GPU:0 with 10204 MB memory) -> physical GPU (device: 0,pci bus id: 0000:62:00.0,compute capability: 7.5)
2020-08-21 12:44:32.696836: I tensorflow/core/common_runtime/eager/execute.cc:501] Executing op StatelessRandomUniform in device /job:localhost/replica:0/task:0/device:GPU:0
2020-08-21 12:44:41.882224: I tensorflow/core/common_runtime/eager/execute.cc:501] Executing op Sub in device /job:localhost/replica:0/task:0/device:GPU:0
2020-08-21 12:44:41.883265: I tensorflow/core/common_runtime/eager/execute.cc:501] Executing op Mul in device /job:localhost/replica:0/task:0/device:GPU:0
2020-08-21 12:44:42.230553: I tensorflow/core/common_runtime/eager/execute.cc:501] Executing op Add in device /job:localhost/replica:0/task:0/device:GPU:0
2020-08-21 12:44:42.233699: I tensorflow/core/common_runtime/eager/execute.cc:501] Executing op MatMul in device /job:localhost/replica:0/task:0/device:GPU:0
2020-08-21 12:44:42.234656: I tensorflow/stream_executor/platform/default/dso_loader.cc:44] Successfully opened dynamic library libcublas.so.10
Num GPUs Available:  1
Generating a  16384 x 16384  matrix took:  0.0015629231929779053 s
Multiplying a  16384 x 16384  matrix took:  0.00017150864005088806 s

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。

相关推荐


依赖报错 idea导入项目后依赖报错,解决方案:https://blog.csdn.net/weixin_42420249/article/details/81191861 依赖版本报错:更换其他版本 无法下载依赖可参考:https://blog.csdn.net/weixin_42628809/a
错误1:代码生成器依赖和mybatis依赖冲突 启动项目时报错如下 2021-12-03 13:33:33.927 ERROR 7228 [ main] o.s.b.d.LoggingFailureAnalysisReporter : *************************** APPL
错误1:gradle项目控制台输出为乱码 # 解决方案:https://blog.csdn.net/weixin_43501566/article/details/112482302 # 在gradle-wrapper.properties 添加以下内容 org.gradle.jvmargs=-Df
错误还原:在查询的过程中,传入的workType为0时,该条件不起作用 <select id="xxx"> SELECT di.id, di.name, di.work_type, di.updated... <where> <if test=&qu
报错如下,gcc版本太低 ^ server.c:5346:31: 错误:‘struct redisServer’没有名为‘server_cpulist’的成员 redisSetCpuAffinity(server.server_cpulist); ^ server.c: 在函数‘hasActiveC
解决方案1 1、改项目中.idea/workspace.xml配置文件,增加dynamic.classpath参数 2、搜索PropertiesComponent,添加如下 <property name="dynamic.classpath" value="tru
删除根组件app.vue中的默认代码后报错:Module Error (from ./node_modules/eslint-loader/index.js): 解决方案:关闭ESlint代码检测,在项目根目录创建vue.config.js,在文件中添加 module.exports = { lin
查看spark默认的python版本 [root@master day27]# pyspark /home/software/spark-2.3.4-bin-hadoop2.7/conf/spark-env.sh: line 2: /usr/local/hadoop/bin/hadoop: No s
使用本地python环境可以成功执行 import pandas as pd import matplotlib.pyplot as plt # 设置字体 plt.rcParams['font.sans-serif'] = ['SimHei'] # 能正确显示负号 p
错误1:Request method ‘DELETE‘ not supported 错误还原:controller层有一个接口,访问该接口时报错:Request method ‘DELETE‘ not supported 错误原因:没有接收到前端传入的参数,修改为如下 参考 错误2:cannot r
错误1:启动docker镜像时报错:Error response from daemon: driver failed programming external connectivity on endpoint quirky_allen 解决方法:重启docker -> systemctl r
错误1:private field ‘xxx‘ is never assigned 按Altʾnter快捷键,选择第2项 参考:https://blog.csdn.net/shi_hong_fei_hei/article/details/88814070 错误2:启动时报错,不能找到主启动类 #
报错如下,通过源不能下载,最后警告pip需升级版本 Requirement already satisfied: pip in c:\users\ychen\appdata\local\programs\python\python310\lib\site-packages (22.0.4) Coll
错误1:maven打包报错 错误还原:使用maven打包项目时报错如下 [ERROR] Failed to execute goal org.apache.maven.plugins:maven-resources-plugin:3.2.0:resources (default-resources)
错误1:服务调用时报错 服务消费者模块assess通过openFeign调用服务提供者模块hires 如下为服务提供者模块hires的控制层接口 @RestController @RequestMapping("/hires") public class FeignControl
错误1:运行项目后报如下错误 解决方案 报错2:Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:3.8.1:compile (default-compile) on project sb 解决方案:在pom.
参考 错误原因 过滤器或拦截器在生效时,redisTemplate还没有注入 解决方案:在注入容器时就生效 @Component //项目运行时就注入Spring容器 public class RedisBean { @Resource private RedisTemplate<String
使用vite构建项目报错 C:\Users\ychen\work>npm init @vitejs/app @vitejs/create-app is deprecated, use npm init vite instead C:\Users\ychen\AppData\Local\npm-