Exemplo n.º 1
0
int multi_dgemm_type::deinit()
{
  if (m_host_data) {
    int device = -1;
    LIBXSTREAM_CHECK_CALL(libxstream_stream_device(m_stream, &device));
    LIBXSTREAM_CHECK_CALL(libxstream_fn_destroy_signature(m_signature));
    LIBXSTREAM_CHECK_CALL(libxstream_stream_destroy(m_stream));
    LIBXSTREAM_CHECK_CALL(libxstream_event_destroy(m_event));
    LIBXSTREAM_CHECK_CALL(libxstream_mem_deallocate(device, m_adata));
    LIBXSTREAM_CHECK_CALL(libxstream_mem_deallocate(device, m_bdata));
    LIBXSTREAM_CHECK_CALL(libxstream_mem_deallocate(device, m_cdata));
    LIBXSTREAM_CHECK_CALL(libxstream_mem_deallocate(device, m_idata));
    m_host_data = 0;
#if defined(LIBXSTREAM_DEBUG)
    m_max_batch = 0;
    m_signature = 0;
    m_stream = 0;
    m_event = 0;
    m_adata = 0;
    m_bdata = 0;
    m_cdata = 0;
    m_idata = 0;
#endif
  }

  return LIBXSTREAM_ERROR_NONE;
}
Exemplo n.º 2
0
int libxstream_construct(libxstream_argument* signature, size_t nargs)
{
  LIBXSTREAM_CHECK_CONDITION((0 != signature || 0 == nargs) && (LIBXSTREAM_MAX_NARGS) >= nargs);

  if (0 != signature) {
#if defined(__INTEL_COMPILER)
#   pragma loop_count min(0), max(LIBXSTREAM_MAX_NARGS), avg(LIBXSTREAM_MAX_NARGS/2)
#endif
    for (size_t i = 0; i < nargs; ++i) {
      LIBXSTREAM_CHECK_CALL(libxstream_construct(signature, i, libxstream_argument::kind_inout, 0, LIBXSTREAM_TYPE_INVALID, 0, 0));
    }
    LIBXSTREAM_CHECK_CALL(libxstream_construct(signature, nargs, libxstream_argument::kind_invalid, 0, LIBXSTREAM_TYPE_INVALID, 0, 0));
  }

  return LIBXSTREAM_ERROR_NONE;
}
Exemplo n.º 3
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;
}
Exemplo n.º 4
0
int multi_dgemm_type::init(const char* name, host_data_type& host_data, int device, size_t max_batch)
{
  LIBXSTREAM_CHECK_CALL(deinit());
  m_host_data = &host_data;
  m_max_batch = max_batch;

  const size_t max_msize = m_max_batch * m_host_data->max_matrix_size();
  LIBXSTREAM_CHECK_CALL(libxstream_stream_create(&m_stream, device, 0, name));
  LIBXSTREAM_CHECK_CALL(libxstream_mem_allocate(device, reinterpret_cast<void**>(&m_adata), sizeof(double) * max_msize, 0));
  LIBXSTREAM_CHECK_CALL(libxstream_mem_allocate(device, reinterpret_cast<void**>(&m_bdata), sizeof(double) * max_msize, 0));
  LIBXSTREAM_CHECK_CALL(libxstream_mem_allocate(device, reinterpret_cast<void**>(&m_cdata), sizeof(double) * max_msize, 0));
  LIBXSTREAM_CHECK_CALL(libxstream_mem_allocate(device, reinterpret_cast<void**>(&m_idata), sizeof(size_t) * max_batch, 0));

  return LIBXSTREAM_ERROR_NONE;
}
Exemplo n.º 5
0
int multi_dgemm_type::init(const char* name, host_data_type& host_data, int device, int demux, size_t max_batch)
{
  LIBXSTREAM_CHECK_CALL(deinit());
  const size_t max_msize = max_batch * host_data.max_matrix_size();
  m_host_data = &host_data;
  m_max_batch = max_batch;

  LIBXSTREAM_CHECK_CALL(libxstream_stream_create(&m_stream, device, demux, 0, name));
  LIBXSTREAM_CHECK_CALL(libxstream_mem_allocate(device, reinterpret_cast<void**>(&m_adata), sizeof(double) * max_msize, 0));
  LIBXSTREAM_CHECK_CALL(libxstream_mem_allocate(device, reinterpret_cast<void**>(&m_bdata), sizeof(double) * max_msize, 0));
  LIBXSTREAM_CHECK_CALL(libxstream_mem_allocate(device, reinterpret_cast<void**>(&m_cdata), sizeof(double) * max_msize, 0));
  LIBXSTREAM_CHECK_CALL(libxstream_mem_allocate(device, reinterpret_cast<void**>(&m_idata), sizeof(size_t) * max_batch, 0));

  LIBXSTREAM_CHECK_CALL(libxstream_fn_create_signature(&m_signature, 6));
  LIBXSTREAM_CHECK_CALL(libxstream_fn_input (m_signature, 2, m_idata, libxstream_map_to_type(m_idata), 1, &max_msize));
  LIBXSTREAM_CHECK_CALL(libxstream_fn_input (m_signature, 3, m_adata, libxstream_map_to_type(m_adata), 1, &max_msize));
  LIBXSTREAM_CHECK_CALL(libxstream_fn_input (m_signature, 4, m_bdata, libxstream_map_to_type(m_bdata), 1, &max_msize));
  LIBXSTREAM_CHECK_CALL(libxstream_fn_output(m_signature, 5, m_cdata, libxstream_map_to_type(m_cdata), 1, &max_msize));

  return LIBXSTREAM_ERROR_NONE;
}