Beispiel #1
0
LIBXSTREAM_TARGET(mic) int libxstream_set_value(libxstream_argument& arg, const void* data)
{
  if (0 != arg.dims || 0 != (libxstream_argument::kind_output & arg.kind)) { // by-pointer
    *reinterpret_cast<const void**>(&arg) = data;
    LIBXSTREAM_ASSERT(libxstream_get_value(arg).const_pointer == data);
  }
  else { // by-value: copy from the given pointer
    size_t typesize = 0 != arg.dims ? 1 : *arg.shape;
    if (LIBXSTREAM_TYPE_VOID != arg.type) {
      LIBXSTREAM_CHECK_CALL(libxstream_get_typesize(arg.type, &typesize));
    }

    if (data) {
      const char *const src = static_cast<const char*>(data);
      for (size_t i = 0; i < typesize; ++i) arg.data.self[i] = src[i];
    }
    else {
      for (size_t i = 0; i < typesize; ++i) arg.data.self[i] = 0;
    }

    // allows to promote smaller types to pointer-size
    for (size_t i = typesize; i < sizeof(void*); ++i) arg.data.self[i] = 0;
  }

  return LIBXSTREAM_ERROR_NONE;
}
Beispiel #2
0
int libxstream_construct(libxstream_argument arguments[], size_t arg, libxstream_argument::kind_type kind, const void* value, libxstream_type type, size_t dims, const size_t shape[])
{
  size_t typesize = 0;
  const bool weak_candidate = LIBXSTREAM_TYPE_VOID == type || (LIBXSTREAM_ERROR_NONE == libxstream_get_typesize(type, &typesize) && 1 == typesize);
  LIBXSTREAM_CHECK_CONDITION((((libxstream_argument::kind_invalid == kind || libxstream_argument::kind_inout == kind) && LIBXSTREAM_TYPE_INVALID == type) || LIBXSTREAM_TYPE_INVALID > type)
    && ((0 == dims && 0 == shape) || (0 == dims && 0 != shape && weak_candidate) || (0 < dims))
    && (LIBXSTREAM_MAX_NDIMS) >= dims);

  LIBXSTREAM_ASSERT((LIBXSTREAM_MAX_NARGS) >= arg);
  libxstream_argument& argument = arguments[arg];

#if defined(LIBXSTREAM_DEBUG)
  memset(argument.data.self, 0, sizeof(libxstream_argument)); // avoid false pos. with mem. analysis
#endif
#if defined(LIBXSTREAM_PRINT)
  static const char *const context[] = { "", "input", "output", "inout" };
#endif
  argument.kind = kind;
  argument.dims = dims;

  if (shape) {
    if (0 < dims || !weak_candidate) {
#if defined(LIBXSTREAM_PRINT)
      if (0 == dims && !weak_candidate) {
        LIBXSTREAM_PRINT_WARN("libxstream_fn_%s: signature=0x%llx arg=%lu is strong-typed (ignored shape)!",
          context[kind], reinterpret_cast<unsigned long long>(arguments), static_cast<unsigned long>(arg));
      }
#endif
      argument.type = type;
    }
    else { // 0 == dims && weak_candidate
      argument.type = LIBXSTREAM_TYPE_VOID;
      LIBXSTREAM_CHECK_CONDITION(sizeof(libxstream_argument::data_union) >= *shape);
      argument.shape[0] = shape[0];
    }

    LIBXSTREAM_PRAGMA_LOOP_COUNT(0, LIBXSTREAM_MAX_NDIMS, 2)
    for (size_t i = 0; i < dims; ++i) argument.shape[i] = shape[i];
  }
  else {
#if defined(LIBXSTREAM_PRINT)
    if (0 < dims && 0 == shape) {