当前位置: 首页 > news >正文

oneMKL--FFT 基本使用

oneMKL–FFT 基本使用

本人基于官方文档的摘录与理解

oneMKL--FFT基本使用

  • oneMKL--FFT 基本使用
    • 1. Both FFT and Cluster FFT functions compute an FFT in five steps
    • 2 Computing an FFT
      • 2.1 缺省值
      • 2.2 Fourier Transform Funcions Code Examples
        • 2.2.1 One_dimentional In-place FFT(一维的原地的FFT,原地指输出覆盖原始数据)
        • 2.2.2 One_dimentional Out-of-place FFT(一维的异地的FFT,异地指输出在准备好的地方) and Changing default setting
        • 2.2.3 Two-dimentional FFT
        • 2.2.4 Changing Default Settings
    • 3 Using Status Checking Functions
    • 4 Computing 2D FFT by One-Dimensional Transforms
    • 5 Examples of Using OpenMP* Threading for FFT Computation
    • 6 oneMKL 中 FFT 的所有函数
    • 7 参数解释
      • Configuration settings

1. Both FFT and Cluster FFT functions compute an FFT in five steps

  1. 为计算分配一个全新的描述器,通过调用DftiCreateDescriptor or DftiCreateDescriptorDM

    • 这个描述器定义了快速傅里叶变换中的参数,比如 维度(dimensionality)、大小(sizes)、转换次数(number of transforms)、输入输出数据的存储布局(指layout,行优先还是列优先)、比例因子(scaling factors)。这些配置参数很多都分配了默认值,有需要的话要再程序中修改。
  2. 需要时,选择性的调整描述器的配置,通过调用DftiSetValue or DftiSetValueDM

    • 通常,你必须仔细定义用于FFT的数据存储布局(指layout)或 用于Cluster FFT过程中的数据分布。描述器的配置参数,比如默认值,可以通过DftiGetValue or DftiGetValueDM 函数来获得
  3. 提交描述器,通过调用DfticommitDescriptor or DftiCommitDescriptorDM

    • 这使描述器ready for transform computation。
    • 一旦提交了描述器,变换(transform)的参数就会被冻结于描述器中,比如变换的类型和数值(type and number of transforms)、步幅(strides)和距离(distances)、数据的类型和存储布局(layout)等等。
  4. 开始计算变换,通过调用DfticomputeForward/DftiComputeBackward or DftiComputeForwardDM/DftiComputeBackwardDM,根据需要来设置运算次数

    • 因为描述器是分开定义和提交的,计算函数做的所有工作就是接受输入和输出并且按照定义来计算变换。
    • 想要修改另一个计算函数的调用的任何配置参数,就使用DftiSetValue后面跟着DftiCommitDescriptorDftiSetValueDM后面就跟着DftiCommitDescriptorDM)来修改,或者 创建并提交另一个描述器。
  5. 释放描述器,通过调用DftiFreeDescriptor or DftiFreeDescriptorDM

    • 描述器内部消耗的内存将被释放掉

上述所有方法都会返回一个整形的状态值(status value),该值在操作成功完成时为0。
你可以通过DftiErrorClass or DftiErrorMessage 来了解非0状态的意义。

2 Computing an FFT

2.1 缺省值

描述器的数据结构在创建时就包含了FFT的长度和域(domain,复数或实数)的信息,也包含了一些配置参数。这些参数的一些缺省值如下:

  • Scale factor :none (that is, σ=1)
  • Number of data sets:one (数据集数量)
  • Data storage: contiguous(连续的)
  • Placement of results: in-place(the computed result overwrites the input data,计算出来的结果覆盖输入数据)

这些默认设置想要改变可以通过 DftiSetValue

2.2 Fourier Transform Funcions Code Examples

