Exemplo n.º 1
0
gpudata *cuda_make_buf(void *c, CUdeviceptr p, size_t sz) {
    cuda_context *ctx = (cuda_context *)c;
    gpudata *res;
    int flags = CU_EVENT_DISABLE_TIMING;

    res = malloc(sizeof(*res));
    if (res == NULL) return NULL;
    res->refcnt = 1;

    cuda_enter(ctx);
    if (ctx->err != CUDA_SUCCESS) {
      free(res);
      return NULL;
    }

    res->ptr = p;
    if (ctx->flags & GA_CTX_MULTI_THREAD)
      flags |= CU_EVENT_BLOCKING_SYNC;
    ctx->err = cuEventCreate(&res->ev, flags);
    if (ctx->err != CUDA_SUCCESS) {
      free(res);
      cuda_exit(ctx);
      return NULL;
    }
    res->sz = sz;
    res->flags = DONTFREE;
    res->ctx = ctx;
    ctx->refcnt++;

    cuda_exit(ctx);
    TAG_BUF(res);
    return res;
}
Exemplo n.º 2
0
static gpudata *new_gpudata(cuda_context *ctx, CUdeviceptr ptr, size_t size) {
  gpudata *res;
  int fl = CU_EVENT_DISABLE_TIMING;

  res = malloc(sizeof(*res));
  if (res == NULL) return NULL;

  res->refcnt = 0;
  res->sz = size;

  res->flags = 0;

  cuda_enter(ctx);

  if (ctx->flags & GA_CTX_MULTI_THREAD)
    fl |= CU_EVENT_BLOCKING_SYNC;
  ctx->err = cuEventCreate(&res->rev, fl);
  if (ctx->err != CUDA_SUCCESS) {
    cuda_exit(ctx);
    free(res);
    return NULL;
  }

  ctx->err = cuEventCreate(&res->wev, fl);
  if (ctx->err != CUDA_SUCCESS) {
    cuEventDestroy(res->rev);
    cuda_exit(ctx);
    free(res);
    return NULL;
  }

  cuda_exit(ctx);

  res->ptr = ptr;
  res->next = NULL;
  res->ctx = ctx;
  TAG_BUF(res);

  return res;
}