编译选项:

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的更多相关文章

  1. 使用CPU的AVX指令

    arch:AVX 很抱歉GCC还不行……有……倒是 但是不是这么写的 我忘记了……官网上有 http://www.oschina.net/news/66980/kreogist-0-9

  2. 编译AVX代码,升级Redhat 5.5 GCC至4.7.1

    Redhat 的GCC编译器4.1版本号,为SSE4,AVX,AVX2支持不够好,官方建议4.7以上. 就这样开始了GCC升级之路. 因为Redhat 5.5它安装在一个虚拟机.全然解决,经过若干尝试 ...

  3. 报错解决——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 ...

  4. SIMD指令集——一条指令操作多个数,SSE,AVX都是,例如:乘累加,Shuffle等

    SIMD指令集 from:https://zhuanlan.zhihu.com/p/31271788 SIMD,即Single Instruction, Multiple Data,一条指令操作多个数 ...

  5. 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 ...

  6. Tensorflow源码编译,解决tf提示未使用SSE4.1 SSE4.2 AVX警告【转】

    本文转载自:https://blog.csdn.net/iTaacy/article/details/72799833 版权声明:欢迎转载,转载请注明出处! https://blog.csdn.net ...

  7. ubuntu16.04解决tensorflow提示未编译使用SSE3、SSE4.1、SSE4.2、AVX、AVX2、FMA的问题【转】

    本文转载自:https://blog.csdn.net/Nicholas_Wong/article/details/70215127 rticle/details/70215127 在我的机器上出现的 ...

  8. DeepFaceLab: SSE,AVX, OpenCL 等版本说明!

    Deep Fake Lab早期只有两个版本,一个是专门正对NVIDIA显卡的CUDA9的版本,另一个是支持CPU的版本. 三月初该项目作者对tenserFlow,Cuda的版本进行了升级,预编译的软件 ...

  9. intel AVX指令集

    听说这 AVX 很牛,,支持Win7,大幅提高游戏浮点运算性能warning C4752: 发现 Intel(R) 高级矢量扩展:请考虑使用 /arch:AVX

  10. Dlib支持CPU指令集编译问题(SSE4.2或者AVX)

    The compile script is: mkdir build cd build cmake ../../tools/python -DUSE_SSE2_INSTRUCTIONS=ON cmak ...

随机推荐

  1. H5在(支付宝和微信环境)使用支付

    首先是在支付宝浏览器环境   使用支付宝支付 参考链接 https://myjsapi.alipay.com/jsapi/native/trade-pay.html 支付宝订单字符串唤起支付  调用支 ...

  2. python pip 换源

    title: pip 换源 author: 杨晓东 permalink: pip-换源 date: 2021-10-02 11:27:04 categories: - 投篮 tags: - demo ...

  3. tomcat 3 - 默认连接器

    Tomcat 中使用的容器连接器必须满足以下要求: 实现 org.apache.catalina.Connector 接口 负责创建实现了 org.apache.catalina.Request 接口 ...

  4. C++实现有序表--顺序表的合并操作代码

    #include<iostream>#include<cstdlib>//C++动态分配存储空间using namespace std;#define OK 1#define ...

  5. laravel 表单提交 图片的异步上传

    这里使用的是WebUploader   百度提供的插件 首先下载最新的包 下载第一个,解压,把解压好的文件放入public目录下 视图层中 <div class="formContro ...

  6. laravel 软删除的使用

    1.模型层 引用类use Illuminate\Database\Eloquent\SoftDeletes;class类中引用软删除use SoftDeletes;然后执行正常的删除,列表已经不显示, ...

  7. windows 设置修改本地 hosts 访问 github 快速访问 提高访问 github 速度

    获取IP地址 查询 以下域名IP地址 github.com github.global.ssl.fastly.net assets-cdn.github.com 通过在线网址查询:https://we ...

  8. 记事本默认编码改为UTF-8

    前端时间发现用记事本直接创建的记录目标信息的TXT文本再用sublime打开变成了乱码,才发现编码有问题,记事本直接创建的文本编码竟然是ANSI编码. 于是动手将记事本默认编码改为UTF-8. 记事本 ...

  9. python+selenium实现自动识别验证码并登录

    最近学习python+selenium实现网站的自动登录,但是遇到需要输入验证码的问题,经过查询百度收获了几种破解验证码的方式. 方式一)从万能的网友那收获了一个小众但非常实用的第3方库ddddocr ...

  10. vs2013如何添加扩展库函数

    本文仅针对C和C++ vs2013下载C/C++编译器后,能够包含常见的头文件,stdlib.h,stdio.h,math.h这些.如果有其他需求例如:调用GL/glfw32.h,freeglut.h ...