2.2.1 One_dimentional In-place FFT(一维的原地的FFT,原地指输出覆盖原始数据)
complex<float> c2c_data[32];
//float _Complex c2c_data[32]; //c风格写法,vs识别有问题
float r2c_data[34];
DFTI_DESCRIPTOR_HANDLE my_desc1_handle = NULL;
DFTI_DESCRIPTOR_HANDLE my_desc2_handle = NULL;
MKL_LONG status;
for (int i = 0; i <= 31; i++) c2c_data[i] = i;
for (int i = 0; i <= 31; i++) r2c_data[i] = i;//complex operation
status = DftiCreateDescriptor(&my_desc1_handle, DFTI_SINGLE, DFTI_COMPLEX, 1, 32);
status = DftiCommitDescriptor(my_desc1_handle);
status = DftiComputeForward(my_desc1_handle, c2c_data);
status = DftiFreeDescriptor(&my_desc1_handle);//reall operation
status = DftiCreateDescriptor(&my_desc2_handle, DFTI_SINGLE, DFTI_REAL, 1, 32);
status = DftiCommitDescriptor(my_desc2_handle);
status = DftiComputeForward(my_desc2_handle, r2c_data);cout << "c2c:" << endl;
for (int i = 0; i < 32; i++) {cout << c2c_data[i] << " ";
}
cout << endl << endl;cout << "r2c:" << endl;
for (int i = 0; i < 34; i++) {cout << r2c_data[i] << " ";
}
cout << endl;}

输出:
one-diemsional in-place FFT output
总结: example中一个数据类型是复数类型complex,一个数据类型是float。输出结果的不同应该是受fft算法的影响,不是很懂。

2.2.2 One_dimentional Out-of-place FFT(一维的异地的FFT,异地指输出在准备好的地方) and Changing default setting
#include <iostream>
#include <mkl_dfti.h>
#include <stdio.h>
#include <complex>
using namespace std;void main() {complex<float> c2c_input[32];complex<float> c2c_output[32];float r2c_input[32];float r2c_output[32];DFTI_DESCRIPTOR_HANDLE my_desc1_handle = NULL;DFTI_DESCRIPTOR_HANDLE my_desc2_handle = NULL;MKL_LONG status;//store the number of command execution status. MKL_LONG is long int.//assign values to arraysfor (int i = 0; i <= 31; i++) c2c_input[i] = i;for (int i = 0; i <= 31; i++) r2c_input[i] = i;// real operation/*create a descriptorsynax:status = DftiCreateDescriptor(&desc_handle, precision, forward_domain, dimension,length);the first parameter &desc_handle is the operation handle of a descriptorthe second parameter DFTI_PRECSION is the precision of FFT operation. DFTI_PRECESION has two enumeration types:DFTI_SINGLE、DFTI_DOUBLE the third parameter DFTI_FORWARD_DOMAIN is the domain of FFT operation. It means the type of fft.DFTI_FORWARD_DOMAIN has two enumeration types:DFTI_COMPLEX、DFTI_REALthe fourth parameter dimention is the dimension of FFT operationthe fifth parameter length is the length of the transform for a one-dimensional transform.the lengths of each dimension for a multi-dimensional transform.*/status = DftiCreateDescriptor(&my_desc1_handle,DFTI_SINGLE, DFTI_COMPLEX, 1, 32);//create a descriptor/*FFT Descriptor Configuration FunctionSyntax: status = DftiSetValue(desc_handle, config_param, config_val);The desc_handle's type is DFTI_DESCRIPTOR_HANDLE. The previous commande had initialized the DFTI_DESCRIPTOR_HANDLE.The DFTI_PlACEMENT is the config_param.The function only can set one particular parameter with a specified configuration value.*/status = DftiSetValue(my_desc1_handle, DFTI_PLACEMENT, DFTI_NOT_INPLACE);status = DftiCommitDescriptor(my_desc1_handle);/*Syntax:status = DftiComputeForward(desc_handle, x_inout);status = DftiComputeForward(desc_handle, x_in, y_out);status = DftiComputeForward(desc_handle, xre_inout, xim_inout);status = DftiComputeForward(desc_handle, xre_in, xim_in, yre_out, yim_out);x_inout,x_in: array of type float or double depending on the precision of the transformData to be transformed in case of a real forward domain or, in the case of a complex forwarddomain in association with FTI_COMPLEX_COMPLEX, set for DFTI_COMPLEX_STORAGE.xre_inout,xim_inout,xre_in, xim_in:Real and imaginary parts of the data tobe transformed in the case of acomplex forward domain.*/status = DftiComputeForward(my_desc1_handle, c2c_input, c2c_output);status = DftiFreeDescriptor(&my_desc1_handle);//complex operationstatus = DftiCreateDescriptor(&my_desc2_handle, DFTI_SINGLE, DFTI_REAL, 1, 32);status = DftiSetValue(my_desc2_handle,DFTI_PLACEMENT,DFTI_NOT_INPLACE);status = DftiCommitDescriptor(my_desc2_handle);status = DftiComputeForward(my_desc2_handle, r2c_input, r2c_output);status = DftiFreeDescriptor(&my_desc2_handle);cout << "c2c:" << endl;for (int i = 0; i < 32; i++) {cout << c2c_output[i] << " ";}cout << endl << endl;cout << "r2c:" << endl;for (int i = 0; i < 32; i++) {cout << r2c_output[i] << " ";}//cout << endl;
}

