1 / 26

SCILAB2C Requirements

SCILAB2C Requirements. Raffaele Nutricato PoliBa. Agenda. Open Issues SCI LAB 2C specifications and limitations. Open Issues: I/O. (Prof. Piazza) We need specifications concerning the input and output data management. Two approaches can be adopted:

axl
Télécharger la présentation

SCILAB2C Requirements

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. SCILAB2C Requirements Raffaele Nutricato PoliBa

  2. Agenda • Open Issues • SCILAB2C specifications and limitations

  3. Open Issues: I/O (Prof. Piazza) We need specifications concerning the input and output data management. Two approaches can be adopted: • Input/Output files  SCI2C will support file management functions • Input/Output buffers  SCI2C will not support file management functions.

  4. Open Issues: Complex Numbers • Need to define an implementation for complex numbers… • For now we have a strong interface(but it may decrease efficiency)

  5. Open Issues: Complex Numbers ************ We proposed 2 implementations: ************ • Standard C-99 : #include <complex.h> […] double a=1.0; double b=2.0; float c=3.0; float d=4.0; double complex z = a+b*I; float complex w = c+d*I; • Hand made Complex structure with strong interface that hide the real implementation : (Only given as example, must be improve for efficiency) #include <doubleComplex.h> #include <floatComplex.h> […] double a=1.0; double b=2.0; float c=3.0; float d=4.0; doubleComplex z = DoubleComplex(a,b); floatComplex w = FloatComplex(c,d);

  6. Open Issues: Complex Numbers ******* Implementation depends on compilation options ******* /* ** \function DoubleComplex ** \brief construct a Double Complex . */ doubleComplex DoubleComplex(double real, double imag) { doubleComplex z; #ifndefSTDC99 z.real = real; z.imag = imag; #else z = real + I * imag; #endif return z; } /* ** Hand made Double Complex definition ** { */ struct double_complex { double real; double imag; }; typedefstruct double_complex doubleComplex; /* ** } */ But we may add another implementation if it’s more efficient. /* ** Another Hand made Double Complex definition ** { */ struct double_complex { double z[2]; }; typedefstruct double_complex doubleComplex; /* ** } */ /* ** Standard C99 Complex ** { */ #include <complex.h> typedef double complex doubleComplex; /* ** } */

  7. Open Issues: String manipulation • Do we need support for string manipulation? Is it important for DSP?

  8. SCI2C specifications and limitations • Most of the specifications for the SCILAB2C tool come from previous meetings with other hArtes partners (mainly INRIA) • They have been proposed in order to reach the final goal (Dr. Gomez): to produce an optimized code. “Optimized" means that the generated C code does not include any part of Scilab interpreter. So it should be very small and efficient.

  9. SCI2C specifications and limitations: Memory Optimization Optimization of memory usage requires: • Function Arguments are passed by reference. • No dynamic memory allocation

  10. SCI2C specifications and limitations: Memory Optimization Function Arguments are passed by reference (in Scilab/Matlab they are passed by value). This means that: • the body of function cannot change the input parameter values. or… • a warning can be issued by the SCILAB2C tool when a function input prm is modified by the body of the function so that the user can change the code according to the warning message. Sol.: Function c = test(a1,b) a = a1; c = a + b; a = rand(); c = c + a; Ex.: Function c = test(a,b) c = a + b; a = rand(); c = c + a; Warning here

  11. SCI2C specifications and limitations: Memory Optimization No dynamic memory allocation. This means that: • No dynamic array extension Ex.: A = [A B]; NOT ALLOWED!!!! • No support for Scilab t-list type. • The code must be annotated: users must specify precisionand size of data (for local/global vars and function prms)

  12. SCI2C specifications and limitations: Memory Optimization Examples of code annotation: Annotated version //SCI2C: PRECISION float; //SCI2C: a = complex2D(10,15) //SCI2C: b = real2D(10,10) //SCI2C: c = real2D(10,15) Non-Annotated version . . . c = foo3(a,b); function y = foo3(x,z) y = abs(x) + det(z); endfunction . . . c = foo3(a,b); //SCI2C: y.size = x.size //SCI2C: y.type = z.type function y = foo3(x,z) y = abs(x) + det(z); endfunction Annotations avoids dynamic memory annotation + crazy code!!!

  13. SCI2C specifications and limitations: Memory Optimization Not known the size of the memory that have to be allocated Examples of crazy code: Somtimes it can work, but if M = random… c = det(RandomMtx()); function B = RandomMtx() M = round(10*rand()); B = rand(M,M); endfunction c = det(RandomMtx(M)); function B = RandomMtx(M) B = rand(M,M); endfunction Rule: Non-crazy code is code that can be annotated by using relationships as OutPrmSize=fnc(InPrmSize). This ensures that the sizes of matrices can be computed at compile time. A = rand(10,15) C = transpose(A); //SCI2C: B.size = [A.size(2), A.size(1)] //SCI2C: B.type = A.type function B = transpose(A) B = A.’; endfunction A = rand(10,10) C = determinant(A); //SCI2C: B.size = [1, 1] //SCI2C: B.type = real function B = determinant(A) B = abs(det(A)); endfunction OK!!! OK!!!

  14. SCI2C specifications and limitations: Memory Optimization Not known the size of the memory that have to be allocated Examples of crazy code: Not known the size and type of the output matrix c = zeromatrix(2); function B = zeromatrix(a) if (a==1) B = zeros(10,10); end if (a==2) B = zeros(20,20); end if (a==3) B = zeros(30,30); end endfunction c = ReferenceMatrix(-11); function B = ReferenceMatrix(a) if (a==1) B = zeros(10,10); elseif (a==2) B = zeros(20,20); elseif (a==-1) B = ones(10,10); else B = ones(20,20)+%i*ones(20,20); end endfunction Non-crazy code is code that can be annotated by using relationships as OutPrmSize=fnc(InPrmSize)

  15. SCI2C specifications and limitations • Functions with a variable number of input/output arguments. In calling a function, users have always to specify all input/output arguments. Prof. Piazza says that it is a strong limitation. We can check (with INRIA) if it is possible to guarantee variable input/output arguments only for the SCI2C DSP library (not for all the scilab functions written by the user). • Change for the moment… • SCI2C DSP library is the library that INRIA is developing in C. • The SCI2C DSP library will be composed of the following functions:…

  16. SCI2C specifications and limitations Basic Statements Support for: • for • while • if, else, elseif • Complex forms of the for statement. From scilab help: • Simple: for j = 2:3:n-1, a(j,j) = j; end; • Complex: for e=eye(3,3),e,end From Matlab help: Long loops are more memory efficient when the colon expression appears in the FOR statement since the index vector is never created.

  17. SCI2C specifications and limitations • find • isempty • isnan • rand • Op: • size • type Auxiliary functions

  18. SCI2C specifications and limitations • FIR • IIR • hilbert • conv • conv2d • cvexp • fft • ifft • levinson • lpc2cep • xcorrc DSP functions

  19. SCI2C specifications and limitations • acos • acosh • asin • asinh • atanh • cos • cosh • exp Elementary functions • log • log10 • sin • sinh • sqrt • tan • tanh • vatan2 • vexp10v

  20. SCI2C specifications and limitations Matrix Operators • abs, det, inv, mchol, sum, trace Arithmetic operators. plus - Plus + minus - Minus - uminus - Unary minus - mtimes - Matrix multiply * times - Array multiply .* mpower - Matrix power ^ power - Array power .^ mrdivide - Slash or right matrix divide / rdivide - Right array divide ./ Relational operators. eq - Equal == ne - Not equal ~= lt - Less than < gt - Greater than > le - Less than or equal <= ge - Greater than or equal >= Logical operators. and - Logical AND & or - Logical OR | not - Logical NOT ~

  21. SCI2C specifications and limitations • part • strcat • strcmp • strindex • strsubst String handling ???

  22. SCI2C specifications and limitations • mclose • mget • mopen • mprintf • mseek File Management ???

  23. SCI2C specifications and limitations • Max dimension is 2D • Each source file must contain only one function declaration NO multiple functions can be written into the same file. • N-ary expressions: Expressions as E=A+B+C+D will not be converted as: • E[i] = A[i] + B[i]+ C[i] + D[i]. • They will be converted as: • E = sum(A,sum(B,sum(C,D))); • To force the first implementation the user har to re-write the Scilab code as in the following example: • for i=1:N • E[i] = A[i] + B[i]+ C[i] + D[i] • end • No support for optimizations that are already available in the C compiler.

  24. SCI2C specifications and limitations • DATA TYPES SUPPORTED: • TYPES: Real/Complex • PRECISION: Float/Double • Integer precision is supported only for the counter variables of the “for” loops. • The precision of data can be float or double and it is the same for all the variables (except for counter variables in the “for loops”).

  25. Control of temp variables Support for temp variables generation control (remove dependences + src != dest): • a = (b + c + h) * (d + e); • a = b + c; • a = a + h; • temp1 = d + e; • a = a * temp1; Or • temp1 = b + c; • temp2 = temp1 + h; • temp3 = d + e; • a = temp2 * temp3; There are some mAgic functions that don’t allow src=dest

  26. End Of Presentation Thank you! Raffaele Nutricato

More Related