00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018 #ifndef CHI_CFN_H
00019 #define CHI_CFN_H
00020
00021 #include <cudyn/type.h>
00022 #ifdef CUCONF_HAVE_LIBFFI_FFI_H
00023 # include <libffi/ffi.h>
00024 #else
00025 # include <ffi.h>
00026 #endif
00027 #include <atomic_ops.h>
00028
00029 CU_BEGIN_DECLARATIONS
00030
00031
00032
00033
00034
00035 struct cudyn_proto
00036 {
00037 cu_inherit (cuoo_type);
00038
00039 cudyn_tuptype_t arg_type;
00040 cuoo_type_t res_type;
00041
00042
00043 ffi_cif cif;
00044
00045 };
00046 #define CUDYN_PROTO_KEY_SIZE \
00047 (offsetof(struct cudyn_proto, cif) - CUOO_HCOBJ_SHIFT)
00048
00049 extern cuoo_type_t cudynP_proto_type;
00050
00051
00052 CU_SINLINE cuoo_type_t cudyn_proto_type()
00053 { return cudynP_proto_type; }
00054
00055
00056 CU_SINLINE cuoo_type_t cudyn_proto_to_type(cudyn_proto_t proto)
00057 { return cu_to(cuoo_type, proto); }
00058
00059
00060 CU_SINLINE cudyn_proto_t cudyn_proto_from_type(cuoo_type_t t)
00061 { return cu_from(cudyn_proto, cuoo_type, t); }
00062
00063
00064 CU_SINLINE cu_bool_t cudyn_is_fn(cuex_t ex)
00065 { return cuex_meta(ex) == cuoo_type_to_meta(cudyn_proto_type()); }
00066
00067
00068 cudyn_proto_t cudyn_proto_by_tuptype(cudyn_tuptype_t arg_type,
00069 cuoo_type_t res_type);
00070
00071
00072
00073
00074 cudyn_proto_t cudyn_proto(cu_rank_t r, ...);
00075
00076
00077 CU_SINLINE cudyn_proto_t
00078 cudyn_proto_0(cuoo_type_t tR)
00079 { return cudyn_proto(0, tR); }
00080
00081
00082 CU_SINLINE cudyn_proto_t
00083 cudyn_proto_1(cuoo_type_t t0, cuoo_type_t tR)
00084 { return cudyn_proto(1, t0, tR); }
00085
00086
00087 CU_SINLINE cudyn_proto_t
00088 cudyn_proto_2(cuoo_type_t t0, cuoo_type_t t1, cuoo_type_t tR)
00089 { return cudyn_proto(2, t0, t1, tR); }
00090
00091
00092 CU_SINLINE cudyn_proto_t
00093 cudyn_proto_3(cuoo_type_t t0, cuoo_type_t t1, cuoo_type_t t2,
00094 cuoo_type_t tR)
00095 { return cudyn_proto(3, t0, t1, t2, tR); }
00096
00097
00098 CU_SINLINE cudyn_proto_t
00099 cudyn_proto_4(cuoo_type_t t0, cuoo_type_t t1, cuoo_type_t t2,
00100 cuoo_type_t t3, cuoo_type_t tR)
00101 { return cudyn_proto(4, t0, t1, t2, t3, tR); }
00102
00103
00104 CU_SINLINE size_t
00105 cudyn_proto_r(cudyn_proto_t proto)
00106 { return cudyn_tuptype_tcomp_cnt(proto->arg_type); }
00107
00108
00109
00110
00111
00112
00113
00114 cuex_t cudyn_proto_apply_fn(cudyn_proto_t proto, cu_fnptr_t fn,
00115 cuex_t *arg_arr);
00116
00117
00118
00119
00120 CU_SINLINE cuoo_type_t
00121 cudyn_proto_arg_type_at(cudyn_proto_t proto, cu_rank_t i)
00122 { return cudyn_tuptype_at(proto->arg_type, i); }
00123
00124
00125 CU_SINLINE cuoo_type_t cudyn_proto_res_type(cudyn_proto_t proto)
00126 { return proto->res_type; }
00127
00128
00129 CU_END_DECLARATIONS
00130 #endif