我目前正试图从我的代码中删除部分繁琐的cudaMallocHost/cudaFreeHost.为此,我愿意只使用std :: vector,但我绝对需要底层内存必须是固定的cuda内存类型.
但是,我使用thrust::system::cuda::experimental::pinned_allocator<>推力库中的奇怪行为:
//STL
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
//CUDA
#include <cuda_runtime.h>
#include <thrust/device_vector.h>
#include <thrust/transform.h>
#include <thrust/system/cuda/experimental/pinned_allocator.h>
#define SIZE 4
#define INITVAL 2
#define ENDVAL 4
//Compile using nvcc ./main.cu -o test -std=c++11
int main( int argc, char* argv[] )
{
// init host
std::vector<float,thrust::system::cuda::experimental::pinned_allocator<float> > hostVec(SIZE);
std::fill(hostVec.begin(),hostVec.end(),INITVAL);
//Init device
thrust::device_vector<float> thrustVec(hostVec.size());
//Copy
thrust::copy(hostVec.begin(), hostVec.end(), thrustVec.begin());
//std::cout << "Dereferencing values of the device, values should be "<< INITVAL << std::endl;
std::for_each(thrustVec.begin(),thrustVec.end(),[](float in){ std::cout …Run Code Online (Sandbox Code Playgroud) 问题很简单,为什么这段代码不起作用:
#include <tuple>
int main( int argc, char* argv[]) {
const int a,b = std::tie(std::make_pair(1,2));
return EXIT_SUCCESS;
}
Run Code Online (Sandbox Code Playgroud)
g ++给了我这个错误:
./test.cpp:在函数'int main(int,char**)'中:./ test.cpp:4:13:error:uninitialized const'a'[-fpermissive] const int a,b = std ::领带(标准:: make_pair(1,2)); ^ ./test.cpp:4:42:
error:无法将类型为'std :: pair&'的非const左值引用绑定到类型为'std :: pair'的rvalue
const int a,b = std :: tie(std :: make_pair(1,2));
使用这种模式(const或非const),我无法通过值获得任何类似元组的返回.这是一个更好的方式来做我想在这里实现的目标吗?
我尝试编写一个脚本,帮助根据用户输入选择pytest选项.不幸的是,脚本总是失败,因为最新的参数与标记有关.
我怀疑标记选项中的引号是问题的根源.不幸的是,我找不到任何解决方法.
这是MWE:
test.sh的内容
#!/bin/bash
options=("-v")
options+=("-m \"not dummy\"")
echo "about to launch pytest ${options[@]}"
pytest ${options[@]}
Run Code Online (Sandbox Code Playgroud)
test_dummy.py的内容:
import pytest
@pytest.mark.dummy
def test_dummy():
assert(True)
Run Code Online (Sandbox Code Playgroud)
现在运行test.sh脚本的输出:
即将推出pytest -v -m"not dummy"====================================== ================================================== =======================================测试会话开始======== ================================================== ================================================== =================== platform linux - Python 3.6.4,pytest-3.3.2,py-1.5.2,pluggy-0.6.0 - /home/[...]/anaconda3/bin/python cachedir:.cache rootdir:/home/[...]/pytest,inifile:pluinsins:cov-2.5.1
================================================== ================================================== ======================没有测试在0.00秒内运行====================== ================================================== ================================================== =错误:找不到文件:dummy"
当然,运行生成的命令
pytest -v -m"not dummy"
完美的工作.如何克服这个问题
先感谢您