1

I have a function like,

function ObjVal=fun(Chrom,a)

  [Nind,Nvar] = size(Chrom);
  [m n]=size(a);

  for i=1:Nind
    c=Chrom(i,:);
    Cmat=repmat(c',1,n);
    ax=abs(sum(Cmat.*a)).^2;
    ObjVal(i)= 10*log10(max(ax)./(mean(ax)));
  end;

Chrom=16*16 and a=16*1024 array. I'm trying to find the fastest way on gpu. Only gpuarray is slower. When I use arrayfun or bsxfun I get some errors.

function valmult=mult(Cmat,a)

  valmult=abs(sum(Cmat.*a)).^2;

ax=arrayfun(@mult,Cmat,a); I get Function passed as first input argument contains unsupported or unknown function 'sum'.)

I am new in MATLAB with GPU. Any suggestions which way is the best and how can I maximize code performance with gpuarray?

1 Answer 1

0

Things will be better if you can eliminate the for-loop. It can be done by the following code.

ax_mat = (Chrom * a).^2;
ObjVal = 10 * log10(max(ax_mat, [], 2) ./ mean(ax_mat, 2));

On the other hand, the heaviest operation in the code, the matrix multiplication of Chrom * a, is too small (16x16x1024) to fully utilize the GPU. You may find that even with the improved code, GPU is still slower.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.