设备内存刷新cuda [英] Device memory flush cuda

查看:250
本文介绍了设备内存刷新cuda的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在运行一个C程序,我调用两次cuda主机函数。我想清除这两个调用之间的设备内存。有没有办法我可以冲刷GPU设备内存?我在计算能力为2.0的特斯拉M2050上

I'm running a C program where I call twice a cuda host function. I want to clean up the device memory between these 2 calls. Is there a way I can flush GPU device memory?? I'm on a Tesla M2050 with computing capability of 2.0

推荐答案

如果你只想要记忆, $ c> cudaMemset 可能是最简单的方法。例如:

If you only want to zero the memory, then cudaMemset is probably the simplest way to do this. For example:

const int n = 10000000;
const int sz = sizeof(float) * n;
float *devicemem;
cudaMalloc((void **)&devicemem, sz);

kernel<<<...>>>(devicemem,....);
cudaMemset(devicemem, 0, sz); // zeros all the bytes in devicemem
kernel<<<...>>>(devicemem,....);

请注意,值 cudaMemset 字节值,并且指定范围内的所有字节都设置为该值,就像标准C memset 。如果您有特定的值,那么您需要编写自己的memset内核以分配值。

Note that the value cudaMemset takes is a byte value, and all bytes in the specified range are set to that value, just like the standard C memset. If you have a specific word value, then you will need to write your own memset kernel to assign the values.

这篇关于设备内存刷新cuda的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