我想使用推力将内存从主机复制到设备
thrust::host_vector<float> h_vec(1 << 28);
thrust::device_vector<float> d_vec(1 << 28);
thrust::copy(h_vec.begin(), h_vec.end(), d_vec.begin());
Run Code Online (Sandbox Code Playgroud)
使用CUDA流类似于使用流将内存从设备复制到设备的方式:
cudaStream_t s;
cudaStreamCreate(&s);
thrust::device_vector<float> d_vec1(1 << 28), d_vec2(1 << 28);
thrust::copy(thrust::cuda::par.on(s), d_vec1.begin(), d_vec1.end(), d_vec2.begin());
cudaStreamSynchronize(s);
cudaStreamDestroy(s);
Run Code Online (Sandbox Code Playgroud)
问题是我无法将执行策略设置为CUDA以在从主机复制到设备时指定流,因为在这种情况下,推力会假设两个向量都存储在设备上.有办法解决这个问题吗?我正在使用github的最新推力版本(它在version.h文件中显示为1.8).
我正在尝试3使用3流来实现“-方式重叠”,如CUDA流和并发网络研讨会中的示例所示。但是我做不到。
我有Geforce GT 550M(带有一个复制引擎的费米架构),并且我正在使用Windows 7(64位)。
这是我编写的代码。
#include <iostream>
#include "cuda_runtime.h"
#include "device_launch_parameters.h"
// includes, project
#include "helper_cuda.h"
#include "helper_functions.h" // helper utility functions
#include <stdio.h>
using namespace std;
#define DATA_SIZE 6000000
#define NUM_THREADS 32
#define NUM_BLOCKS 16
#define NUM_STREAMS 3
__global__ void kernel(const int *in, int *out, int dataSize)
{
int start = blockIdx.x * blockDim.x + threadIdx.x;
int end = dataSize;
for (int i = start; i < end; i += blockDim.x * …Run Code Online (Sandbox Code Playgroud)