I have no problem when I use cublasSscal with alpha=3 (or other constants)

[codebox]#include “mex.h”

#include “cublas.h”

void mexFunction(int nlhs, mxArray *plhs, int nrhs, const mxArray *prhs)

{

int m,n;

int dims0[2];

float *A,*gA,*ans;

m=mxGetM(prhs[0]);

n=mxGetN(prhs[0]);

dims0[0]=m;

dims0[1]=n;

plhs[0]=mxCreateNumericArray(2,dims0,mxSINGLE_CLASS,mxREAL);

ans=(float*)mxGetData(plhs[0]);

A=(float*)mxGetData(prhs[0]);

cublasInit();

cublasAlloc(m*n,sizeof(float),(void**)&gA);

cudaMemset(gA,0,m*n*4);

cublasSetMatrix(m,n,sizeof(float),A,m,(void*)gA,m);

(void)cublasSscal(m-1,3,gA,1);

cublasGetMatrix(m,n,sizeof(float),gA,m,ans,m);

cublasFree(gA);

}[/codebox]

But I start to get problem when I use an element in gA instead of a constant for alpha (eg. gA[1])

[codebox]#include “mex.h”

#include “cublas.h”

void mexFunction(int nlhs, mxArray *plhs, int nrhs, const mxArray *prhs)

{

int m,n;

int dims0[2];

float *A,*gA,*ans;

m=mxGetM(prhs[0]);

n=mxGetN(prhs[0]);

dims0[0]=m;

dims0[1]=n;

plhs[0]=mxCreateNumericArray(2,dims0,mxSINGLE_CLASS,mxREAL);

ans=(float*)mxGetData(plhs[0]);

A=(float*)mxGetData(prhs[0]);

cublasInit();

cublasAlloc(m*n,sizeof(float),(void**)&gA);

cudaMemset(gA,0,m*n*4);

cublasSetMatrix(m,n,sizeof(float),A,m,(void*)gA,m);

(void)cublasSscal(m-1,gA[1],gA,1);

cublasGetMatrix(m,n,sizeof(float),gA,m,ans,m);

cublasFree(gA);

}[/codebox]