123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506 |
- {
- File: vBLAS.p
-
- Contains: Header for the Basic Linear Algebra Subprograms, with Apple extensions.
-
- Version: Technology: All
- Release: Universal Interfaces 3.4.2
-
- Copyright: © 2000-2002 by Apple Computer, Inc., all rights reserved.
-
- Bugs?: For bug reports, consult the following page on
- the World Wide Web:
-
- http://www.freepascal.org/bugs.html
-
- }
- { ========================================================================================================================== }
- {
- =================================================================================================
- Definitions of the Basic Linear Algebra Subprograms (BLAS) as provided by Apple Computer. At
- present this is a subset of the "legacy" FORTRAN and C interfaces. Only single precision forms
- are provided, and only the most useful routines. For example only the general matrix forms are
- provided, not the symmetric, Hermitian, or triangular forms. A few additional functions, unique
- to Mac OS, have also been provided. These are clearly documented as Apple extensions.
- Documentation on the BLAS standard, including reference implementations, can be found on the web
- starting from the BLAS FAQ page at these URLs (at least as of August 2000):
- http://www.netlib.org/blas/faq.html
- http://www.netlib.org/blas/blast-forum/blast-forum.html
- =================================================================================================
- }
- {
- =================================================================================================
- Matrix shape and storage
- ========================
- Keeping the various matrix shape and storage parameters straight can be difficult. The BLAS
- documentation generally makes a distinction between the concpetual "matrix" and the physical
- "array". However there are a number of places where this becomes fuzzy because of the overall
- bias towards FORTRAN's column major storage. The confusion is made worse by style differences
- between the level 2 and level 3 functions. It is amplified further by the explicit choice of row
- or column major storage in the C interface.
- The storage order does not affect the actual computation that is performed. That is, it does not
- affect the results other than where they appear in memory. It does affect the values passed
- for so-called "leading dimension" parameters, such as lda in sgemv. These are always the major
- stride in storage, allowing operations on rectangular subsets of larger matrices. For row major
- storage this is the number of columns in the parent matrix, and for column major storage this is
- the number of rows in the parent matrix.
- For the level 2 functions, which deal with only a single matrix, the matrix shape parameters are
- always M and N. These are the logical shape of the matrix, M rows by N columns. The transpose
- parameter, such as transA in sgemv, defines whether the regular matrix or its transpose is used
- in the operation. This affects the implicit length of the input and output vectors. For example,
- if the regular matrix A is used in sgemv, the input vector X has length N, the number of columns
- of A, and the output vector Y has length M, the number of rows of A. The length of the input and
- output vectors is not affected by the storage order of the matrix.
- The level 3 functions deal with 2 input matrices and one output matrix, the matrix shape parameters
- are M, N, and K. The logical shape of the output matrix is always M by N, while K is the common
- dimension of the input matrices. Like level 2, the transpose parameters, such as transA and transB
- in sgemm, define whether the regular input or its transpose is used in the operation. However
- unlike level 2, in level 3 the transpose parameters affect the implicit shape of the input matrix.
- Consider sgemm, which computes "C = (alpha * A * B) + (beta * C)", where A and B might be regular
- or transposed. The logical shape of C is always M rows by N columns. The physical shape depends
- on the storage order parameter. Using column major storage the declaration of C (the array) in C
- (the language) would be something like "float C[N][M]". The logical shape of A without transposition
- is M by K, and B is K by N. The one storage order parameter affects all three matrices.
- For those readers still wondering about the style differences between level 2 and level 3, they
- involve whether the input or output shapes are explicit. For level 2, the input matrix shape is
- always M by N. The input and output vector lengths are implicit and vary according to the
- transpose parameter. For level 3, the output matrix shape is always M by N. The input matrix
- shapes are implicit and vary according to the transpose parameters.
- =================================================================================================
- }
- { ========================================================================================================================== }
- {
- Modified for use with Free Pascal
- Version 200
- Please report any bugs to <[email protected]>
- }
- {$mode macpas}
- {$packenum 1}
- {$macro on}
- {$inline on}
- {$CALLING MWPASCAL}
- unit vBLAS;
- interface
- {$setc UNIVERSAL_INTERFACES_VERSION := $0342}
- {$setc GAP_INTERFACES_VERSION := $0200}
- {$ifc not defined USE_CFSTR_CONSTANT_MACROS}
- {$setc USE_CFSTR_CONSTANT_MACROS := TRUE}
- {$endc}
- {$ifc defined CPUPOWERPC and defined CPUI386}
- {$error Conflicting initial definitions for CPUPOWERPC and CPUI386}
- {$endc}
- {$ifc defined FPC_BIG_ENDIAN and defined FPC_LITTLE_ENDIAN}
- {$error Conflicting initial definitions for FPC_BIG_ENDIAN and FPC_LITTLE_ENDIAN}
- {$endc}
- {$ifc not defined __ppc__ and defined CPUPOWERPC}
- {$setc __ppc__ := 1}
- {$elsec}
- {$setc __ppc__ := 0}
- {$endc}
- {$ifc not defined __i386__ and defined CPUI386}
- {$setc __i386__ := 1}
- {$elsec}
- {$setc __i386__ := 0}
- {$endc}
- {$ifc defined __ppc__ and __ppc__ and defined __i386__ and __i386__}
- {$error Conflicting definitions for __ppc__ and __i386__}
- {$endc}
- {$ifc defined __ppc__ and __ppc__}
- {$setc TARGET_CPU_PPC := TRUE}
- {$setc TARGET_CPU_X86 := FALSE}
- {$elifc defined __i386__ and __i386__}
- {$setc TARGET_CPU_PPC := FALSE}
- {$setc TARGET_CPU_X86 := TRUE}
- {$elsec}
- {$error Neither __ppc__ nor __i386__ is defined.}
- {$endc}
- {$setc TARGET_CPU_PPC_64 := FALSE}
- {$ifc defined FPC_BIG_ENDIAN}
- {$setc TARGET_RT_BIG_ENDIAN := TRUE}
- {$setc TARGET_RT_LITTLE_ENDIAN := FALSE}
- {$elifc defined FPC_LITTLE_ENDIAN}
- {$setc TARGET_RT_BIG_ENDIAN := FALSE}
- {$setc TARGET_RT_LITTLE_ENDIAN := TRUE}
- {$elsec}
- {$error Neither FPC_BIG_ENDIAN nor FPC_LITTLE_ENDIAN are defined.}
- {$endc}
- {$setc ACCESSOR_CALLS_ARE_FUNCTIONS := TRUE}
- {$setc CALL_NOT_IN_CARBON := FALSE}
- {$setc OLDROUTINENAMES := FALSE}
- {$setc OPAQUE_TOOLBOX_STRUCTS := TRUE}
- {$setc OPAQUE_UPP_TYPES := TRUE}
- {$setc OTCARBONAPPLICATION := TRUE}
- {$setc OTKERNEL := FALSE}
- {$setc PM_USE_SESSION_APIS := TRUE}
- {$setc TARGET_API_MAC_CARBON := TRUE}
- {$setc TARGET_API_MAC_OS8 := FALSE}
- {$setc TARGET_API_MAC_OSX := TRUE}
- {$setc TARGET_CARBON := TRUE}
- {$setc TARGET_CPU_68K := FALSE}
- {$setc TARGET_CPU_MIPS := FALSE}
- {$setc TARGET_CPU_SPARC := FALSE}
- {$setc TARGET_OS_MAC := TRUE}
- {$setc TARGET_OS_UNIX := FALSE}
- {$setc TARGET_OS_WIN32 := FALSE}
- {$setc TARGET_RT_MAC_68881 := FALSE}
- {$setc TARGET_RT_MAC_CFM := FALSE}
- {$setc TARGET_RT_MAC_MACHO := TRUE}
- {$setc TYPED_FUNCTION_POINTERS := TRUE}
- {$setc TYPE_BOOL := FALSE}
- {$setc TYPE_EXTENDED := FALSE}
- {$setc TYPE_LONGLONG := TRUE}
- uses MacTypes,ConditionalMacros;
- {$ALIGN POWER}
- {
- ==========================================================================================================================
- Types and constants
- ===================
- }
- type
- CBLAS_ORDER = SInt32;
- const
- CblasRowMajor = 101;
- CblasColMajor = 102;
- type
- CBLAS_TRANSPOSE = SInt32;
- const
- CblasNoTrans = 111;
- CblasTrans = 112;
- CblasConjTrans = 113;
- type
- CBLAS_UPLO = SInt32;
- const
- CblasUpper = 121;
- CblasLower = 122;
- type
- CBLAS_DIAG = SInt32;
- const
- CblasNonUnit = 131;
- CblasUnit = 132;
- type
- CBLAS_SIDE = SInt32;
- const
- CblasLeft = 141;
- CblasRight = 142;
- {
- ------------------------------------------------------------------------------------------------------------------
- IsAlignedCount - True if an SInt16 is positive and a multiple of 4. Negative strides are considered unaligned.
- IsAlignedAddr - True if an address is a multiple of 16.
- }
- {
- ==========================================================================================================================
- ==========================================================================================================================
- Legacy BLAS Functions
- ==========================================================================================================================
- ==========================================================================================================================
- }
- {
- ==========================================================================================================================
- Level 1 Single Precision Functions
- ==================================
- }
- {
- * cblas_sdot()
- *
- * Availability:
- * Non-Carbon CFM: in vecLib 1.0.2 and later
- * CarbonLib: not in Carbon, but vecLib is compatible with Carbon
- * Mac OS X: in version 10.0 and later
- }
- function cblas_sdot(N: SInt32; (*const*) var X: Single; incX: SInt32; (*const*) var Y: Single; incY: SInt32): Single; external name '_cblas_sdot';
- {
- * cblas_snrm2()
- *
- * Availability:
- * Non-Carbon CFM: in vecLib 1.0.2 and later
- * CarbonLib: not in Carbon, but vecLib is compatible with Carbon
- * Mac OS X: in version 10.0 and later
- }
- function cblas_snrm2(N: SInt32; (*const*) var X: Single; incX: SInt32): Single; external name '_cblas_snrm2';
- {
- * cblas_sasum()
- *
- * Availability:
- * Non-Carbon CFM: in vecLib 1.0.2 and later
- * CarbonLib: not in Carbon, but vecLib is compatible with Carbon
- * Mac OS X: in version 10.0 and later
- }
- function cblas_sasum(N: SInt32; (*const*) var X: Single; incX: SInt32): Single; external name '_cblas_sasum';
- {
- * cblas_isamax()
- *
- * Availability:
- * Non-Carbon CFM: in vecLib 1.0.2 and later
- * CarbonLib: not in Carbon, but vecLib is compatible with Carbon
- * Mac OS X: in version 10.0 and later
- }
- function cblas_isamax(N: SInt32; (*const*) var X: Single; incX: SInt32): SInt32; external name '_cblas_isamax';
- {
- * cblas_sswap()
- *
- * Availability:
- * Non-Carbon CFM: in vecLib 1.0.2 and later
- * CarbonLib: not in Carbon, but vecLib is compatible with Carbon
- * Mac OS X: in version 10.0 and later
- }
- procedure cblas_sswap(N: SInt32; var X: Single; incX: SInt32; var Y: Single; incY: SInt32); external name '_cblas_sswap';
- {
- * cblas_scopy()
- *
- * Availability:
- * Non-Carbon CFM: in vecLib 1.0.2 and later
- * CarbonLib: not in Carbon, but vecLib is compatible with Carbon
- * Mac OS X: in version 10.0 and later
- }
- procedure cblas_scopy(N: SInt32; (*const*) var X: Single; incX: SInt32; var Y: Single; incY: SInt32); external name '_cblas_scopy';
- {
- * cblas_saxpy()
- *
- * Availability:
- * Non-Carbon CFM: in vecLib 1.0.2 and later
- * CarbonLib: not in Carbon, but vecLib is compatible with Carbon
- * Mac OS X: in version 10.0 and later
- }
- procedure cblas_saxpy(N: SInt32; alpha: Single; (*const*) var X: Single; incX: SInt32; var Y: Single; incY: SInt32); external name '_cblas_saxpy';
- {
- * cblas_srot()
- *
- * Availability:
- * Non-Carbon CFM: in vecLib 1.0.2 and later
- * CarbonLib: not in Carbon, but vecLib is compatible with Carbon
- * Mac OS X: in version 10.0 and later
- }
- procedure cblas_srot(N: SInt32; var X: Single; incX: SInt32; var Y: Single; incY: SInt32; c: Single; s: Single); external name '_cblas_srot';
- {
- * cblas_sscal()
- *
- * Availability:
- * Non-Carbon CFM: in vecLib 1.0.2 and later
- * CarbonLib: not in Carbon, but vecLib is compatible with Carbon
- * Mac OS X: in version 10.0 and later
- }
- procedure cblas_sscal(N: SInt32; alpha: Single; var X: Single; incX: SInt32); external name '_cblas_sscal';
- {
- ==========================================================================================================================
- Level 1 Double Precision Functions
- ==================================
- }
- { *** TBD *** }
- {
- ==========================================================================================================================
- Level 1 Complex Single Precision Functions
- ==========================================
- }
- { *** TBD *** }
- {
- ==========================================================================================================================
- Level 2 Single Precision Functions
- ==================================
- }
- {
- * cblas_sgemv()
- *
- * Availability:
- * Non-Carbon CFM: in vecLib 1.0.2 and later
- * CarbonLib: not in Carbon, but vecLib is compatible with Carbon
- * Mac OS X: in version 10.0 and later
- }
- procedure cblas_sgemv(order: CBLAS_ORDER; transA: CBLAS_TRANSPOSE; M: SInt32; N: SInt32; alpha: Single; (*const*) var A: Single; lda: SInt32; (*const*) var X: Single; incX: SInt32; beta: Single; var Y: Single; incY: SInt32); external name '_cblas_sgemv';
- {
- ==========================================================================================================================
- Level 2 Double Precision Functions
- ==================================
- }
- { *** TBD *** }
- {
- ==========================================================================================================================
- Level 2 Complex Single Precision Functions
- ==========================================
- }
- { *** TBD *** }
- {
- ==========================================================================================================================
- Level 3 Single Precision Functions
- ==================================
- }
- {
- * cblas_sgemm()
- *
- * Availability:
- * Non-Carbon CFM: in vecLib 1.0.2 and later
- * CarbonLib: not in Carbon, but vecLib is compatible with Carbon
- * Mac OS X: in version 10.0 and later
- }
- procedure cblas_sgemm(order: CBLAS_ORDER; transA: CBLAS_TRANSPOSE; transB: CBLAS_TRANSPOSE; M: SInt32; N: SInt32; K: SInt32; alpha: Single; (*const*) var A: Single; lda: SInt32; (*const*) var B: Single; ldb: SInt32; beta: Single; var C: Single; ldc: SInt32); external name '_cblas_sgemm';
- {
- ==========================================================================================================================
- Level 3 Double Precision Functions
- ==================================
- }
- { *** TBD *** }
- {
- ==========================================================================================================================
- Level 3 Complex Single Precision Functions
- ==========================================
- }
- { *** TBD *** }
- {
- ==========================================================================================================================
- ==========================================================================================================================
- Latest Standard BLAS Functions
- ==========================================================================================================================
- ==========================================================================================================================
- }
- { *** TBD *** }
- {
- ==========================================================================================================================
- ==========================================================================================================================
- Additional Functions from Apple
- ==========================================================================================================================
- ==========================================================================================================================
- }
- {
- -------------------------------------------------------------------------------------------------
- These routines provide optimized, AltiVec-only support for common small matrix multiplications.
- They do not check for the availability of AltiVec instructions or parameter errors. They just do
- the multiplication as fast as possible. Matrices are presumed to use row major storage. Because
- these are all square, column major matrices can be multiplied by simply reversing the parameters.
- }
- {
- ==========================================================================================================================
- Error handling
- ==============
- }
- {
- -------------------------------------------------------------------------------------------------
- The BLAS standard requires that parameter errors be reported and cause the program to terminate.
- The default behavior for the Mac OS implementation of the BLAS is to print a message in English
- to stdout using printf and call exit with EXIT_FAILURE as the status. If this is adequate, then
- you need do nothing more or worry about error handling.
- The BLAS standard also mentions a function, cblas_xerbla, suggesting that a program provide its
- own implementation to override the default error handling. This will not work in the shared
- library environment of Mac OS 9. Instead the Mac OS implementation provides a means to install
- an error handler. There can only be one active error handler, installing a new one causes any
- previous handler to be forgotten. Passing a null function pointer installs the default handler.
- The default handler is automatically installed at startup and implements the default behavior
- defined above.
- An error handler may return, it need not abort the program. If the error handler returns, the
- BLAS routine also returns immediately without performing any processing. Level 1 functions that
- return a numeric value return zero if the error handler returns.
- }
- type
- {$ifc TYPED_FUNCTION_POINTERS}
- BLASParamErrorProc = procedure(funcName: ConstCStringPtr; paramName: ConstCStringPtr; (*const*) var paramPos: SInt32; (*const*) var paramValue: SInt32);
- {$elsec}
- BLASParamErrorProc = ProcPtr;
- {$endc}
- {
- * SetBLASParamErrorProc()
- *
- * Availability:
- * Non-Carbon CFM: in vecLib 1.0.2 and later
- * CarbonLib: not in Carbon, but vecLib is compatible with Carbon
- * Mac OS X: in version 10.0 and later
- }
- procedure SetBLASParamErrorProc(ErrorProc: BLASParamErrorProc); external name '_SetBLASParamErrorProc';
- { ========================================================================================================================== }
- {$ALIGN MAC68K}
- end.
|