Skip to content

Commit

Permalink
Loom Shell Multi-GPU support (#393)
Browse files Browse the repository at this point in the history
* Loom Shell - Support Multiple Devices

* Free Allocated Mem
  • Loading branch information
kiritigowda authored Nov 13, 2020
1 parent 607f6ea commit 95e4d94
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions utilities/loom_shell/loom_shell_util.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -128,19 +128,27 @@ static cl_command_queue GetCmdqCached(cl_mem mem)
cmdq = globalClCtx2CmdqMap[opencl_context];
}
else {
// First, get the size of device list data
size_t device_list_size_;
cl_int err;
err = clGetContextInfo(opencl_context, CL_CONTEXT_DEVICES, 0, NULL, &device_list_size_);
if (err) { Error("ERROR: clGetContextInfo(*,CL_CONTEXT_DEVICES) failed (%d)", err); return nullptr; }
// create OpenCL cmd_queue using first device in the context
cl_int err; cl_device_id device_id = nullptr;
err = clGetContextInfo(opencl_context, CL_CONTEXT_DEVICES, sizeof(device_id), &device_id, nullptr);
cl_device_id *devices_; devices_ = (cl_device_id *)malloc(device_list_size_);
if(devices_==NULL){ Error("ERROR: cl_device_id is NULL"); return nullptr; }
err = clGetContextInfo(opencl_context, CL_CONTEXT_DEVICES, device_list_size_, devices_, nullptr);
if (err) { Error("ERROR: clGetContextInfo(*,CL_CONTEXT_DEVICES) failed (%d)", err); return nullptr; }
#if defined(CL_VERSION_2_0)
cmdq = clCreateCommandQueueWithProperties(opencl_context, device_id, NULL, &err);
cmdq = clCreateCommandQueueWithProperties(opencl_context, devices_[0], NULL, &err);
#else
cmdq = clCreateCommandQueue(opencl_context, device_id, 0, &err);
cmdq = clCreateCommandQueue(opencl_context, devices_[0], 0, &err);
#endif
if (!cmdq) { Error("ERROR: clCreateCommandQueueWithProperties: failed (%d)", err); return nullptr; }
// save the command-queue
globalClCtx2CmdqMap[opencl_context] = cmdq;
globalClMem2CmdqMap[mem] = cmdq;
// free mem
free(devices_);
}
}
return cmdq;
Expand Down

0 comments on commit 95e4d94

Please sign in to comment.