Skip to content

Commit

Permalink
Cleanup and restructure OpenModelica typedefs (#9108)
Browse files Browse the repository at this point in the history
- Remove `m_integer` and replace its uses with `modelica_integer`. 

  - It adds nothing more than confusion. It is the same as `modelica_integer`
 
- Remove `m_real` and replace its uses with `modelica_real`. 

  - It adds nothing more than confusion. It is the same as `modelica_real`
 
- Remove `m_boolean` and replace its uses with `modelica_boolean`. 

  - It adds nothing more than confusion. It is the same as `modelica_boolean`
 
- Remove `m_string` and replace its uses with `modelica_string`. 

  - It adds nothing more than confusion. It is the same as `modelica_string`
 
- Remove `real_array_t` and replace its uses with `real_array`. 

  - It adds nothing more than confusion. It is the same as `real_array`

  - This could also have been done the other way around. Changeing the code
    generators to generate `real_array_t` instead of `real_array`

  - A member previously named `real_array` in the union `type_desc_s._data`
    in the header `openmodelica.h` is now renamed to `r_array` to avoid
    confusion.
 
- Remove `integer_array_t` and replace its uses with `integer_array`. 

  - It adds nothing more than confusion. It is the same as `integer_array`

  - This could also have been done the other way around. Changeing the code
    generators to generate `integer_array_t` instead of `integer_array`
 
- Remove `boolean_array_t` and replace its uses with `boolean_array`. 

  - It adds nothing more than confusion. It is the same as `boolean_array`

  - This could also have been done the other way around. Changeing the code
    generators to generate `boolean_array_t` instead of `boolean_array`
 
- Remove `string_array_t` and replace its uses with `string_array`. 

  - It adds nothing more than confusion. It is the same as `string_array`

  - This could also have been done the other way around. Changeing the code
    generators to generate `string_array_t` instead of `string_array`
 
- Cleanup restructure `openmodelica_types.h`. 

  - Move things around so that they are ordered logically.

  - Removed unused macros `maxmacro` and `minmacro`.
  • Loading branch information
mahge committed Jun 16, 2022
1 parent b6fbd45 commit 7dffec6
Show file tree
Hide file tree
Showing 21 changed files with 973 additions and 983 deletions.
16 changes: 8 additions & 8 deletions OMCompiler/Compiler/runtime/Dynload.cpp
Expand Up @@ -601,10 +601,10 @@ void *type_desc_to_value(type_description *desc)
varlst, namelst, mmc_mk_icon(-1));
};
case TYPE_DESC_REAL_ARRAY: {
void *ptr = (modelica_real *) desc->data.real_array.data
+ base_array_nr_of_elements(desc->data.real_array) - 1;
return generate_array(TYPE_DESC_REAL, 1, desc->data.real_array.ndims,
desc->data.real_array.dim_size, &ptr);
void *ptr = (modelica_real *) desc->data.r_array.data
+ base_array_nr_of_elements(desc->data.r_array) - 1;
return generate_array(TYPE_DESC_REAL, 1, desc->data.r_array.ndims,
desc->data.r_array.dim_size, &ptr);
};
case TYPE_DESC_INT_ARRAY: {
void *ptr = (modelica_integer *) desc->data.int_array.data
Expand Down Expand Up @@ -767,8 +767,8 @@ static int parse_array(type_description *desc, void *arrdata, void *dimLst)
dim_size = (_index_t*) malloc(sizeof(_index_t) * dims);
switch (desc->type) {
case TYPE_DESC_REAL_ARRAY:
desc->data.real_array.ndims = dims;
desc->data.real_array.dim_size = dim_size;
desc->data.r_array.ndims = dims;
desc->data.r_array.dim_size = dim_size;
break;
case TYPE_DESC_INT_ARRAY:
desc->data.int_array.ndims = dims;
Expand All @@ -790,8 +790,8 @@ static int parse_array(type_description *desc, void *arrdata, void *dimLst)
return -1;
switch (desc->type) {
case TYPE_DESC_REAL_ARRAY:
alloc_real_array_data(&(desc->data.real_array));
data = desc->data.real_array.data;
alloc_real_array_data(&(desc->data.r_array));
data = desc->data.r_array.data;
return get_array_data(1, dims, dim_size, arrdata, TYPE_DESC_REAL, &data);
case TYPE_DESC_INT_ARRAY:
alloc_integer_array_data(&(desc->data.int_array));
Expand Down
Expand Up @@ -71,11 +71,11 @@ size_t device_array_nr_of_elements(device_array *a){
}


static inline modelica_real *real_ptrget(real_array_t *a, size_t i){
static inline modelica_real *real_ptrget(real_array *a, size_t i){
return ((modelica_real *) a->data) + i;
}

static inline modelica_integer *integer_ptrget(integer_array_t *a, size_t i){
static inline modelica_integer *integer_ptrget(integer_array *a, size_t i){
return ((modelica_integer *) a->data) + i;
}

Expand Down Expand Up @@ -300,9 +300,9 @@ void swap_and_release(base_array_t* lhs, base_array_t* rhs){
//which, right now, doesn't support overloading or the stdarg standard library.
//even though the functions have the same body here they will have different body on the OpenCL counterparts

m_real* real_array_element_addr_c99_1(real_array_t* source,int ndims,...){
modelica_real* real_array_element_addr_c99_1(real_array* source,int ndims,...){
va_list ap;
m_real* tmp;
modelica_real* tmp;

va_start(ap,ndims);
tmp = real_ptrget(source, ocl_calc_base_index_va(source, ndims, ap));
Expand All @@ -311,9 +311,9 @@ m_real* real_array_element_addr_c99_1(real_array_t* source,int ndims,...){
return tmp;
}

m_real* real_array_element_addr_c99_2(real_array_t* source,int ndims,...){
modelica_real* real_array_element_addr_c99_2(real_array* source,int ndims,...){
va_list ap;
m_real* tmp;
modelica_real* tmp;

va_start(ap,ndims);
tmp = real_ptrget(source, ocl_calc_base_index_va(source, ndims, ap));
Expand All @@ -322,9 +322,9 @@ m_real* real_array_element_addr_c99_2(real_array_t* source,int ndims,...){
return tmp;
}

m_real* real_array_element_addr_c99_3(real_array_t* source,int ndims,...){
modelica_real* real_array_element_addr_c99_3(real_array* source,int ndims,...){
va_list ap;
m_real* tmp;
modelica_real* tmp;

va_start(ap,ndims);
tmp = real_ptrget(source, ocl_calc_base_index_va(source, ndims, ap));
Expand All @@ -333,9 +333,9 @@ m_real* real_array_element_addr_c99_3(real_array_t* source,int ndims,...){
return tmp;
}

m_integer* integer_array_element_addr_c99_1(integer_array_t* source,int ndims,...){
modelica_integer* integer_array_element_addr_c99_1(integer_array* source,int ndims,...){
va_list ap;
m_integer* tmp;
modelica_integer* tmp;

va_start(ap,ndims);
tmp = integer_ptrget(source, ocl_calc_base_index_va(source, ndims, ap));
Expand All @@ -344,9 +344,9 @@ m_integer* integer_array_element_addr_c99_1(integer_array_t* source,int ndims,..
return tmp;
}

m_integer* integer_array_element_addr_c99_2(integer_array_t* source,int ndims,...){
modelica_integer* integer_array_element_addr_c99_2(integer_array* source,int ndims,...){
va_list ap;
m_integer* tmp;
modelica_integer* tmp;

va_start(ap,ndims);
tmp = integer_ptrget(source, ocl_calc_base_index_va(source, ndims, ap));
Expand All @@ -355,9 +355,9 @@ m_integer* integer_array_element_addr_c99_2(integer_array_t* source,int ndims,..
return tmp;
}

m_integer* integer_array_element_addr_c99_3(integer_array_t* source,int ndims,...){
modelica_integer* integer_array_element_addr_c99_3(integer_array* source,int ndims,...){
va_list ap;
m_integer* tmp;
modelica_integer* tmp;

va_start(ap,ndims);
tmp = integer_ptrget(source, ocl_calc_base_index_va(source, ndims, ap));
Expand Down Expand Up @@ -390,7 +390,7 @@ void print_array_info(device_real_array* arr){
}
*/

void print_array(real_array_t* arr){
void print_array(real_array* arr){
printf("\n\n");
for(int q = 1; q < arr->dim_size[0]; q++){
printf(" | %f", (*real_array_element_addr_c99_1(arr, 1, ((modelica_integer) q))));
Expand All @@ -400,7 +400,7 @@ void print_array(real_array_t* arr){

/*
void print_array(device_real_array* dev_arr){
real_array_t arr;
real_array arr;
int nr_of_elm = device_array_nr_of_elements(dev_arr);
alloc_real_array(&arr, 1, nr_of_elm);
copy_real_array_data(dev_arr, &arr);
Expand Down
Expand Up @@ -67,7 +67,7 @@

// sets the number of threads for subsequent parallel operations
// arguments are arrays of work_dim size specifying each workgroup dimension
void ocl_set_num_threads(integer_array_t global_threads_in, integer_array_t local_threads_in);
void ocl_set_num_threads(integer_array global_threads_in, integer_array local_threads_in);


// sets the number of threads for subsequent parallel operations.
Expand Down Expand Up @@ -142,17 +142,17 @@ void swap_and_release(base_array_t* lhs, base_array_t* rhs);
//which right now doesn't support overloading or the stdarg standard library.
//even though the functions have the same body here they will have different body on the OpenCL counterparts

modelica_real* real_array_element_addr_c99_1(real_array_t* source,int ndims,...);
modelica_real* real_array_element_addr_c99_1(real_array* source,int ndims,...);

modelica_real* real_array_element_addr_c99_2(real_array_t* source,int ndims,...);
modelica_real* real_array_element_addr_c99_2(real_array* source,int ndims,...);

modelica_real* real_array_element_addr_c99_3(real_array_t* source,int ndims,...);
modelica_real* real_array_element_addr_c99_3(real_array* source,int ndims,...);

modelica_integer* integer_array_element_addr_c99_1(integer_array_t* source,int ndims,...);
modelica_integer* integer_array_element_addr_c99_1(integer_array* source,int ndims,...);

modelica_integer* integer_array_element_addr_c99_2(integer_array_t* source,int ndims,...);
modelica_integer* integer_array_element_addr_c99_2(integer_array* source,int ndims,...);

modelica_integer* integer_array_element_addr_c99_3(integer_array_t* source,int ndims,...);
modelica_integer* integer_array_element_addr_c99_3(integer_array* source,int ndims,...);


//array dimension size functions. returns the size of a given dimension for device real array
Expand All @@ -172,7 +172,7 @@ void free_device_array(base_array_t* dest);
void print_array_info(device_real_array* arr);

//prints array. useful for debugging.
void print_array(real_array_t* arr);
void print_array(real_array* arr);

//ATTENTION: printing a device array means copying back and then printing. Expensive Operation.
//void print_array(device_real_array* dev_arr);
Expand Down
Expand Up @@ -486,7 +486,7 @@ void ocl_execute_kernel(cl_kernel kernel){
}


void ocl_set_num_threads(integer_array_t global_threads_in, integer_array_t local_threads_in){
void ocl_set_num_threads(integer_array global_threads_in, integer_array local_threads_in){

WORK_DIM = global_threads_in.dim_size[0];

Expand Down
Expand Up @@ -72,7 +72,7 @@ extern const char* omc_ocl_kernels_source;
extern unsigned int default_ocl_device;


extern m_integer* integer_array_element_addr_c99_1(integer_array_t* source,int ndims,...);
extern modelica_integer* integer_array_element_addr_c99_1(integer_array* source,int ndims,...);


//Reads kernels from a file
Expand Down Expand Up @@ -110,7 +110,7 @@ void ocl_execute_kernel(cl_kernel kernel);

// sets the number of threads for subsequent parallel operations
// arguments are arrays of work_dim size specifiying each workgroup dimension
void ocl_set_num_threads(integer_array_t global_threads_in, integer_array_t local_threads_in);
void ocl_set_num_threads(integer_array global_threads_in, integer_array local_threads_in);

// sets the number of threads for subsequent parallel operations.
// similar to the above function with arrays of size 1 only.
Expand Down
16 changes: 8 additions & 8 deletions OMCompiler/SimulationRuntime/c/gc/memory_pool.c
Expand Up @@ -255,27 +255,27 @@ omc_alloc_interface_t omc_alloc_interface = {
};

/* allocates n reals in the real_buffer */
m_real* real_alloc(int n)
modelica_real* real_alloc(int n)
{
return (m_real*) omc_alloc_interface.malloc_atomic(n*sizeof(m_real));
return (modelica_real*) omc_alloc_interface.malloc_atomic(n*sizeof(modelica_real));
}

/* allocates n integers in the integer_buffer */
m_integer* integer_alloc(int n)
modelica_integer* integer_alloc(int n)
{
return (m_integer*) omc_alloc_interface.malloc_atomic(n*sizeof(m_integer));
return (modelica_integer*) omc_alloc_interface.malloc_atomic(n*sizeof(modelica_integer));
}

/* allocates n strings in the string_buffer */
m_string* string_alloc(int n)
modelica_string* string_alloc(int n)
{
return (m_string*) omc_alloc_interface.malloc(n*sizeof(m_string));
return (modelica_string*) omc_alloc_interface.malloc(n*sizeof(modelica_string));
}

/* allocates n booleans in the boolean_buffer */
m_boolean* boolean_alloc(int n)
modelica_boolean* boolean_alloc(int n)
{
return (m_boolean*) omc_alloc_interface.malloc_atomic(n*sizeof(m_boolean));
return (modelica_boolean*) omc_alloc_interface.malloc_atomic(n*sizeof(modelica_boolean));
}

_index_t* size_alloc(int n)
Expand Down
8 changes: 4 additions & 4 deletions OMCompiler/SimulationRuntime/c/gc/memory_pool.h
Expand Up @@ -39,10 +39,10 @@ extern "C" {
#endif

/* Allocation functions */
extern m_real* real_alloc(int n);
extern m_integer* integer_alloc(int n);
extern m_string* string_alloc(int n);
extern m_boolean* boolean_alloc(int n);
extern modelica_real* real_alloc(int n);
extern modelica_integer* integer_alloc(int n);
extern modelica_string* string_alloc(int n);
extern modelica_boolean* boolean_alloc(int n);
extern _index_t* size_alloc(int n);
extern _index_t** index_alloc(int n);

Expand Down
8 changes: 4 additions & 4 deletions OMCompiler/SimulationRuntime/c/openmodelica.h
Expand Up @@ -127,13 +127,13 @@ struct type_desc_s {
int retval : 1;
union _data {
modelica_real real;
real_array_t real_array;
real_array r_array;
modelica_integer integer;
integer_array_t int_array;
integer_array int_array;
modelica_boolean boolean;
boolean_array_t bool_array;
boolean_array bool_array;
modelica_string string;
string_array_t string_array;
string_array string_array;
struct _tuple {
size_t elements;
struct type_desc_s *element;
Expand Down
94 changes: 42 additions & 52 deletions OMCompiler/SimulationRuntime/c/openmodelica_types.h
Expand Up @@ -39,23 +39,6 @@
extern "C" {
#endif

typedef int integer;
typedef unsigned int uinteger;
typedef double doublereal;
#define maxmacro(X,Y) X > Y ? X : Y
#define minmacro(X,Y) X > Y ? Y : X

typedef void* modelica_complex; /* currently only External objects are represented using modelica_complex.*/
typedef void* modelica_metatype; /* MetaModelica extension, added by sjoelund */
/* MetaModelica extension.
We actually store function-pointers in lists, etc...
So it needs to be void*. If we use a platform with different sizes of function-
pointers, some changes need to be done to code generation */
typedef void* modelica_fnptr;

/* When MetaModelica grammar is enabled, all strings are boxed */
typedef modelica_metatype modelica_string;

#if defined(_LP64) /* linux 64bit*/

#define MMC_SIZE_DBL 8
Expand Down Expand Up @@ -111,11 +94,44 @@ typedef int mmc_sint_t;
#define OMC_INT_FORMAT "%*ld"
#endif

typedef double m_real;
typedef mmc_sint_t m_integer;
typedef modelica_metatype m_string;
typedef signed char m_boolean;
typedef m_integer _index_t;
typedef void* modelica_complex; /* currently only External objects are represented using modelica_complex.*/
typedef void* modelica_metatype; /* MetaModelica extension, added by sjoelund */
/* MetaModelica extension.
We actually store function-pointers in lists, etc...
So it needs to be void*. If we use a platform with different sizes of function-
pointers, some changes need to be done to code generation */
typedef void* modelica_fnptr;

typedef double modelica_real;
typedef mmc_sint_t modelica_integer;
typedef signed char modelica_boolean;
/* When MetaModelica grammar is enabled, all strings are boxed */
typedef modelica_metatype modelica_string;
typedef mmc_sint_t _index_t;

#ifndef FALSE
#define FALSE 0
#endif

#ifndef TRUE
#define TRUE 1
#endif


struct base_array_s
{
int ndims;
_index_t *dim_size;
void *data;
modelica_boolean flexible;
};
typedef struct base_array_s base_array_t;

typedef base_array_t boolean_array;
typedef base_array_t real_array;
typedef base_array_t integer_array;
typedef base_array_t string_array;


/* This structure holds indexes when subscripting an array.
* ndims - number of subscripts, E.g. A[1,{2,3},:] => ndims = 3
Expand All @@ -134,39 +150,13 @@ struct index_spec_s
};
typedef struct index_spec_s index_spec_t;

struct base_array_s
{
int ndims;
_index_t *dim_size;
void *data;
m_boolean flexible;
};

typedef struct base_array_s base_array_t;

typedef base_array_t string_array_t;

typedef signed char modelica_boolean;
#ifndef FALSE
#define FALSE 0
#endif

#ifndef TRUE
#define TRUE 1
#endif

typedef base_array_t boolean_array_t;

typedef double modelica_real;
typedef base_array_t real_array_t;

typedef m_integer modelica_integer;
typedef base_array_t integer_array_t;

typedef real_array_t real_array;
typedef integer_array_t integer_array;
typedef boolean_array_t boolean_array;
typedef string_array_t string_array;
// This typedfes should be removed and their uses replaced by the corresponding data types.
typedef int integer;
typedef unsigned int uinteger;
typedef double doublereal;

#include "gc/omc_gc.h" /* for threadData_t */

Expand Down

0 comments on commit 7dffec6

Please sign in to comment.