when i am trying to convert this code into gpuArray then i will not get the same result?

1 visualizzazione (ultimi 30 giorni)
clc;
clear;
close all;
tic
k = 1:0.5:10;
a = 1:0.5:10;
n1 = numel(k);
nump = kron(k, ones(1, length(a)))';
n2 = numel(a);
denp = repmat([ones(n2,1), a.', zeros(n2,1)], n1, 1);
w = [0.1,0.5,0.8,1,2,8,15,50];
%%%%%% freqcp %%%%%%%%%%%%%%%%%%%%
delay = 0;
w = w(:)';
s = 1i * w;
upper = nump(:, 1);
for i = 2:size(nump, 2)
upper = bsxfun(@plus, bsxfun(@times, s, upper), nump(:, i));
end
lower = denp(:, 1);
for i = 2:size(denp, 2)
lower = bsxfun(@plus, bsxfun(@times, s, lower), denp(:, i));
end
X = bsxfun(@times, bsxfun(@rdivide, upper, lower), exp(-s * delay));
  3 Commenti
Walter Roberson
Walter Roberson il 29 Lug 2017
Generally speaking, gpu results are not expected to be exactly the same, because the GPU optimizes for speed, rather than for last bit accuracy.
Joss Knight
Joss Knight il 29 Lug 2017
I'd hate for that to go out there unqualified, Walter! gpuArray results should be precisely as accurate as the CPU. The answers will not always be the same, but they should just be 'differently wrong' in the order of f(eps(input)). A classic example is sum, where the GPU always gives a different answer because the numbers are added in a different order (in a binary tree), and is generally more accurate because the operands of each addition usually have the same magnitude (whereas when you're adding serially one operand is continually increasing in magnitude).
There are a few exceptions, as we recently discovered with exp for single. MATLAB's long-standing CPU implementations of some elementary functions include some very clever optimisations and on occasion the GPU implementation does not use these because they incur too great a performance cost for too little gain. But the general rule is that we want people to be able to rely on switching their code over to the GPU and getting results that are just as good.

Accedi per commentare.

Risposte (0)

Prodotti

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by