输出:
One-diemntional  Out-of-place FFT

2.2.3 Two-dimentional FFT
#include "mkl_dfti.h"
#include <stdio.h>
#include <iostream>
#include <complex>
using namespace std;void main() {complex<float> c2c_data[32][100];float r2c_data[34][102];DFTI_DESCRIPTOR_HANDLE my_desc1_handle = NULL;DFTI_DESCRIPTOR_HANDLE my_desc2_handle = NULL;MKL_LONG status;MKL_LONG dim_sizes[2] = { 32,100 };for (int i = 0; i < 32; i++) {for (int j = 0; j < 100; j++) {c2c_data[i][j] = i * 100 + j;}}for (int i = 0; i < 34; i++) {for (int j = 0; j < 102; j++) {r2c_data[i][j] = i * 100 + j;}}status = DftiCreateDescriptor(&my_desc1_handle, DFTI_SINGLE, DFTI_COMPLEX, 2, dim_sizes);status = DftiCommitDescriptor(my_desc1_handle);status = DftiComputeForward(my_desc1_handle, c2c_data);status = DftiFreeDescriptor(&my_desc1_handle);status = DftiCreateDescriptor(&my_desc2_handle, DFTI_SINGLE, DFTI_REAL, 2, dim_sizes);status = DftiCommitDescriptor(my_desc2_handle);status = DftiComputeForward(my_desc2_handle, r2c_data);status = DftiFreeDescriptor(&my_desc2_handle);for (int i = 0; i < 32; i++) {for (int j = 0; j < 100; j++) {cout << r2c_data[i][j] << " ";}cout << endl;}for (int i = 0; i < 32; i++) {for (int j = 0; j < 100; j++) {cout << c2c_data[i][j] << " ";}cout << endl;}
}
2.2.4 Changing Default Settings
/* C99 example */
#include "mkl_dfti.h"
float _Complex x_in[32], x_out[32];
DFTI_DESCRIPTOR_HANDLE my_desc_handle = NULL;
MKL_LONG status;
/* ...put values into x_in[i] 0<=i<=31 */
status = DftiCreateDescriptor(&my_desc_handle, DFTI_SINGLE,DFTI_COMPLEX, 1, 32);
status = DftiSetValue(my_desc_handle, DFTI_PLACEMENT, DFTI_NOT_INPLACE);
status = DftiCommitDescriptor(my_desc_handle);
status = DftiComputeForward(my_desc_handle, x_in, x_out);
status = DftiFreeDescriptor(&my_desc_handle);
/* result is the complex value x_out[i], 0<=i<=31 */

3 Using Status Checking Functions

This example illustrates the use of status checking functions described in “Fourier Transform Functions”

#include "mkl_dfti.h"
#include <complex>
//#include <stdio.h>
#include <iostream>
using namespace std;void main() {complex<float> c2c_data[32];DFTI_DESCRIPTOR_HANDLE desc = NULL;MKL_LONG status;//status = DftiCreateDescriptor(&desc, DFTI_SINGLE, DFTI_COMPLEX, 1, 32);status = DftiCommitDescriptor(desc);/*predicate = DftiErrorClass(status, error_class);error_class: predefined error class which type is MKL_LONGpredicate : result of checking which type is MKL_LONG*/if (status && !DftiErrorClass(status, DFTI_NO_ERROR)) {cout << "Error: " << DftiErrorMessage(status) << endl;}
}

在这里插入图片描述
在这里插入图片描述

4 Computing 2D FFT by One-Dimensional Transforms

5 Examples of Using OpenMP* Threading for FFT Computation

6 oneMKL 中 FFT 的所有函数

