My GPU coder has wrong output.

1 visualización (últimos 30 días)
lim daehee
lim daehee el 4 de Dic. de 2019
Respondida: Walter Roberson el 4 de Dic. de 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?

Respuestas (1)

Walter Roberson
Walter Roberson el 4 de Dic. de 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

Categorías

Más información sobre Get Started with GPU Coder en Help Center y File Exchange.

Community Treasure Hunt

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

Start Hunting!

Translated by