avx
编译选项:
CXXFLAGS += -mavx2
#include <immintrin.h>
#include <cmath> void reset_xy(int *x, int *y, int vector_size)
{
for (int i = 0; i < vector_size; i++) {
x[i] = 1;
y[i] = 1;
}
} template <typename F>
double runtime_test(int repeat_times, const F& f)
{
clock_t start = clock();
int counter = repeat_times;
while (counter--) {
f();
}
clock_t end = clock();
double time = (double)(end - start) / CLOCKS_PER_SEC;
return time;
} int avx_test()
{
constexpr int repeat_times = 100;
constexpr int vector_size = 1000 * 1000;
int x[vector_size] = {0};
int y[vector_size] = {0};
reset_xy(x, y, vector_size);
std::cout << "repeat_times = " << repeat_times << " vector_size = " << vector_size << std::endl; auto f_noavx = [&x, &y, vector_size]() {
for(int i = 0; i < vector_size; i++) {
x[i] += y[i];
}
};
double noavx_time = runtime_test(repeat_times, f_noavx);
std::cout << "x[0] = " << x[0] << " x[vector_size - 1] = " << x[vector_size - 1] << std::endl; auto f_avx = [&x, &y, vector_size]() {
for(int i = 0; i < vector_size; i += 8) { // step 8 is 8 * 32 = 256 bit
int *x0 = x + i;
int *y0 = y + i;
__m256i v1 = _mm256_loadu_si256((const __m256i*)x0);
__m256i v2 = _mm256_loadu_si256((const __m256i*)y0);
v1 = _mm256_add_epi32(v1, v2);
_mm256_storeu_si256 ((__m256i*)x0, v1);
}
};
reset_xy(x, y, vector_size);
double avx_time = runtime_test(repeat_times, f_avx);
std::cout << "x[0] = " << x[0] << " x[vector_size - 1] = " << x[vector_size - 1] << std::endl;
std::cout << "noavx_time = " << noavx_time << " avx_time = " << avx_time << std::endl;
std::cout << "noavx_time / avx_time = "<< noavx_time / avx_time << std::endl;
return 0;
}
avx的更多相关文章
- 使用CPU的AVX指令
arch:AVX 很抱歉GCC还不行……有……倒是 但是不是这么写的 我忘记了……官网上有 http://www.oschina.net/news/66980/kreogist-0-9
- 编译AVX代码,升级Redhat 5.5 GCC至4.7.1
Redhat 的GCC编译器4.1版本号,为SSE4,AVX,AVX2支持不够好,官方建议4.7以上. 就这样开始了GCC升级之路. 因为Redhat 5.5它安装在一个虚拟机.全然解决,经过若干尝试 ...
- 报错解决——Your CPU supports instructions that this TensorFlow binary was not compiled to use: AVX AVX2
在导入tensorflow后,进行运算时,出现了报错Your CPU supports instructions that this TensorFlow binary was not compile ...
- SIMD指令集——一条指令操作多个数,SSE,AVX都是,例如:乘累加,Shuffle等
SIMD指令集 from:https://zhuanlan.zhihu.com/p/31271788 SIMD,即Single Instruction, Multiple Data,一条指令操作多个数 ...
- not compiled to use: SSE4.1 SSE4.2 AVX AVX2 FMA
Your CPU supports instructions that this TensorFlow binary was not compiled to use: SSE4.1 SSE4.2 AV ...
- Tensorflow源码编译,解决tf提示未使用SSE4.1 SSE4.2 AVX警告【转】
本文转载自:https://blog.csdn.net/iTaacy/article/details/72799833 版权声明:欢迎转载,转载请注明出处! https://blog.csdn.net ...
- ubuntu16.04解决tensorflow提示未编译使用SSE3、SSE4.1、SSE4.2、AVX、AVX2、FMA的问题【转】
本文转载自:https://blog.csdn.net/Nicholas_Wong/article/details/70215127 rticle/details/70215127 在我的机器上出现的 ...
- DeepFaceLab: SSE,AVX, OpenCL 等版本说明!
Deep Fake Lab早期只有两个版本,一个是专门正对NVIDIA显卡的CUDA9的版本,另一个是支持CPU的版本. 三月初该项目作者对tenserFlow,Cuda的版本进行了升级,预编译的软件 ...
- intel AVX指令集
听说这 AVX 很牛,,支持Win7,大幅提高游戏浮点运算性能warning C4752: 发现 Intel(R) 高级矢量扩展:请考虑使用 /arch:AVX
- Dlib支持CPU指令集编译问题(SSE4.2或者AVX)
The compile script is: mkdir build cd build cmake ../../tools/python -DUSE_SSE2_INSTRUCTIONS=ON cmak ...
随机推荐
- Could not resolve dependency:peer swiper@“^5.2.0“ from vue-awesome-swiper@4.1.1
在安装vue-awesome-swiper时报错: Could not resolve dependency:peer swiper@"^5.2.0" from vue-aweso ...
- VeeValidate 注册实例
注册 1 安装: npm install vee-validate --save 2.mian.js 填写 import Vue from 'vue' import VeeValidate, {Val ...
- ProcessLassoLauncher.exe
html, body { font-size: 15px } body { font-family: Helvetica, "Hiragino Sans GB", 微软雅黑, &q ...
- HCIA-ICT实战基础08-访问控制列表ACL原理与配置
HCIA-ICT实战基础-访问控制列表ACL原理与配置 目录 ACL技术概述 ACL的基本概念及其工作原理 ACL的基础配置及应用 ACL技术概述 技术背景: 需要一个工具实现流量过滤 ACL是由一系 ...
- 使用signalr不使用连接服务器和前台的js的方法
1:使用这种方式,,就不需要前后台链接的js 2:新建一个empty的MVC项目 3:新建一个controller和index.html 4: 新建一个signalr 集线器类名为PersonHub, ...
- 根据指定月份,打印该月份所属的季节。 3,4,5 春季 6,7,8 夏季 9,10,11 秋季 12, 1, 2 冬季 if和switch各写一版
1.public class Month{ public static void main(String args[]){ for (int i = 1;i <= 12 ;i++ ) { if ...
- python学习笔记-简介
python简介 python是一种简单易学,功能强大的编程语言,他有高效的高层数据结构,简单而有效的实现面向对象编程.python是一种解释性语言,在多数平台的多个领域都是理想的脚本语言,特别适用于 ...
- 学习笔记||使用Vue时踩过的坑2.0
6.Vue指令之v-show篇 v-show的功能,其功能类似于v-if 1.判断某个元素是否显示或隐藏 <el-button v-show="list.power == 1" ...
- adaptsegnet 论文分析比较好的
https://blog.csdn.net/weixin_43795588/article/details/118058775 常用的语义分割一般是由两部分组成:一部分是特征提取器,比如可以用Resn ...
- Java字符串的一些函数方法
一.substring()方法 String str="123456"; String s1=str.substring(2); //s1="3456" Str ...