FFT函数的头文件是mkl_dfti.h

Function Name1

Function Name2

7 参数解释

Configuration settings

在MKL_DFTI模型中,每一个配置参数都由一个命名了的常量(named constant)所确定。这些常量都有一个枚举类型(enumeration type)DFTI_CONFIG_PARAM 并且被定义在mkl_dfti.h头文件中。

Configuration Parameters1

Configuration Parameters2
Configuration Parameters3

Configuration Parameters4

相关文章:

oneMKL--FFT 基本使用

oneMKL–FFT 基本使用 本人基于官方文档的摘录与理解 oneMKL--FFT基本使用 oneMKL--FFT 基本使用1. Both FFT and Cluster FFT functions compute an FFT in five steps2 Computing an FFT2.1 缺省值2.2 Fourier Transform Funcions Code Examples2.2.1 One_dimentional In-p…...

软件测试工程师面试汇总Linux篇

Linux 命令篇 cd&#xff1a;切换目录 cd / #进入到系统根目录 cd . #进入到当前目录 cd .. #返回上层目录 cd /tmp #进入指定目录/tmp cd ~ #进入当前用户的家目录 2ls&#xff1a;列出当前目录的所有文件、文件夹&#xff08;目录&#xff09;信息&#xff1b; -l 列出目录或…...

【python】使用代理IP爬取猫眼电影专业评分数据

前言 我们为什么需要使用IP代理服务&#xff1f; 在编写爬虫程序的过程中&#xff0c;IP封锁无疑是一个常见且棘手的问题。尽管网络上存在大量的免费IP代理网站&#xff0c;但其质量往往参差不齐&#xff0c;令人堪忧。许多代理IP的延迟过高&#xff0c;严重影响了爬虫的工作…...

C/C++中枚举(enum)和结构体(struct)的异同

一、枚举 enum 1.普通枚举&#xff0c;枚举在C中使用比C使用简单 C语言: enum Color {red,green,blue }; enum Color c red;C语言 enum Color {red,green,blue }; Color c red;C认为这种枚举方式会污染名字&#xff0c;即&#xff1a;枚举使用的名字&#xff0c;在同一个作…...

【数据可视化】使用Python + Gephi,构建中医方剂关系网络图!

代码和示例数据下载 前言 在这篇文章中&#xff0c;我们将会可视化 《七版方剂学》 的药材的关系&#xff0c;我们将使用Python制作节点和边的数据&#xff0c;然后在Gephi中绘制出方剂的网络图。 Gephi是一个专门用于构建网络图的工具&#xff0c;只要你能提供节点和边的数…...

部署prometheus+Grafana可视化仪表盘监控服务

一、部署prometheus及监控仪表盘 简介 Prometheus是开源监控报警系统和时序列数据库(TSDB)。 Prometheus的基本原理是通过HTTP协议周期性抓取被监控组件的状态&#xff0c;任意组件只要提供对应的HTTP接口就可以接入监控&#xff0c;输出被监控组件信息的HTTP接口被叫做expo…...

python中的类与对象

前言 在Python中&#xff0c;类是一种用于创建新类型对象的结构&#xff0c;它允许我们将数据和功能&#xff08;属性和方法&#xff09;封装到一个单独的逻辑单元中。类可以被看作是创建对象&#xff08;实例&#xff09;的蓝图或模板。类&#xff08;Class&#xff09;和对象…...

sentry-cli - error: Failed to load .sentryclirc file from project path

Xcode 15.2 warning sentry-cli - error: Failed to load .sentryclirc file from project path (/Users/zhuhongwei/Desktop/pandabill/.sentryclirc)推荐一下刚上线的 App 熊猫小账本&#xff0c;里面有用到这篇博客讲的内容 熊猫小账本 一个简洁的记账 App&#xff0c;用于…...

回归预测 | Matlab实现SO-BP蛇算法优化BP神经网络多变量回归预测

回归预测 | Matlab实现SO-BP蛇算法优化BP神经网络多变量回归预测 目录 回归预测 | Matlab实现SO-BP蛇算法优化BP神经网络多变量回归预测预测效果基本描述程序设计参考资料 预测效果 基本描述 1.Matlab实现SO-BP蛇算法优化BP神经网络多变量回归预测&#xff08;完整源码和数据) …...

