我先说我是 SIMD 内在函数的完全初学者。
本质上,我有一个支持 AVX2 内在 ( Intel(R) Core(TM) i5-7500T CPU @ 2.70GHz)的 CPU 。我想知道计算两个std::vector<float>size的点积的最快方法512。
我在网上做了一些挖掘,发现了这个和这个,这个堆栈溢出问题建议使用以下函数__m256 _mm256_dp_ps(__m256 m1, __m256 m2, const int mask);,但是,这些都表明了执行点积的不同方法我不确定什么是正确的(和最快的)方法它。
特别是,我正在寻找对大小为 512 的向量执行点积的最快方法(因为我知道向量大小会影响实现)。
感谢您的帮助
编辑 1:我也对-mavx2gcc 标志有点困惑。如果我使用这些 AVX2 函数,我编译时是否需要添加标志?另外,-OFast如果我编写了一个天真的点积实现,gcc 是否能够为我做这些优化(比如我使用gcc 标志)?
编辑 2 如果有人有时间和精力,如果您能编写完整的实现,我将不胜感激。我相信其他初学者也会重视这些信息。
我在我正在开发的应用程序中使用react-native-camera组件(https://github.com/lwansbrough/react-native-camera).
有没有办法从视频/摄像机馈送中获取单个帧,以便我可以实时执行处理.
我的最终目标是使用tracking.js库实时跟踪对象,以实现AR效果.
谢谢您的帮助!
react-native react-native-camera react-native-android tracking.js
我想知道如何在 C++ 中有效地标准化向量。到目前为止,这就是我所拥有的。有没有办法提高效率和/或一次性完成。
std::array<float, MyClass::FEATURE_LENGTH> MyClass::normalize(const std::array<float, FEATURE_LENGTH>& arr) {
std::array<float, MyClass::FEATURE_LENGTH> output{};
double mod = 0.0;
for (size_t i = 0; i < arr.size(); ++i) {
mod += arr[i] * arr[i];
}
double mag = std::sqrt(mod);
if (mag == 0) {
throw std::logic_error("The input vector is a zero vector");
}
for (size_t i = 0; i < arr.size(); ++i) {
output[i] = arr[i] / mag;
}
return output;
}
Run Code Online (Sandbox Code Playgroud) 我有一个项目(此处的代码),我在其中运行基准测试来比较计算点积的不同方法(朴素方法、特征库、SIMD 实现等)的性能。我正在新的 Centos 7.6 VM 上进行测试。我注意到当我使用不同版本的 时libstdc++.so.6,我得到的性能明显不同。
当我启动一个新的 Centos 7.6 实例时,默认的 C++ 标准库是libstdc++.so.6.0.19. 当我运行我的基准测试可执行文件(链接到这个版本的libstdc++)时,输出如下:
Naive Implementation, 1000000 iterations: 1448.74 ns average time
Optimized Implementation, 1000000 iterations: 1094.2 ns average time
AVX2 implementation, 1000000 iterations: 1069.57 ns average time
Eigen Implementation, 1000000 iterations: 1027.21 ns average time
AVX & FMA implementation 1, 1000000 iterations: 1028.68 ns average time
AVX & FMA implementation 2, 1000000 iterations: 1021.26 ns average time
Run Code Online (Sandbox Code Playgroud)
如果我下载libstdc++.so.6.0.26并更改符号链接libstdc++.so.6 …
我在类 Unix 系统上使用 CMake 3.15-rc3。
\n我需要将我正在构建的程序与多个 CUDA 库链接,包括cublas, cufft, cusolver, curand, nppicc, nppial, nppist, nppidei, nppig, nppitc, npps。
根据我在网上找到的信息,我需要做这样的事情:
\nadd_executable(test benchmark.cpp)\nfind_package(CUDALibs)\ntarget_link_libraries(test CUDA::cudart CUDA::cublas CUDA::cufft CUDA::cusolver CUDA::curand CUDA::nppicc CUDA::nppial CUDA::nppist CUDA::nppidei CUDA::nppig CUDA::nppitc CUDA::npps)\nRun Code Online (Sandbox Code Playgroud)\n当我运行时,make出现以下错误:
CMake Warning at CMakeLists.txt:27 (find_package):\n By not providing "FindCUDALibs.cmake" in CMAKE_MODULE_PATH this project has\n asked CMake to find a package configuration file provided by "CUDALibs",\n but CMake …Run Code Online (Sandbox Code Playgroud) 我的目标是使用 GStreamer 后端使用 OpenCV Python 创建一个 RTSP 服务器。我将 RGB 图像存储为 OpenCV Mat,并且我想创建一个VideoWriter可以写入 RTSP 接收器的图像。输出视频必须采用 x264 编码。
我相信使用 GStreamer 管道并向VideoWriter构造函数提供管道参数,然后将帧推送到 VideoWriter 可以轻松实现这一点,但问题是我没有使用 GStreamer 的经验,我发现它非常令人困惑。
我在 SO 上找到的答案不完整,使用特定的硬件解码器(例如 NVIDIA Jetson),或者过于复杂。我想找到一个适用于 CPU 的更通用的解决方案。
希望从 ARM 源代码交叉编译 postgresql 获得一些帮助。我正在尝试在X86_64 Ubuntu 18.04.4. 我正在使用传递 autoconf 以下参数:
CC=arm-linux-gnueabihf-gcc CXX=arm-linux-gnueabihf-g++ AR=arm-linux-gnueabihf-ar RANLIB=arm-linux-gnueabihf-ranlib ../configure --host=arm-linux-gnueabihf --without-readline --without-zlib
Run Code Online (Sandbox Code Playgroud)
当我使用 postgresql release 使用上述参数运行 configure 时9.6.2,它会成功,并且我能够正确构建库。但是,我想使用最新版本,目前是 V 12.2。
当我使用 V 运行上述命令时12.2,收到以下错误消息:
// a bunch of successfull output from autoconf before error message...
checking for /dev/urandom... configure: error: cannot check for file existence when cross compiling
Run Code Online (Sandbox Code Playgroud)
任何想法如何解决这一问题?这是他们的 autoconf 中的错误,还是我这边做错了什么?
我正在使用一个函数(它是库的一部分),它返回一个uint8_t*指向已在堆上分配并保存图像像素数据的内存的原始指针。这个函数的调用者负责调用free指针。
我调用此函数的代码有许多提前终止的分支,因此我需要free(buffer)在许多点调用。我认为最好将缓冲区包装在 a 中,unique_ptr以便当它超出范围时,内存会自动释放。
我怎样才能做到这一点?
作为参考,函数 decleration 看起来像这样:(uint8_t* getFrame()我已经知道图像的宽度、高度和 num 通道以及缓冲区的长度);
c++ ×5
autoconf ×1
avx2 ×1
cmake ×1
cuda ×1
dot-product ×1
fma ×1
gcc ×1
gstreamer ×1
heap-memory ×1
libstdc++ ×1
linux ×1
opencv ×1
optimization ×1
performance ×1
postgresql ×1
python ×1
raw-pointer ×1
react-native ×1
rtsp ×1
simd ×1
tracking.js ×1
unique-ptr ×1