flat assembler
Message board for the users of flat assembler.

Index > High Level Languages > [SOLVED] - FASM and Intel MKL (Math Kernel Library): how to?

Author
Thread Post new topic Reply to topic
ctl3d32



Joined: 30 Dec 2009
Posts: 206
Location: Brazil
ctl3d32 03 Jul 2011, 00:50
Hi folks,

How should i declare my arrays and matrixes in FASM so that i can call Intel MKL (http://software.intel.com/en-us/articles/intel-mkl/)?
Should i pass the first byte of the declared array as reference? Or it expects an structure?

P.S.: Intel MKL -> Standard APIs in C and Fortran.

Thanks,
ctl3d32

Example:
Code:
.data
array dq 1.0,3.5,6.9,-1.0
result dq 4 dup (?)
scalar dq 3

.code
invoke MKL_MultiplyArrayByScalar, array, scalar, result
    

or
Code:
.data
struct ARRAY
  num_elements dd ?
  array dd ?
ends

array_elem dq 1.0,3.5,6.9,-1.0
result_array dq 4 dup (?)

result ARRAY 4, result_array
array ARRAY 4,array_elem

scalar dq 3

.code
invoke MKL_MultiplyArrayByScalar, array, scalar, result
    


Last edited by ctl3d32 on 04 Jul 2011, 00:32; edited 1 time in total
Post 03 Jul 2011, 00:50
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 03 Jul 2011, 01:17
Well, can't find anything so I'll have to tell you what to do:

It looks more reasonable your second option because this function seems to lack of "sizeOfArray" parameter. Still, what you should actually do is to check the header files to see what the types of each parameter are and then look up for the involved structures and port them to fasm (i.e., despite I've told you your second option is more reasonable it is very likely to be ALSO wrong anyway).
Post 03 Jul 2011, 01:17
View user's profile Send private message Reply with quote
ctl3d32



Joined: 30 Dec 2009
Posts: 206
Location: Brazil
ctl3d32 03 Jul 2011, 01:31
Problem is: Where do i find these definitions? Which header files have these informations?
Post 03 Jul 2011, 01:31
View user's profile Send private message Reply with quote
LocoDelAssembly
Your code has a bug


Joined: 06 May 2005
Posts: 4624
Location: Argentina
LocoDelAssembly 03 Jul 2011, 05:17
The .h files, if you installed the package you should have those (I think, I didn't and I won't go through all the steps Intel requires to download this stuff).

If "MKL_MultiplyArrayByScalar" exists, then you could use the Windows' search feature and in the "A word or phrase in the file" box (not "All or part of file name") search for that function. Repeat this step for the parameter types.
Post 03 Jul 2011, 05:17
View user's profile Send private message Reply with quote
idle



Joined: 06 Jan 2011
Posts: 440
Location: Ukraine
idle 03 Jul 2011, 07:07
in alike cases i use TotalCmd:


Description:
Filesize: 61.32 KB
Viewed: 14845 Time(s)

tc lister.png


Description:
Filesize: 23.72 KB
Viewed: 14845 Time(s)

searching in tc.png


Post 03 Jul 2011, 07:07
View user's profile Send private message Reply with quote
ctl3d32



Joined: 30 Dec 2009
Posts: 206
Location: Brazil
ctl3d32 03 Jul 2011, 21:11
Does anyone have an idea, because i don't.
Post 03 Jul 2011, 21:11
View user's profile Send private message Reply with quote
ctl3d32



Joined: 30 Dec 2009
Posts: 206
Location: Brazil
ctl3d32 03 Jul 2011, 22:30
I've made a .dll in Pelles C and it heappens that arrays are passed as reference to the first element. No structure at all. I've imported it with fasm and it worked perfectly. I guess i'm doing something wrong with the MKL...
Post 03 Jul 2011, 22:30
View user's profile Send private message Reply with quote
ctl3d32



Joined: 30 Dec 2009
Posts: 206
Location: Brazil
ctl3d32 04 Jul 2011, 00:31
Got It Folks! Here is the solution!

These are the types in mkl_types.h:
Code:
!*******************************************************************************
!  Content:
!      Intel(R) Math Kernel Library (MKL) types definition
!******************************************************************************/

#ifndef _MKL_TYPES_H_
#define _MKL_TYPES_H_

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/* Complex type (single precision). */
#ifndef MKL_Complex8
typedef
struct _MKL_Complex8 {
    float    real;
    float    imag;
} MKL_Complex8;
#endif

/* Complex type (double precision). */
#ifndef MKL_Complex16
typedef
struct _MKL_Complex16 {
    double    real;
    double    imag;
} MKL_Complex16;
#endif

typedef
struct {
    int       MajorVersion;
    int       MinorVersion;
    int       UpdateVersion;
    char *    ProductStatus;
    char *    Build;
    char *    Processor;
    char *    Platform;
} MKLVersion;

#if (!defined(__INTEL_COMPILER)) & defined(_MSC_VER)
    #define MKL_INT64 __int64
#else
    #define MKL_INT64 long long int
#endif

#ifdef MKL_ILP64
  #define MKL_INT MKL_INT64
  #define MKL_LONG MKL_INT64
#else
  #define MKL_INT int
  #define MKL_LONG long int
#endif

/********************************************/

/** MKL threading stuff **/
/** MKL Domains codes   **/
#define MKL_ALL  0
#define MKL_BLAS 1
#define MKL_FFT  2
#define MKL_VML  3
/**************************/

#ifdef __cplusplus
}
#endif /* __cplusplus */

#endif /* _MKL_TYPES_H_ */
    


Other types in mkl_lapack.h
Code:
!*******************************************************************************
!  Content:
!      Intel(R) Math Kernel Library (MKL) interface for LAPACK routines
!******************************************************************************/

#ifndef _MKL_LAPACK_H_
#define _MKL_LAPACK_H_

#include "mkl_types.h"

#ifdef __cplusplus
extern "C" {
#endif /* __cplusplus */

/* LAPACK specific types */

typedef MKL_INT (*MKL_C_SELECT_FUNCTION_1) ( MKL_Complex8* );
typedef MKL_INT (*MKL_C_SELECT_FUNCTION_2) ( MKL_Complex8*, MKL_Complex8* );
typedef MKL_INT (*MKL_D_SELECT_FUNCTION_2) ( double*, double* );
typedef MKL_INT (*MKL_D_SELECT_FUNCTION_3) ( double*, double*, double* );
typedef MKL_INT (*MKL_S_SELECT_FUNCTION_2) ( float*, float* );
typedef MKL_INT (*MKL_S_SELECT_FUNCTION_3) ( float*, float*, float* );
typedef MKL_INT (*MKL_Z_SELECT_FUNCTION_1) ( MKL_Complex16* );
typedef MKL_INT (*MKL_Z_SELECT_FUNCTION_2) ( MKL_Complex16*, MKL_Complex16* );
    


Code:
/* LAPACK 3.2 routines */

void sgetrf( const MKL_INT* m, const MKL_INT* n, float* a, const MKL_INT* lda,
             MKL_INT* ipiv, MKL_INT* info );

void sgetrs( const char* trans, const MKL_INT* n, const MKL_INT* nrhs,
             const float* a, const MKL_INT* lda, const MKL_INT* ipiv, float* b,
             const MKL_INT* ldb, MKL_INT* info );
    


This is my fasm code:
Code:
; OBJECTIVE: Solve Ax=b. Find x!!! b will be overwritten to hold the solution.

; OBS.: Matrixes are stored in column-major order. If a = [-1.0 3.2; 2.0 -1.5], it shoul be stored as a = [-1.0 2.0; 3.2 -1.5].

;void sgetrf( const MKL_INT* m, const MKL_INT* n, float* a, const MKL_INT* lda,
;             MKL_INT* ipiv, MKL_INT* info );

;void sgetrs( const char* trans, const MKL_INT* n, const MKL_INT* nrhs,
;             const float* a, const MKL_INT* lda, const MKL_INT* ipiv, float* b,
;             const MKL_INT* ldb, MKL_INT* info );

format PE GUI 4.0
entry start

include 'win32a.inc'

section '.text' code readable executable

  start:

        invoke  GetModuleHandle,0
        mov     [hInstance],eax
        cinvoke mkl_lapack_sgetrf,m,n,a,lda,ipvi,info
        cinvoke mkl_lapack_sgetrs,trans,n,nrhs,a,lda,ipvi,b,ldb,info

  exit:
        invoke  ExitProcess,0


section '.bss' readable writeable

  hInstance dd ?

section '.data' data readable writeable

  trans db 'N',0
  m     dd 2
  n     dd 2
  nrhs  dd 1
  a     dd -1.0, 2.0,\
            3.2,-1.5
  lda   dd 2
  ipvi  dd 2 dup (?)
  b     dd 1.5,\
           2.4
  ldb   dd 2
  info  dd ?


section '.idata' import data readable writeable

  library kernel32,'KERNEL32.DLL',\
          user32,'USER32.DLL',\
          gdi32,'GDI32.DLL',\
          mkl,'mkl_core.dll'

  include 'api\kernel32.inc'
  include 'api\user32.inc'
  include 'api\gdi32.inc'

  import mkl,\
         mkl_lapack_sgetrs,'mkl_lapack_sgetrs',\
         mkl_lapack_sgetrf,'mkl_lapack_sgetrf_local'
    
Post 04 Jul 2011, 00:31
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2025, Tomasz Grysztar. Also on GitHub, YouTube.

Website powered by rwasa.