static int opt_set(void *opts, const struct opt_def *def, const char **val, struct region *region, uint32_t errcode, uint32_t field_no) { int64_t ival; uint64_t uval; char *errmsg = tt_static_buf(); double dval; uint32_t str_len; const char *str; char *ptr; char *opt = ((char *) opts) + def->offset; switch (def->type) { case OPT_BOOL: if (mp_typeof(**val) != MP_BOOL) goto type_mismatch_err; store_bool(opt, mp_decode_bool(val)); break; case OPT_UINT32: if (mp_typeof(**val) != MP_UINT) goto type_mismatch_err; uval = mp_decode_uint(val); if (uval > UINT32_MAX) goto type_mismatch_err; store_u32(opt, uval); break; case OPT_INT64: if (mp_read_int64(val, &ival) != 0) goto type_mismatch_err; store_u64(opt, ival); break; case OPT_FLOAT: if (mp_read_double(val, &dval) != 0) goto type_mismatch_err; store_double(opt, dval); break; case OPT_STR: if (mp_typeof(**val) != MP_STR) goto type_mismatch_err; str = mp_decode_str(val, &str_len); str_len = MIN(str_len, def->len - 1); memcpy(opt, str, str_len); opt[str_len] = '\0'; break; case OPT_STRPTR: if (mp_typeof(**val) != MP_STR) goto type_mismatch_err; str = mp_decode_str(val, &str_len); if (str_len > 0) { ptr = (char *) region_alloc(region, str_len + 1); if (ptr == NULL) { diag_set(OutOfMemory, str_len + 1, "region", "opt string"); return -1; } memcpy(ptr, str, str_len); ptr[str_len] = '\0'; assert (strlen(ptr) == str_len); } else { ptr = NULL; } *(const char **)opt = ptr; break; case OPT_ENUM: if (mp_typeof(**val) != MP_STR) goto type_mismatch_err; str = mp_decode_str(val, &str_len); if (def->to_enum == NULL) { ival = strnindex(def->enum_strs, str, str_len, def->enum_max); } else { ival = def->to_enum(str, str_len); } switch(def->enum_size) { case sizeof(uint8_t): store_u8(opt, (uint8_t)ival); break; case sizeof(uint16_t): store_u16(opt, (uint16_t)ival); break; case sizeof(uint32_t): store_u32(opt, (uint32_t)ival); break; case sizeof(uint64_t): store_u64(opt, (uint64_t)ival); break; default: unreachable(); }; break; case OPT_ARRAY: if (mp_typeof(**val) != MP_ARRAY) goto type_mismatch_err; ival = mp_decode_array(val); assert(def->to_array != NULL); if (def->to_array(val, ival, opt, errcode, field_no) != 0) return -1; break; case OPT_LEGACY: mp_next(val); break; default: unreachable(); } return 0; type_mismatch_err: snprintf(errmsg, TT_STATIC_BUF_LEN, "'%s' must be %s", def->name, opt_type_strs[def->type]); diag_set(ClientError, errcode, field_no, errmsg); return -1; }
vx_kernel vxAddTilingKernel(vx_context c, vx_char name[VX_MAX_KERNEL_NAME], vx_enum enumeration, vx_tiling_kernel_f func_ptr, vx_uint32 num_params, vx_kernel_input_validate_f input, vx_kernel_output_validate_f output) { vx_context_t *context = (vx_context_t *)c; vx_kernel kernel = 0; vx_uint32 t = 0; vx_size index = 0; vx_target_t *target = NULL; vx_char targetName[VX_MAX_TARGET_NAME]; if (vxIsValidContext(context) == vx_false_e) { VX_PRINT(VX_ZONE_ERROR, "Invalid Context\n"); return (vx_kernel)NULL; } if (func_ptr == NULL || input == NULL || output == NULL || num_params > VX_INT_MAX_PARAMS || num_params == 0 || name == NULL || strncmp(name, "", VX_MAX_KERNEL_NAME) == 0) /* initialize and de-initialize can be NULL */ { VX_PRINT(VX_ZONE_ERROR, "Invalid Parameters!\n"); vxAddLogEntry(c, VX_ERROR_INVALID_PARAMETERS, "Invalid Parameters supplied to vxAddKernel\n"); return (vx_kernel)NULL; } /* find target to assign this to */ index = strnindex(name, ':', VX_MAX_TARGET_NAME); if (index == VX_MAX_TARGET_NAME) { strcpy(targetName,"khronos.c_model"); } else { strncpy(targetName, name, index); } VX_PRINT(VX_ZONE_KERNEL, "Deduced Name as %s\n", targetName); for (t = 0u; t < context->numTargets; t++) { target = &context->targets[t]; if (strncmp(targetName,target->name, VX_MAX_TARGET_NAME) == 0) { break; } target = NULL; } if (target && target->funcs.addtilingkernel) { kernel = target->funcs.addtilingkernel(target, name, enumeration, func_ptr, num_params, input, output); VX_PRINT(VX_ZONE_KERNEL,"Added Kernel %s to Target %s ("VX_FMT_REF")\n", name, target->name, kernel); } else { vxAddLogEntry(c, VX_ERROR_NO_RESOURCES, "No target named %s exists!\n", targetName); } return (vx_kernel)kernel; }