My GPU coder has wrong output.

조회 수: 1 (최근 30일)
lim daehee
lim daehee 2019년 12월 4일
답변: Walter Roberson 2019년 12월 4일
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?

답변 (1개)

Walter Roberson
Walter Roberson 2019년 12월 4일
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

카테고리

Help CenterFile Exchange에서 Get Started with GPU Coder에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by