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 Center および File ExchangeMATLAB Coder についてさらに検索

Community Treasure Hunt

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

Start Hunting!

Translated by