用CUDA实现矩阵乘法后.我试图用CUBLAS实现它(感谢论坛中一些人的建议).
我可以乘以平方矩阵但是(是的再次......)我在使用非方矩阵时遇到了困难.唯一可行的非方矩阵乘法类型是改变矩阵A的宽度(A*B = C).
我没有得到任何错误,但结果矩阵返回错误的值.这是我的代码(它基本上是simpleCUBLAS SDK示例的改编):
#include <stdlib.h>
#include <stdio.h>
#include "cublas.h"
#define HA 2
#define WA 9
#define WB 2
#define HB WA
#define WC WB
#define HC HA
#define index(i,j,ld) (((j)*(ld))+(i))
void printMat(float*P,int uWP,int uHP){
//printf("\n %f",P[1]);
int i,j;
for(i=0;i<uHP;i++){
printf("\n");
for(j=0;j<uWP;j++)
printf("%f ",P[index(i,j,uHP)]);
//printf("%f ",P[i*uWP+j]);
}
}
int main (int argc, char** argv) {
cublasStatus status;
int i,j;
cublasInit();
float *A = (float*)malloc(HA*WA*sizeof(float));
float *B = (float*)malloc(HB*WB*sizeof(float));
float *C = (float*)malloc(HC*WC*sizeof(float));
if (A == 0) {
fprintf …Run Code Online (Sandbox Code Playgroud) 我在CUDA中用于矩阵乘法的代码允许我将正方形矩阵和非正方形矩阵相乘,但是,宽度和高度必须是块大小的倍数.
所以,例如,我可以乘[3] [6]*[6] [3](使用blocksize = 3),但我不能乘以[3] [2]*[2] [3].
有谁知道这样做的方法?这是我的内核:
#include <stdio.h>
#include <limits.h>
#include <stdlib.h>
#define blocksize 3
#define HM (1*blocksize)
#define WM (2*blocksize)
#define WN (1*blocksize)
#define HN WM
#define WP WN
#define HP HM
#define PTH WM
#define PTW HM
__global__ void nonsquare(float*M, float*N, float*P, int uWM,int uWN)
{
__shared__ float MS[blocksize][blocksize];
__shared__ float NS[blocksize][blocksize];
int tx=threadIdx.x, ty=threadIdx.y, bx=blockIdx.x, by=blockIdx.y;
int rowM=ty+by*blocksize;
int colN=tx+bx*blocksize;
float Pvalue=0;
for(int m=0; m< uWM/blocksize;++m){
MS[ty][tx]=M[rowM*uWM+(m*blocksize+tx)];
NS[ty][tx]=M[colN + uWN*(m*blocksize+ty)];
__syncthreads();
for(int k=0;k<blocksize;k++)
Pvalue+=MS[ty][k]*NS[k][tx]; …Run Code Online (Sandbox Code Playgroud) 经过一番研究,我没有发现与我的问题相关的任何内容。所以设置是已经与 sequelize (sqllite) 一起工作的 M:M 关系:
return User.find({ where: { _id: userId } }).then(user => {
logger.info(`UserController - found user`);
Notification.find({ where: { _id: notificationId } }).then(notification => {
if (associate) {
return user.addNotification([notification]);
} else {
return user.removeNotification([notification]);
}
})
})
Run Code Online (Sandbox Code Playgroud)
问题是我在 inter 表(cityId,active)中有额外的字段,我不知道在运行“addNotification”时如何更新它。
提前致谢
我试图只包括一些路由(身份验证)的会话,但由于错误页面路由我遇到了问题:
我有这个:
app.use(session({
secret: config.secrets.session,
saveUninitialized: false,
resave: false,
store: sessionStore,
proxy: true,
cookie: {
maxAge: config.token_duration,
secure: false
}
// rolling: false
}));
app.use('/api/user', require('./api/user'));
app.use('/api/auth', require('./api/auth'));
app.route(['/error/500','/error/404','/user/settings'])
.get((req, res) => {
res.sendFile(path.resolve(app.get('appPath') + '/index.html'));
});
app.route('/*/*')
.get(errors[404]);
app.use(errors[500]);
Run Code Online (Sandbox Code Playgroud)
所以,如果我像这样使用它,我的应用程序中的所有页面都将创建一个会话(我不想要).如果我在错误路由之后移动会话部分,我将永远不会到达api路由,因为它将到达404路由.
提前致谢
我搜索过网站,但我找不到问题的答案.
我的程序输出一个图像,我想保存到一个不同的文件,每个图像在循环迭代后产生.
我保存文件的代码就是这个
FILE *fobjecto;
if ((fobjecto = fopen ("OSEM.ima", "wb")) != NULL)
{
printf("Writing reconstructed image file");
fwrite (objecto, sizeof(float), (detectorXDim)*detectorYDim*(NSlices-1), fobjecto);
fclose (fobjecto);
}
else
printf("Reconstructed image file could not be saved");
Run Code Online (Sandbox Code Playgroud)
我想在输出文件的名称中添加一个整数变量,我试过用"+"和","但我无法解决它.
提前致谢