[TESTS] Why requires_metal skip test but I build tvm with metal?

Hello,

I have a problem with running some metal tests in TVM. I tried to add new tests on Metal and use decorator @tvm.testing.requires_metal to specify that this test should be run only for Metal. But when I run this test, it is skipped, because it didn’t find GPU. I commented *requires_gpu() in requires_metal and after this the test was executed.

Could you help me, what should I do to run this test without commenting *requres_gpu()?

I’m working on MacOS. And build TVM with the following keys:

              -DUSE_OPENCL=ON
            \ -DUSE_METAL=ON
            \ -DUSE_RPC=ON
            \ -DUSE_GRAPH_RUNTIME=ON
            \ -DUSE_GRAPH_EXECUTOR_DEBUG=ON
            \ -DUSE_LLVM=ON
            \ -DUSE_RANDOM=ON
            \ -DUSE_SORT=ON
            \ -DUSE_RELAY_DEBUG=ON
            \ -DUSE_MKLDN=${HOME}/Soft/dnnl_mac_1.7.0_cpu_iomp
            \ -DUSE_BNNS=ON

Also, I tried to register device_api.gpu in metal_device_api.mm in the same way as it done in cuda_device_api.cc:

TVM_REGISTER_GLOBAL("device_api.gpu").set_body([](TVMArgs args, TVMRetValue* rv) {
  DeviceAPI* ptr = MetalWorkspace::Global();
  *rv = static_cast<void*>(ptr);
});

And with this declaration the test also was executed without commenting requires_gpu(). But I don’t think that it is a good fix because will happen if I try to build tvm with cuda and metal support?

Hello! Does your machine have a CUDA GPU? @tvm.testing.requires_metal currently includes @tvm.testing.requires_gpu, which checks whether a cuda gpu is present (this line), if not, the test will be skipped.

Thank you for your reply! No, I don’t have any CUDA GPU on my mac.

I’m working on an older version of main, so it names gpu there. I see that it was yesterday renamed. But anyway, it doesn’t really matter what is the name of this function gpu or cuda.

Why we require CUDA for Metal or for example for OpenCL? We can run OpenCL tests on many different devices. But the tests won’t work on them, because of this requirement. Maybe we should change it and remove this requirement at least for Metal and maybe for some other runtimes?

Yes! I don’t think the current implementation of tvm.testing.requires_gpu is right. The intention of it should be just to check whether the machine has a GPU, and it can be Nvidia, ARM, Apple, etc.

cc @tkonolige, do you think we should change tvm.testing.requires_gpu to check whether any type of the GPU types exist?

Hi @echuraev, we submitted a PR, which should fix this issue. :slight_smile:

Thank you! I checked and it fixed my problem! :slightly_smiling_face:

1 Like