如何添加 Android Native 系统服务

如何添加 Android Native 系统服务 工作学习过程中&#xff0c;我们可能需要去阅读不同类型的 Native 系统服务&#xff0c;也有可能会自己去完成一个 Native 系统服务。无论哪种情况都需要我们了解基本的 Native 如何去添加。就像我们写 Android App 得先了解一下四大组件才行…...

【力扣】189.轮转数组

题目描述 给定一个整数数组 nums&#xff0c;将数组中的元素向右轮转 k 个位置&#xff0c;其中 k 是非负数。 示例 1: 输入: nums [1,2,3,4,5,6,7], k 3 输出: [5,6,7,1,2,3,4] 解释: 向右轮转 1 步: [7,1,2,3,4,5,6] 向右轮转 2 步: [6,7,1,2,3,4,5] 向右轮转 3 步: [5,6…...

C语言字符函数和字符串函数详解

Hello, 大家好&#xff0c;我是一代&#xff0c;今天给大家带来有关字符函数和字符串函数的有关知识 所属专栏&#xff1a;C语言 创作不易&#xff0c;望得到各位佬们的互三呦 一.字符函数 在C语言中有一些函数是专门为字符设计的&#xff0c;这些函数的使用都需要包含一个头文…...

【CKA模拟题】查询消耗CPU最多的Pod

题干 For this question, please set this context (In exam, diff cluster name) 对于此问题&#xff0c;请设置此上下文&#xff08;在考试中&#xff0c;diff 集群名称&#xff09; kubectl config use-context kubernetes-adminkubernetesFind the pod that consumes the …...

网络简略总结

目录 一、三次握手 四次挥手 1、三次握手:为了建立长链接进行交互即建立一个会话,使用http/https协议 2、四次挥手是一个断开连接释放服务器资源的过程 3、如果已经建立了连接,但是客户端突然出现故障了怎么办? 4、谁可以中断连接?客户端还是服务端还是都可以? 5、…...

如何处理错误情况

处理错误情况是确保自动窗帘系统稳定运行的重要一环。在编写代码时&#xff0c;你需要考虑可能发生的各种错误情况&#xff0c;并编写相应的错误处理代码。下面是一些处理错误情况的常见方法&#xff1a; (1)错误检测&#xff1a; 首先&#xff0c;你需要能够检测到错误的发生。…...

【Greenhills】MULTI IDE-GHS最新版本Compiler 23.5.4的兼容性问题

【更多软件使用问题请点击亿道电子官方网站查询】 1、 文档目标 关于GHS推出的最新编译器版本 Compiler 2023.5.4在GHS以前版本的MULTI IDE上面能否使用的问题 2、 问题场景 针对于&#xff0c;客户使用MULTI IDE 8.1.4以前的IDE版本&#xff0c;想要搭载使用最新版本的编译器…...

用连续自然数之和来表达整数 - 华为OD统一考试(C卷)

OD统一考试(C卷) 分值: 100分 题解: Java / Python / C++ 题目描述 一个整数可以由连续的自然数之和来表示。给定一个整数,计算该整数有几种连续自然数之和的表达式,且打印出每种表达式。 输入描述 一个目标整数T (1 <=T<= 1000) 输出描述 该整数的所有表达式…...

SQLiteC/C++接口详细介绍之sqlite3类(十二)

返回目录&#xff1a;SQLite—免费开源数据库系列文章目录 上一篇&#xff1a;SQLiteC/C接口详细介绍之sqlite3类&#xff08;十一&#xff09; 下一篇&#xff1a;SQLiteC/C接口详细介绍之sqlite3类&#xff08;十三&#xff09; ​37.sqlite3_load_extension 用于在SQLit…...

linux系统--------------mysql数据库管理

目录 一、SQL语句 1.1SQL语言分类 1.2查看数据库信息 1.3登录到你想登录的库 1.4查看数据库中的表信息 1.5显示数据表的结构&#xff08;字段&#xff09; 1.5.1数据表的结构 1.5.2常用的数据类型: 二、关系型数据库的四种语言 2.1DDL&#xff1a;数据定义语言&am…...

网络——入门基础

