- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我有一个带有一些 SSE2 指令的 C++ 函数。问题是在使用 Microsoft Visual C++ 编译此代码时出现以下链接器错误:
函数“void * __cdecl”中引用的未解析外部符号 _m_empty过程(无效*)”
当我评论 _m_empty 时,我会得到一个运行时错误!但它应该用于 MMX 指令,不是吗?
#include "mex.h"
#include <pthread.h>
#include <emmintrin.h>
#include <stdint.h>
#include <stdlib.h>
#define malloc_aligned(a,b) _aligned_malloc(a,b)
#define IS_ALIGNED(ptr) ((((uintptr_t)(ptr)) & 0xF) == 0)
#define NUM_FEATURES 32
#define __attribute__(A) /* do nothing */
/*
* This code is used for computing filter responses. It computes the
* response of a set of filters with a feature map.
*
* Multithreaded version.
*/
struct thread_data {
float *A;
float *B;
double *C;
mxArray *mxC;
const mwSize *A_dims;
const mwSize *B_dims;
mwSize C_dims[2];
};
// convolve A and B
void *process(void *thread_arg) {
thread_data *args = (thread_data *)thread_arg;
float *A = args->A;
float *B = args->B;
double *C = args->C;
const mwSize *A_dims = args->A_dims;
const mwSize *B_dims = args->B_dims;
const mwSize *C_dims = args->C_dims;
__m128 a,b,c;
double *dst = C;
for (int x = 0; x < C_dims[1]; x++) {
for (int y = 0; y < C_dims[0]; y++) {
__m128 v = _mm_setzero_ps();
const float *A_src = A + y*NUM_FEATURES + x*A_dims[0]*NUM_FEATURES;
const float *B_src = B;
for (int xp = 0; xp < B_dims[1]; xp++) {
const float *A_off = A_src;
const float *B_off = B_src;
for (int yp = 0; yp < B_dims[0]; yp++) {
a = _mm_load_ps(A_off+0);
b = _mm_load_ps(B_off+0);
c = _mm_mul_ps(a, b);
v = _mm_add_ps(v, c);
a = _mm_load_ps(A_off+4);
b = _mm_load_ps(B_off+4);
c = _mm_mul_ps(a, b);
v = _mm_add_ps(v, c);
a = _mm_load_ps(A_off+8);
b = _mm_load_ps(B_off+8);
c = _mm_mul_ps(a, b);
v = _mm_add_ps(v, c);
a = _mm_load_ps(A_off+12);
b = _mm_load_ps(B_off+12);
c = _mm_mul_ps(a, b);
v = _mm_add_ps(v, c);
a = _mm_load_ps(A_off+16);
b = _mm_load_ps(B_off+16);
c = _mm_mul_ps(a, b);
v = _mm_add_ps(v, c);
a = _mm_load_ps(A_off+20);
b = _mm_load_ps(B_off+20);
c = _mm_mul_ps(a, b);
v = _mm_add_ps(v, c);
a = _mm_load_ps(A_off+24);
b = _mm_load_ps(B_off+24);
c = _mm_mul_ps(a, b);
v = _mm_add_ps(v, c);
a = _mm_load_ps(A_off+28);
b = _mm_load_ps(B_off+28);
c = _mm_mul_ps(a, b);
v = _mm_add_ps(v, c);
// N.B. Unroll me more/less if you change NUM_FEATURES
A_off += NUM_FEATURES;
B_off += NUM_FEATURES;
}
A_src += A_dims[0]*NUM_FEATURES;
B_src += B_dims[0]*NUM_FEATURES;
}
// buf[] must be 16-byte aligned
float buf[4] __attribute__ ((aligned (16)));
_mm_store_ps(buf, v);
_mm_empty();
*(dst++) = buf[0]+buf[1]+buf[2]+buf[3];
}
}
pthread_exit(NULL);
return 0;
}
float *prepare(float *in, const int *dims) {
float *F = (float *)malloc_aligned(16, dims[0]*dims[1]*NUM_FEATURES*sizeof(float));
// Sanity check that memory is aligned
if (!IS_ALIGNED(F))
mexErrMsgTxt("Memory not aligned");
float *p = F;
for (int x = 0; x < dims[1]; x++) {
for (int y = 0; y < dims[0]; y++) {
for (int f = 0; f < dims[2]; f++)
*(p++) = in[y + f*dims[0]*dims[1] + x*dims[0]];
for (int f = dims[2]; f < NUM_FEATURES; f++)
*(p++) = 0;
}
}
return F;
}
// matlab entry point
// C = fconv(A, cell of B, start, end);
void mexFunction(int nlhs, mxArray *plhs[], int nrhs, const mxArray *prhs[]) {
if (nrhs != 4)
mexErrMsgTxt("Wrong number of inputs");
if (nlhs != 1)
mexErrMsgTxt("Wrong number of outputs");
// get A
const mxArray *mxA = prhs[0];
if (mxGetNumberOfDimensions(mxA) != 3 ||
mxGetClassID(mxA) != mxSINGLE_CLASS)
mexErrMsgTxt("Invalid input: A");
// get B and start/end
const mxArray *cellB = prhs[1];
mwSize num_bs = mxGetNumberOfElements(cellB);
int start = (int)mxGetScalar(prhs[2]) - 1;
int end = (int)mxGetScalar(prhs[3]) - 1;
if (start < 0 || end >= num_bs || start > end)
mexErrMsgTxt("Invalid input: start/end");
int len = end-start+1;
// start threads
thread_data *td = (thread_data *)mxCalloc(len, sizeof(thread_data));
pthread_t *ts = (pthread_t *)mxCalloc(len, sizeof(pthread_t));
const mwSize *A_dims = mxGetDimensions(mxA);
float *A = prepare((float *)mxGetPr(mxA), A_dims);
for (int i = 0; i < len; i++) {
const mxArray *mxB = mxGetCell(cellB, i+start);
td[i].A_dims = A_dims;
td[i].A = A;
td[i].B_dims = mxGetDimensions(mxB);
td[i].B = prepare((float *)mxGetPr(mxB), td[i].B_dims);
if (mxGetNumberOfDimensions(mxB) != 3 ||
mxGetClassID(mxB) != mxSINGLE_CLASS ||
td[i].A_dims[2] != td[i].B_dims[2])
mexErrMsgTxt("Invalid input: B");
// compute size of output
int height = td[i].A_dims[0] - td[i].B_dims[0] + 1;
int width = td[i].A_dims[1] - td[i].B_dims[1] + 1;
if (height < 1 || width < 1)
mexErrMsgTxt("Invalid input: B should be smaller than A");
td[i].C_dims[0] = height;
td[i].C_dims[1] = width;
td[i].mxC = mxCreateNumericArray(2, td[i].C_dims, mxDOUBLE_CLASS, mxREAL);
td[i].C = (double *)mxGetPr(td[i].mxC);
if (pthread_create(&ts[i], NULL, process, (void *)&td[i]))
mexErrMsgTxt("Error creating thread");
}
// wait for the treads to finish and set return values
void *status;
plhs[0] = mxCreateCellMatrix(1, len);
for (int i = 0; i < len; i++) {
pthread_join(ts[i], &status);
mxSetCell(plhs[0], i, td[i].mxC);
free(td[i].B);
}
mxFree(td);
mxFree(ts);
free(A);
}
最佳答案
根据 this link , MMX 没有为 x64 实现。使用成熟的 SSE2 n x64。
关于c++ - 为什么我不能删除 _mm_empty()?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34308187/
我是 javascript 的新手(今天开始弄乱它)。 我正在尝试更改名为“bar”的元素(div)的高度。条形图将成为图表的一部分。 我可以毫无问题地将按钮连接到更改栏高度的函数。一切正常,除了条形
错误 -> “UIVIew”没有名为“addSubView”的成员 override func viewDidLoad() { super.viewDidLoad() // Do an
我在命令行工具项目中复制并粘贴了 main.swift 下面链接中的代码。 How do you use CGEventTapCreate in Swift? 它构建没有错误,但是当我运行时, gua
我在尝试编译我的代码时遇到以下错误。 ERROR! ..\myCode\CPOI.cpp:68:41: error: cannot dynamic_cast 'screenType' (of type
我正在尝试将多个字符串连接到一个我已为其分配内存的字符串指针。这是一个例子: char *finalNumString = malloc(sizeof(char)*1024); finalNumStr
我在使用 dup2() 和 pipe() 时遇到问题。 当我尝试将管道的写入端 dup2 到 STDOUT_FILENO 时,我收到了 EBADF。 我用 gdb 在 dup2(pout[1], ST
首先,我应该说我运行的是 Windows 7。 因此,今天早上我尝试像往常一样从我的存储库中提取数据,但我做不到。我得到了错误: The authenticity of host 'github.co
刚开始在虚拟环境中运行Python,乱用Django,无法激活虚拟环境。 花了最后 4 个小时尝试在本地终端/VS 代码上激活虚拟环境 (venv),但没有成功。 避免使用“sudo pip inst
Tidyverse 的粉丝经常给出使用小标题而不是数据框的几个优点。它们中的大多数似乎旨在保护用户免于犯错误。例如,与数据框不同,小标题: 不需要 ,drop=FALSE不从数据中删除维度的论据。 不
我一直在对 Elm 应用程序进行 docker 化时遇到问题。据我所知,我已经创建了一个完整且有效的 Docker 文件……但它不起作用。 我会解释的。 所以我的脚本在 3 个文件中运行。 首先是启动
我可以在 Controller 中使用@Autowired,例如 @RestController public class Index { @Autowired HttpServlet
我定义了一个方法和一个函数: def print(str:String) = println val intToString = (n:Int) => n.toString 现在我想创作它们。 我的问
当我控制台单独记录变量“pokemons”时,它确实返回一个数组。但是当我尝试映射它时,出现错误: TypeError: pokemons.map is not a function 我的代码: im
每当我尝试在 Python 解释器中导入 smtplib 时,都会收到此错误: ImportError: cannot import name fix_eols 我该如何解决这个问题? 编辑:这是完整
我正在使用 Meteor.js 开发一个项目,但在使用 Handlebar 时遇到了一些问题:我想检索集合的最后一项,并显示字段:其中包含 html 的文本: 这是我的javascript代码: Te
你好,我想使用 Service 实现 GestureDetector 但是我有这个错误The method onTouchEvent(MotionEvent) of type GestureServi
我正在尝试在 Controller bean 中 Autowiring 接口(interface) 在我放置的上下文配置文件中 和 我的 Controller 类是 @Controller pub
我试图在 mainwindow.cpp 中包含 QtSvg,但是当我编译时它说无法打开包含文件:QtSvg。我已经在我的 *.pro 文件中添加了这个(QT += svg)。我可以知道可能是什么问题吗
鉴于以下 PostgreSQL 代码,我认为这段代码不容易受到 SQL 注入(inject)攻击: _filter 'day' _start 1 _end 10 _sort 'article_name
我想执行以下操作。这在 MySQL 中是非法的。 PostGRESQL 中关联的 CTE(“with”子句)有效。这里的假设是 MySQL 中的子查询不是完全限定的 CTE。 请注意:这个查询显然非常
我是一名优秀的程序员,十分优秀!