How to convert my function for GPU (Cuda) and run it on GPU

조회 수: 10 (최근 30일)
SH
SH 2023년 3월 8일
댓글: Joss Knight 2023년 3월 14일
Hello, I hope you are doing well, I have the following function i want to convert it into cuda so it can run on GPU or any other Embedded Device
Can anybody Please help me with this
I also Attached My dataset for this
function [Score] = Scorefunction(Dataset,clusternumber)
dataset_len = size(Dataset,1);
Score = zeros(1,clusternumber);
for j=1:clusternumber
[cluster_assignments,centroids] = kmeans(Dataset,j);
distance_within=zeros(dataset_len,1);
distance_between=Inf(dataset_len,j);
for i=1:dataset_len
for jj=1:j
boo=cluster_assignments==cluster_assignments(i);
Xsamecluster=Dataset(boo,:);
if size(Xsamecluster,1)>1
distance_within(i)=sum(sum((Dataset(i,:)-Xsamecluster).^2,2))/(size(Xsamecluster,1)-1);
end
boo1= cluster_assignments~=cluster_assignments(i);
Xdifferentcluster=Dataset(boo1 & cluster_assignments ==jj,:);
if ~isempty(Xdifferentcluster)
distance_between(i,jj)=mean(sum((Dataset(i,:)-Xdifferentcluster).^2,2));
end
end
end
minavgDBetween = min(distance_between, [], 2);
silh = (minavgDBetween - distance_within) ./ max(distance_within,minavgDBetween);
Score(j) =mean(silh);
end
end
  댓글 수: 1
Joss Knight
Joss Knight 2023년 3월 14일
Do you need to deploy to an embedded device or just run on GPU on the desktop? Because you can just use PCT's gpuArray.

댓글을 달려면 로그인하십시오.

답변 (1개)

Arka
Arka 2023년 3월 8일
Hi,
MATLAB has quite a few coder apps to generate specific code from MATLAB code.
To generate GPU code, you can make use of the GPU Coder.
To generate Embedded Code, you can use the Embdedded Coder.
If you wish to learn more about GPU coder and Embedded coder, please check out the MathWorks documentation links below:
  댓글 수: 4
SH
SH 2023년 3월 8일
@Arka I am unable to convert it into cuda, I want to write a Code for this
Arka
Arka 2023년 3월 9일
What have you tried till now, and what is the error that you are encountering?

댓글을 달려면 로그인하십시오.

카테고리

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