问题:是否有任何(特定于供应商)方式来获取英特尔图形卡的PCIe总线(或获得英特尔GPU的任何其他唯一ID(每个供应商的唯一性)).
我知道如果不使用Vendor-Specific-Extensions我就无法获得这些信息.我知道对于AMD,使用cl_amd_device_topology,我可以获得这些信息.对于NVIDIA,我可以使用cl_nv_device_attribute_query和CL_DEVICE_PCI_BUS_ID_NV来获取它.
在simd教程中,我找到了以下代码片段。
void simd(float* a, int N)
{
// We assume N % 4 == 0.
int nb_iters = N / 4;
__m128* ptr = reinterpret_cast<__m128*>(a); // (*)
for (int i = 0; i < nb_iters; ++i, ++ptr, a += 4)
_mm_store_ps(a, _mm_sqrt_ps(*ptr));
}
Run Code Online (Sandbox Code Playgroud)
现在我的问题是,带有(*)未定义行为的行吗?由于来自(https://en.cppreference.com/w/cpp/language/reinterpret_cast)的以下规范
每当尝试通过AliasedType类型的glvalue读取或修改DynamicType类型的对象的存储值时,除非满足以下条件之一,否则行为是不确定的:
- AliasedType和DynamicType相似。
- AliasedType是DynamicType的(可能是cv限定的)带符号或无符号的变体。
- AliasedType是std :: byte,(从C ++ 17开始)char或unsigned char:这允许将任何对象的对象表示形式检查为字节数组。
在这种情况下,有人如何防止未定义的行为?我知道我可以std :: memcopy,但是性能下降会使simd失去作用,或者我错了吗?
问题 std::future 在销毁时调用 wait() 或 get() 吗?
例子
void fun()
{
std::future<int> fut = my_thread_pool.submit(some_work);
}//is fut.wait() or fut.get() called? here
Run Code Online (Sandbox Code Playgroud) 我正在使用 Visual Studio 2013,我想实现这行代码
f = p.get_future();
auto task =[f = std::move(f)](){
//use f
};
Run Code Online (Sandbox Code Playgroud)
我知道这里的解决方案
,但不幸的是这不能在 VS2013 ( error C2558 no copy-constructor available)下编译。
我发现这个 OpenCL:运行CPU/GPU多个设备.
但我仍然有疑问(3)如何在多个设备上运行程序.配方如下?(Q1)
创建您要使用的设备.
为每个设备创建一个上下文.
为每个上下文调用clBuilProgram来构建程序
对于每个程序调用clCreateCommandQueue来为每个上下文构建一个命令队列
对于每个上下文和每个函数参数调用clCreateBuffer.
或者我必须连接CommandQueues.(Q2)
有人一些示例代码或教程的链接?(Q3)
我有一个(成员)功能重载像这样:
bool foo(bool);
int foo(int);
float foo(float);
...
std::string foo( std::string const&);
Run Code Online (Sandbox Code Playgroud)
对于几种内置类型但不适用于const char*.打电话foo("beauty is only skin-deep");,我的大惊喜,叫foo的函数的布尔变.这引出了我的问题:
问题:是否为内置类型定义了明确的隐式转换顺序
不是问题:如何避免隐式转换.隐含转换是多么邪恶....
编辑:删除了有关用户定义问题的隐式转换顺序的问题
我正在使用尺寸为5x5和7x7的OpenCV Sobel滤镜来计算图像导数.
有人可以告诉我OpenCV中尺寸为5x5和7x7的Sobel滤波器的内核值吗?在进行谷歌搜索时,它向我展示了许多不同的内核.
以下是5 x 5的一些示例:
2 1 0 -1 -2
4 8 0 -4 -8
6 12 0 -12 -6
4 8 0 -4 -8
2 1 0 -1 -2
Run Code Online (Sandbox Code Playgroud)
2 1 0 -1 -2
4 10 0 -4 -10
7 17 0 -17 -7
4 10 0 -4 -10
2 1 0 -1 -2
Run Code Online (Sandbox Code Playgroud)
2 1 0 -1 -2
3 2 0 -2 -3
4 3 0 -3 -4
3 2 0 -2 -3
2 …Run Code Online (Sandbox Code Playgroud) 以下代码片段在我的编译器(visual studio)上始终返回true.但这种行为是否定义良好且可移植?
bool return_always_true(std::string const& str)
{
return str.find("") != std::string::npos;
}
int main(){
cout << boolapha << return_always_true("") << endl
<< return_always_true("oxylottl") << endl
<< return_always_true("lorem ipsum") << endl;
//true true true
}
Run Code Online (Sandbox Code Playgroud) 我正在与旧的C风格界面作斗争.我有一个像这样的签名功能:
/// if return_value == NULL only the length is returned
void f( char * return_value, size_t * size_only_known_at_runtime);
Run Code Online (Sandbox Code Playgroud)
我的问题是,以下代码是否安全?
std::size required;
f( NULL, &required );
std::string s;
s.resize(required);
f( &s[0], &required );
Run Code Online (Sandbox Code Playgroud)
有没有更好的方法将数据输入字符串?
我想使用C++ 11 std::aligned_alloc,但遗憾的是它不适用于Microsoft Visual Studio 2013.
我正在考虑,intsead,aligned_alloc我自己实施.实现应该如何?以下例如不编译,因为它无法转换void*为void*&.
template<typename T>
T* aligned_alloc( std::size_t size, std::size_t align )
{
T* ptr = new T[size + align];
std::align(align, size, reinterpret_cast<void*>(ptr), align + size);
return ptr;
}
Run Code Online (Sandbox Code Playgroud) c++ memory-alignment dynamic-memory-allocation visual-studio-2013