-
Notifications
You must be signed in to change notification settings - Fork 0
/
gpuConvolutionCor.m
46 lines (35 loc) · 1016 Bytes
/
gpuConvolutionCor.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
function output = gpuConvolutionCor(input,filters,biasvals) % nxmxk input nxmxkxp filters
sizeofinput = size(input);
sizeoffilters = size(filters);
n = sizeofinput(1);
x = sizeofinput(2);
y = sizeofinput(3);
fn = sizeoffilters(1);
fd = sizeoffilters(2);
fx = sizeoffilters(3);
fy = sizeoffilters(4);
output = zeros(fn,x-fx+1,y-fy+1);
output = gpuArray(output);
ginput=gpuArray(input);
gfilters = gpuArray(filters);
gbiasvals = gpuArray(biasvals);
combinp = zeros(n,fx*fy,(x-fx+1)*(y-fy+1));
combinp = gpuArray(combinp);
for i=1:n
coninp = im2col(reshape(ginput(i,:,:),x,y),[fx fy]);
combinp(i,:,:) = coninp;
end
for j=1:fd
ress = reshape(combinp(j,:,:),fx*fy,(x-fx+1)*(y-fy+1))';
for i=1:fn
cf = im2col(reshape(filters(i,j,:,:),fx,fy),[fx fy]);
outfilter = ress*cf;
temp = reshape(outfilter,x-fx+1,y-fy+1);
output(i,:,:) = output(i,:,:)+reshape(temp,1,x-fx+1,y-fy+1);
end
end
for i=1:fn
output(i,:,:) = output(i,:,:) + biasvals(1,i);
end
output=gather(output);
end