我有GeForce GTX460 SE,所以它是:6 SM x 48 CUDA核心= 288 CUDA核心.众所周知,在一个Warp中包含32个线程,并且在一个块中同时(一次)只能执行一个Warp.也就是说,在单个多处理器(SM)中,即使有48个可用核心,也可以同时只执行一个Block,一个Warp和32个线程?
此外,可以使用threadIdx.x和blockIdx.x来分发具体的Thread和Block的示例.要分配它们,请使用内核<<< Blocks,Threads >>>().但是如何分配特定数量的Warp-s并分发它们,如果不可能那么为什么还要去了解Warps呢?
当我在Windows7x64(MSVS2012 + Nsight 2.0 + CUDA5.5)中编译包含设计C++ 11的以下代码时,我没有得到错误,并且所有内容都编译并运行良好:
#include <thrust/device_vector.h>
int main() {
thrust::device_vector<int> dv(10);
auto iter = dv.begin();
return 0;
}
Run Code Online (Sandbox Code Playgroud)
但是当我尝试在Linux64(Debian 7 Wheezey + Nsight Eclipse,来自CUDA5.5)下编译它时,我得到错误:
../src/CudaCpp11.cu(5):错误:缺少显式类型(假设为"int")
../src/CudaCpp11.cu(5):错误:没有合适的转换函数
"thrust :: detail :: normal_iterator>"到"int"存在
在编译"/tmp/tmpxft_00001520_00000000-6_CudaCpp11.cpp1.ii"中检测到2个错误.make:* [src/CudaCpp11.o]错误2
当我添加行:-stdc ++ 11
在Properties-> Build-> Settings-> Tool Settings-> Build Stages-> Preprocessor options(-Xcompiler)中
我收到更多错误:
/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h(432):错误:标识符"nullptr"未定义
/usr/lib/gcc/x86_64-linux-gnu/4.8/include/stddef.h(432):错误:预期";"
...
/usr/include/c++/4.8/bits/cpp_type_traits.h(314):错误:命名空间"std :: __ gnu_cxx"没有成员
"__normal_iterator"
/usr/include/c++/4.8/bits/cpp_type_traits.h(314):错误:预期">"
nvcc错误:'cudafe'因信号11(无效内存引用)而死亡:* [src/CudaCpp11.o]错误11
只有当我thrust::device_vector<int>::iterator iter = dv.begin();在Linux-GCC中使用时,我才会收到错误.但在Windows MSVS2012中,所有c ++ 11功能都可以正常工作!
我可以在Windows7x64(MSVC)和Linux64(GCC4.8.2)的.cu文件(CUDA5.5)中使用C++ 11吗?
使用Fast/Faster-RCNN和Caffe在C++上制作对象检测器的最简单方法是什么?
众所周知,我们可以使用跟随RCNN(基于区域的卷积神经网络)和Caffe:
RCNN:https://github.com/BVLC/caffe/blob/be163be0ea5befada208dbf0db29e6fa5811dc86/python/caffe/detector.py#L174
快速RCNN:https://github.com/rbgirshick/fast-rcnn/blob/master/tools/demo.py#L89
scores, boxes = im_detect(net, im, obj_proposals) 哪个叫 def im_detect(net, im, boxes):
使用rbgirshick/caffe-fast-rcnn,ROIPooling-layers和输出bbox_pred
scores, boxes = im_detect(net, im) 哪个叫 def im_detect(net, im, boxes=None):
使用rbgirshick/caffe-fast-rcnn,ROIPooling-layers和输出bbox_pred
所有这些都使用Python和Caffe,但是如何在C++和Caffe上做到这一点?
分类只有C++示例(在图像上说什么),但是没有用于检测(表示图像上的内容和位置):https://github.com/BVLC/caffe/tree/master/examples/cpp_classification
用rbgirshick/caffe-fast-rcnn简单地克隆rbgirshick/py-faster-rcnn存储库
就足够了,下载预先设定的模型,使用这个coco/VGG16/faster_rcnn_end2end/test.prototxt并在CaffeNet C++分类中做了一些小改动例子?./data/scripts/fetch_faster_rcnn_models.sh
如何从两层bbox_pred和cls_score获取输出数据?
我是否将所有(bbox_pred和cls_score)放在一个数组中:
const vector<Blob<float>*>& output_blobs = net_->ForwardPrefilled();
Blob<float>* output_layer = output_blobs[0]; …Run Code Online (Sandbox Code Playgroud) 以下是在x86/x86_64中实现顺序一致性的四种方法:
正如它在这里写的:http://www.cl.cam.ac.uk/~pes20/cpp/cpp0xmappings.html
C/C++ 11操作x86实现
- 加载Seq_Cst:MOV(来自内存)
- Store Seq Cst:(LOCK)XCHG //替代方案:MOV(进入内存),MFENCE
注意:有一个C/C++ 11到x86的替代映射,而不是锁定(或屏蔽)Seq Cst存储锁/隔离Seq Cst加载:
- 加载Seq_Cst:LOCK XADD(0)//替代:MFENCE,MOV(来自内存)
- Store Seq Cst:MOV(进入内存)
GCC 4.8.2(x86_64中的GDB)对C++ 11-std :: memory_order_seq_cst使用第一种方法,即LOAD(没有fence)和STORE + MFENCE:
std::atomic<int> a;
int temp = 0;
a.store(temp, std::memory_order_seq_cst);
0x4613e8 <+0x0058> mov 0x38(%rsp),%eax
0x4613ec <+0x005c> mov %eax,0x20(%rsp)
0x4613f0 <+0x0060> mfence
Run Code Online (Sandbox Code Playgroud)
我们知道,MFENCE = LFENCE + SFENCE.然后这段代码我们可以重写为:LOAD(without fence) and STORE+LFENCE+SFENCE
问题:
标准C++ 11是否保证memory_order_seq_cst阻止StoreLoad重新排序原子操作以进行非原子内存访问?
众所周知,std::memory_orderC++ 11中有6 个,它指定了如何围绕原子操作对常规的非原子内存访问进行排序 - 工作草案,编程语言C++标准2016-07-12:http:/ /www.open-std.org/jtc1/sc22/wg21/docs/papers/2016/n4606.pdf
§29.3顺序和一致性
§29.3/ 1
枚举memory_order指定1.10中定义的详细常规(非原子)内存同步顺序,并且可以提供操作排序.其枚举值及其含义如下:
众所周知,这6个memory_orders会阻止其中一些重新排序:
但是,是否会memory_order_seq_cst阻止StoreLoad围绕原子操作重新排序以进行常规的非原子内存访问,或仅针对其他具有相同原子的原子进行重新排序memory_order_seq_cst?
即,如果我们同时使用std::memory_order_seq_cstSTORE和LOAD,或仅用于其中一个,则阻止此StoreLoad重新排序?
std::atomic<int> a, b;
b.store(1, std::memory_order_seq_cst); // Sequential Consistency
a.load(std::memory_order_seq_cst); // Sequential Consistency
Run Code Online (Sandbox Code Playgroud)
关于Acquire-Release语义是明确的,它完全指定了跨原子操作的非原子内存访问重新排序:http://en.cppreference.com/w/cpp/atomic/memory_order
为防止StoreLoad重新排序,我们应该使用std::memory_order_seq_cst.
两个例子:
std::memory_order_seq_cst对于STORE和LOAD:有MFENCE StoreLoad无法重新排序 - GCC 6.1.0 x86_64:https://godbolt.org/g/mVZJs0
std::atomic<int> a, b;
b.store(1, std::memory_order_seq_cst); // can't be executed after LOAD
a.load(std::memory_order_seq_cst); // …Run Code Online (Sandbox Code Playgroud) 我可以使用std::initializer_list对象而不是大括号括起初始化器来初始化数组吗?
众所周知,我们可以这样做:http://en.cppreference.com/w/cpp/language/aggregate_initialization
unsigned char b[5]{"abc"};
// equivalent to unsigned char b[5] = {'a', 'b', 'c', '\0', '\0'};
int ar[] = {1,2,3};
std::array<int, 3> std_ar2{ {1,2,3} }; // std::array is an aggregate
std::array<int, 3> std_ar1 = {1, 2, 3};
Run Code Online (Sandbox Code Playgroud)
但我不能通过以下方式初始化数组std::initializer_list il;:
#include <iostream>
#include <initializer_list>
#include <array>
int main() {
int arr1[] = { 1, 2, 3 }; // OK
std::array<int, 3> arr2 = { 1, 2, 3 }; // OK
std::initializer_list<int> il …Run Code Online (Sandbox Code Playgroud) Can Boost ASIO可用于构建低延迟应用,例如HFT(高频交易)吗?
因此Boost.ASIO使用特定于平台的最佳解复用机制:IOCP,epoll,kqueue,poll_set,/ dev/poll
也可以使用带TOE(TCP/IP卸载引擎)的Ethernet-Adapter和OpenOnload(内核旁路BSD套接字).
但是可以使用Boost.ASIO + TOE + OpenOnload构建低延迟应用程序吗?
众所周知,SO_REUSEPORT允许多个套接字侦听相同的IP地址和端口组合,它将每秒请求增加2到3倍,并减少延迟(~30%)和延迟标准差(8次):https ://www.nginx.com/blog/socket-sharding-nginx-release-1-9-1/
NGINX版本1.9.1引入了一项新功能,该功能支持使用 SO_REUSEPORT套接字选项,该选项适用于许多操作系统的较新版本,包括DragonFly BSD和Linux(内核版本3.9及更高版本).此套接字选项允许多个套接字侦听相同的IP地址和端口组合.然后内核负载平衡套接字上的传入连接....
如图所示,reuseport将每秒请求数增加了2到3倍,并减少了延迟和延迟的标准偏差.
SO_REUSEPORT适用于大多数现代操作系统:Linux(自2013年4月29日起内核> = 3.9),Free/Open/NetBSD,MacOS,iOS/watchOS/tvOS,IBM AIX 7.2,Oracle Solaris 11.1,Windows(仅表现为2个标志)在BSD上一起+ ,可能在Android上:https: //stackoverflow.com/a/14388707/1558037SO_REUSEPORTSO_REUSEPORTSO_REUSEADDR
Linux> = 3.9
- 此外,内核为
SO_REUSEPORT其他操作系统中找不到的套接字执行一些"特殊魔法" :对于UDP套接字,它尝试均匀分布数据报,对于TCP侦听套接字,它会尝试分发传入的连接请求 (通过调用接受的请求accept())均匀地跨越共享相同地址和端口组合的所有套接字.因此,应用程序可以轻松地在多个子进程中打开相同的端口,然后使用它SO_REUSEPORT来获得非常便宜的负载平衡.
同样众所周知,为了避免自旋锁定和高性能锁定,不应该有超过1个线程的套接字.即每个线程都应该处理自己的套接字以进行读/写.
accept()对于相同的套接字描述符是线程安全的函数,因此它应该被锁定 - 因此锁争用会降低性能:http://unix.derkeiler.com/Newsgroups/comp.unix.programmer/2007-06/msg00246.htmlPOSIX.1-2001/SUSv3 需要accept(),bind(),connect(),listen(),socket(),send(),recv()等作为线程安全函数.标准中可能存在关于它们与线程交互的一些含糊之处,但其意图是它们在多线程程序中的行为受标准控制.
我用4台固定式摄像机.相机不会相对移动.我想将他们的视频图像实时拼接成一个视频图像.
我用这个OpenCV 2.4.10和cv:stitcher类,像这样:
// use 4 video-cameras
cv::VideoCapture cap0(0), cap1(1), cap2(2), cap3(3);
bool try_use_gpu = true; // use GPU
cv::Stitcher stitcher = cv::Stitcher::createDefault(try_use_gpu);
stitcher.setWarper(new cv::CylindricalWarperGpu());
stitcher.setWaveCorrection(false);
stitcher.setSeamEstimationResol(0.001);
stitcher.setPanoConfidenceThresh(0.1);
//stitcher.setSeamFinder(new cv::detail::GraphCutSeamFinder(cv::detail::GraphCutSeamFinderBase::COST_COLOR_GRAD));
stitcher.setSeamFinder(new cv::detail::NoSeamFinder());
stitcher.setBlender(cv::detail::Blender::createDefault(cv::detail::Blender::NO, true));
//stitcher.setExposureCompensator(cv::detail::ExposureCompensator::createDefault(cv::detail::ExposureCompensator::NO));
stitcher.setExposureCompensator(new cv::detail::NoExposureCompensator());
std::vector<cv::Mat> images(4);
cap0 >> images[0];
cap1 >> images[1];
cap2 >> images[2];
cap3 >> images[3];
// call once!
cv::Stitcher::Status status = stitcher.estimateTransform(images);
while(true) {
// **lack of speed, even if I use old frames**
// std::vector<cv::Mat> images(4);
//cap0 …Run Code Online (Sandbox Code Playgroud) 我可以在CUDA处理器Tegra 1/2上开发应用程序,我需要什么以及Tegra 1/2 CUDA功能?我发现只有NVIDIA Debug Manager可以在Eclipse for Eclipse中进行开发,但我不知道他是否可以开发CUDA风格.