Filter löschen
Filter löschen

My GPU coder has wrong output.

2 Ansichten (letzte 30 Tage)
lim daehee
lim daehee am 4 Dez. 2019
Beantwortet: Walter Roberson am 4 Dez. 2019
I'm studying GPU coder, and I have a problem with GPU coder.
I generated my code into MEX file stated below.
function [B_mat,R_mat] = fcn_Get_B(a) %#codegen
coder.gpu.kernelfun();
n = length(a);
B_mat = coder.nullcopy(ones(n));
R_mat = coder.nullcopy(ones(n));
coder.gpu.kernel;
for i=1:n
for j=1:n
R_mat(i,j)=B_mat(i,j)*3;
end
end
I intended that the result of B_mat is axa matrices and its elements are all 1 and R_mat is axa matrices and its elements are all 3. In CPU, the function worked well and the value B_mat and R_mat is as I thought. However, when I generated MEX file with this function, all elements of B_mat and R_mat became 0.
I wonder why this problem happened.
Does anybody who knows the way to solve my problem?

Antworten (1)

Walter Roberson
Walter Roberson am 4 Dez. 2019
X = coder.nullcopy(A) copies type, size, and complexity of A to X, but does not copy element values. The function preallocates memory for X without incurring the overhead of initializing memory. In code generation, the coder.nullcopy function declares uninitialized variables.
So your source matrix B_mat is uninitialized. It could contain anything . Containing 0 is as valid as anything else. It could contain 0xDEADBEEF

Kategorien

Mehr zu Get Started with GPU Coder finden Sie in Help Center und File Exchange

Community Treasure Hunt

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

Start Hunting!

Translated by