TVM opencl context how to choose device type as accelerator

So I am using device accelerator which uses opencl (pocl). Here when I try to run opencl code using tvm on this device I have to fetch the context here as tvm.cl() but it does not use the device type as accelerator unless I set the dtype = CL_DEVICE_TYPE_ACCELERATOR, in the tvm/src/runtime/opencl/opencl_device_api.cc

So how do I set the dtype as accelerator without explicitly setting the dtype in the opencl_device_api.ccm which function takes these parameters and which files can I go through to find out how these parameters are set

(https://discuss.tvm.apache.org/t/how-does-tvm-choose-the-platform-and-device/7695/5?u=akhilj99)

1 Like

Hello, I made TVM work with OpenCL accelerators and I am preparing a pull request to make TVM accept opencl accelerator device type along with some modifications in the opencl default schedules to generalize them. I will post further updates here.

I made the pull request #6412. It may not be perfect but it should help you for your project.

Hey @aurel333 Thanks a ton for that fix. The update you have given will try choose the first platform even if couldn’t find an accelerator device. Would it be better to continue and check the next platform instead of trying to change the device_type and look for devices ?

I tried to use the same system as what was already present but I agree that this system is not of high quality.

In my opinion it will benefit greatly from an overhaul that let the user specify which device type to use, so feel free to submit a pull request if you implement it. However I recommend you check with @tqchen or @kazum as they worked on this part before.

cc @FrozenGene, who may have more experiences on OpenCL.

The problem is in

  void Init(const std::string& type_key, const std::string& device_type,
            const std::string& platform_name = "");
  virtual void Init() { Init("opencl", "gpu"); } // gpu is the device type

Inside Init, we will only try to match the gpu device type, if no, we will use opencl cpu.

For your case, I would suggest we create one new DeviceType (although you are using OpenCL, but you are an accelerator), you could refer how AOCL (Intel FPGA which uses OpenCL) to do, your case is almost the same as them.