For testing the GPU capabilities on Matlab with testGPU.m script Y = exp(X) [by the Horner's rule] + sinc(X^2) Z is based on matrix product for testing the effect of network between cores on GPU calculations INPUTS: - X: any tensor [n,m,p,....] - a: scalar or tensor [n,m,p,....] - b: scalar or tensor [n,m,p,....] - c: parameters in cell format [1,3] - d: parameters in structure format [1,3] OUTPUTS: - Y: processed tensor [n,m,p,....] - Z: processed tensor [n,m,p,....] - T: processed structure T.y = Y and T.z = Z [structure] - W: processed cell W{Y}, W{Z} [table of cells] by Yves Peysson <yves.peysson@cea.fr> (CEA-IRFM) and Joan Decker <joan.decker@cea.fr> (CEA-IRFM)
0001 function [Y,Z,T,W] = funGPU(X,a,b,c,d) 0002 % 0003 % For testing the GPU capabilities on Matlab with testGPU.m script 0004 % Y = exp(X) [by the Horner's rule] + sinc(X^2) 0005 % Z is based on matrix product for testing the effect of network between cores on GPU calculations 0006 % 0007 % INPUTS: 0008 % 0009 % - X: any tensor [n,m,p,....] 0010 % - a: scalar or tensor [n,m,p,....] 0011 % - b: scalar or tensor [n,m,p,....] 0012 % - c: parameters in cell format [1,3] 0013 % - d: parameters in structure format [1,3] 0014 % 0015 % OUTPUTS: 0016 % 0017 % - Y: processed tensor [n,m,p,....] 0018 % - Z: processed tensor [n,m,p,....] 0019 % - T: processed structure T.y = Y and T.z = Z [structure] 0020 % - W: processed cell W{Y}, W{Z} [table of cells] 0021 % 0022 % by Yves Peysson <yves.peysson@cea.fr> (CEA-IRFM) and Joan Decker <joan.decker@cea.fr> (CEA-IRFM) 0023 % 0024 if nargin == 3, 0025 [Y,Z] = funGPU1(X,a,b); 0026 elseif nargin == 4,%matrix product with cell (imaginary or real) 0027 if ~isempty(c) && iscell(c), 0028 [Y,Z] = funGPU1(X,a,b,c); 0029 else 0030 [Y,Z] = funGPU1(X,a,b); 0031 end 0032 elseif nargin == 5,%matrix product with structure (imaginary or real) 0033 if ~isempty(c) && iscell(c) && isstruct(d), 0034 % 0035 [Y,Z] = funGPU1(X,a,b,c); 0036 % 0037 fn = fieldnames(d); 0038 for id = 1:size(d), 0039 for ifn = 1:length(fn), 0040 if ~isempty(d(id).(fn{ifn})), 0041 Z = d(id).(fn{ifn}).*Z^2; 0042 end 0043 end 0044 end 0045 else 0046 [Y,Z] = funGPU1(X,a,b); 0047 end 0048 end 0049 % 0050 T.y = Y; 0051 T.z = Z; 0052 % 0053 W{1} = Y; 0054 W{2} = Z; 0055 % 0056 end 0057 % 0058 function [Y,Z] = funGPU1(X,a,b,c) 0059 % 0060 Y = 1 + X.*(1 + X.*((1 + X.*((1 + X.*((1 + X.*((1 + X.*((1 + X.*((1 + X.*((1 + X./9)./8))./7))./6))./5))./4))./3))./2)) + sinc(X.^2);%matrix dot-product (Horner's rule to compute y = exp(x) + sinc(x^2)) 0061 % 0062 if imag(a)~=0 || imag(b)~=0, 0063 Z = a - 3*b + Y*(1 + Y*((1 + Y*((1 + Y*((1 + Y*((1 + Y*((1 + Y*((1 + Y*((1 + Y/9)/8))/7))/6))/5))/4))/3))/2));%for testing matrix product that uses heavily network between cores 0064 else 0065 Z = ''; 0066 end 0067 % 0068 if nargin == 4, 0069 Z = c{1}.*Y - c{2}.*Y.^2 + c{3}.*Y.^3; 0070 end 0071 end