目录 协议 网络协议 OSI七层模型 网络传输基本流程 网络传输流程图 局域网通信 数据包的封装和解包 广域网通信 网络地址管理 IP地址 MAC地址 协议 关于什么是局域网&#xff0c;什么是广域网&#xff0c;我这里就不过多赘述了&#xff0c;我们直接来谈一下什么…...

ubuntu搭建nfs服务centos挂载访问

在Ubuntu上设置NFS服务器 在Ubuntu上&#xff0c;你可以使用apt包管理器来安装NFS服务器。打开终端并运行&#xff1a; sudo apt update sudo apt install nfs-kernel-server创建共享目录 创建一个目录用于共享&#xff0c;例如/shared&#xff1a; sudo mkdir /shared sud…...

椭圆曲线密码学(ECC)

一、ECC算法概述 椭圆曲线密码学&#xff08;Elliptic Curve Cryptography&#xff09;是基于椭圆曲线数学理论的公钥密码系统&#xff0c;由Neal Koblitz和Victor Miller在1985年独立提出。相比RSA&#xff0c;ECC在相同安全强度下密钥更短&#xff08;256位ECC ≈ 3072位RSA…...

(二)原型模式

原型的功能是将一个已经存在的对象作为源目标,其余对象都是通过这个源目标创建。发挥复制的作用就是原型模式的核心思想。 一、源型模式的定义 原型模式是指第二次创建对象可以通过复制已经存在的原型对象来实现,忽略对象创建过程中的其它细节。 📌 核心特点: 避免重复初…...

Robots.txt 文件

什么是robots.txt&#xff1f; robots.txt 是一个位于网站根目录下的文本文件&#xff08;如&#xff1a;https://example.com/robots.txt&#xff09;&#xff0c;它用于指导网络爬虫&#xff08;如搜索引擎的蜘蛛程序&#xff09;如何抓取该网站的内容。这个文件遵循 Robots…...

【论文阅读28】-CNN-BiLSTM-Attention-(2024)

本文把滑坡位移序列拆开、筛优质因子&#xff0c;再用 CNN-BiLSTM-Attention 来动态预测每个子序列&#xff0c;最后重构出总位移&#xff0c;预测效果超越传统模型。 文章目录 1 引言2 方法2.1 位移时间序列加性模型2.2 变分模态分解 (VMD) 具体步骤2.3.1 样本熵&#xff08;S…...

Aspose.PDF 限制绕过方案:Java 字节码技术实战分享(仅供学习)

Aspose.PDF 限制绕过方案&#xff1a;Java 字节码技术实战分享&#xff08;仅供学习&#xff09; 一、Aspose.PDF 简介二、说明&#xff08;⚠️仅供学习与研究使用&#xff09;三、技术流程总览四、准备工作1. 下载 Jar 包2. Maven 项目依赖配置 五、字节码修改实现代码&#…...

Netty从入门到进阶(二)

二、Netty入门 1. 概述 1.1 Netty是什么 Netty is an asynchronous event-driven network application framework for rapid development of maintainable high performance protocol servers & clients. Netty是一个异步的、基于事件驱动的网络应用框架&#xff0c;用于…...

C# 表达式和运算符(求值顺序)

求值顺序 表达式可以由许多嵌套的子表达式构成。子表达式的求值顺序可以使表达式的最终值发生 变化。 例如&#xff0c;已知表达式3*52&#xff0c;依照子表达式的求值顺序&#xff0c;有两种可能的结果&#xff0c;如图9-3所示。 如果乘法先执行&#xff0c;结果是17。如果5…...

Git常用命令完全指南:从入门到精通

Git常用命令完全指南&#xff1a;从入门到精通 一、基础配置命令 1. 用户信息配置 # 设置全局用户名 git config --global user.name "你的名字"# 设置全局邮箱 git config --global user.email "你的邮箱example.com"# 查看所有配置 git config --list…...

MySQL 索引底层结构揭秘:B-Tree 与 B+Tree 的区别与应用

文章目录 一、背景知识&#xff1a;什么是 B-Tree 和 BTree&#xff1f; B-Tree&#xff08;平衡多路查找树&#xff09; BTree&#xff08;B-Tree 的变种&#xff09; 二、结构对比&#xff1a;一张图看懂 三、为什么 MySQL InnoDB 选择 BTree&#xff1f; 1. 范围查询更快 2…...