我需要计算GPU运行时代码,以及总运行代码(主机和设备)。在我的代码中,我有两个gpu内核在运行,在主机for循环之间复制数据,下面的示例可以显示我的代码是什么样子的。
cuda event start
//FIRST kernel code call <<...>>
// cuda memory copy result back from device to host
CudadeviceSyncronize()
// copy host data to host array (CPU funtion loop)
// cuda memory copy fr
我是OpenCL的新手,试图找出OpenCL和hashes的优缺点。
例如,我有一个琐碎的散列函数:
public static uint GetHash(string str)
{
uint s = 21; // seed
foreach (char ch in str)
s = (s + (uint)ch) * 10;
return s;
}
(我知道这是个可怕的哈希,但这只是一个例子)
现在假设我希望计算出所有字符a-zA-Z0-9_的排列长度为50,例如:
a
b
...
_
aa
ab
...
__
显然,这是我需要计算的大量散列(63^50),所以我决定使用
在tensorflow关于的指南中,有一段代码如下:
import time
def measure(x, steps):
# TensorFlow initializes a GPU the first time it's used, exclude from timing.
tf.matmul(x, x)
start = time.time()
for i in range(steps):
x = tf.matmul(x, x)
_ = x.numpy() # Make sure to execute op and not just enq
我已经写了一个简单的Halide代码来计算从0到n的数字的平方,然而它在GPU上比在CPU上多花22倍的时间。
#include"stdafx.h"
#include "Halide.h"
#include <stdio.h>
using namespace Halide;
#include "HalideRuntimeOpenCL.h"
#define GPU_TILE 16
#define COMPUTE_SIZE 1024
Target find_gpu_target();
// Define some Vars to u
我有两个GPU,一个内核,一个上下文和两个命令队列(每个GPU一个)。我尝试在一个循环中运行它们,其中每个命令队列都会运行,然后我尝试了queue.finish()和queue.flush(),希望在GPU上同时运行工作。
但实际发生的情况是,数据首先被发送到一个设备,GPU执行其工作,然后另一个GPU开始工作。它需要的时间是使用单个GPU的两倍。这不是我想要达到的目的!
虽然我也将缓冲区读回到主机代码中,有人可能会认为这可能是第二个GPU等待第一个GPU的结果的问题。但我也在没有任何运气的情况下注释了结果的读数。还是老样子。
for (unsigned int iter = 0; iter
我在这里有一个无聊的脚本,我正在MATLAB R2013b中执行:
clear all;
n = 2000;
times = 50;
i = 0;
tCPU = tic;
disp 'CPU::'
A = rand(n, n);
B = rand(n, n);
disp '::Go'
for i = 0:times
CPU = A * B;
end
tCPU = toc(tCPU);
tGPU = tic;
disp 'GPU::'
A = gpuArray(A);
B = gpuArray(B);
disp '::Go
我有以下全局内核:
__global__ void pdegpu(PDE_ParabolicD1_Num_GPU **pdes)
{
PDE_ParabolicD1_Num_GPU *loc;
loc = new PDE_ParabolicD1_Num_GPU();
loc->Setup();
delete loc;
//above code was just an example to show that new and delete work fine
*pdes = new PDE_ParabolicD1_Num_GPU()