Skip to content

cuGetProcAddress not implement #3

Description

@chaunceyjiang

cuGetProcAddress not implement

I encountered the aforementioned error, and I also tried to implement it myself, but was continuously unsuccessful.

If you have some spare time, could you help implement this function? Thank you very much.

server

// cuda.cc


void Cuda::DispatchCuGetProcAddress(CudaRequest* request, RenderResponse* response) {
  CL_ASSERT(request->param_count == 5);
  auto symbol = (const char*)CUDA_REQUEST_EXTEND(request);
  CL_LOG("params1 :%s", symbol);
  CL_LOG("params2 :%d", (int)request->params[2]);
  CL_LOG("params3 :%d", (cuuint64_t)request->params[3]);

  response->header.size = sizeof(void*) + sizeof(CUdriverProcAddressQueryResult);
  response->data.resize(response->header.size);

  void** fn = (void**)response->data.data();
  CUdriverProcAddressQueryResult* ret = (CUdriverProcAddressQueryResult*)FIELD_OFFSET(fn);

  response->header.result = cuGetProcAddress(symbol, bin, (int)request->params[2], (cuuint64_t)request->params[3], ret);
    CL_LOG("-----");
  CL_LOG("ret1: %d", fn);
  CL_LOG("ret1: %d", *fn);
  CL_LOG("ret2: %d", *ret);
}




---
void Cuda::Dispatch(WorkerItem* item) {
  auto request = (CudaRequest*)item->request.data.data();
  CL_LOG("call api=%s param_count=%d", GetCudaFunctionName(request->api_index), request->param_count);
  
  CL_ASSERT(request->version == version_);
  Render::Dispatch(item);

  switch (request->api_index) {
    case CUGETPROCADDRESS:
        DispatchCuGetProcAddress(request, &item->response);
        break;
...
...

client

// render.cpp

CUresult Render::PrepareRequest(RenderRequest* request) {
  auto cuda = (CudaRequest*)request->datas[0].data();

  switch (cuda->api_index) {
  case CUGETPROCADDRESS: {
      auto symbol = (char*)cuda->params[0];
      if (symbol) {
          std::string_view name_sv(symbol, strlen(symbol) + 1);
          request->header.size += (uint32_t)name_sv.size();
          request->datas.emplace_back(std::move(name_sv));
      }
      break;
  }


// -----

CUresult Render::HandleResponse(RenderRequest* request, RenderResponse* response) {
  auto cuda = (CudaRequest*)request->datas[0].data();
  auto result = (CUresult)response->header.result;

  if (result != CUDA_SUCCESS) {
    CL_ERROR("handle error for api=%s result=%d", GetCudaFunctionName(cuda->api_index), result);
    goto end;
  }

  switch (cuda->api_index) {
    case CUGETPROCADDRESS:
      auto ret = (uint64_t*)response->data.data();
      auto fn = (void*)ret[0];
      auto size = (CUdriverProcAddressQueryResult)ret[1];
      *(void**)cuda->params[1] = fn;
      if (cuda->params[4]) {
        *(CUdriverProcAddressQueryResult*)cuda->params[4] = size;
      }
     break;

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions