tqchen commented on a change in pull request #6331:
URL: https://github.com/apache/incubator-tvm/pull/6331#discussion_r475843056



##########
File path: python/tvm/testing.py
##########
@@ -285,4 +288,105 @@ def _check_forward(constraints1, constraints2, varmap, 
backvarmap):
                    constraints_trans.dst_to_src, constraints_trans.src_to_dst)
 
 
+def gpu(f):
+    """Mark to differentiate tests that use the GPU is some capacity. These
+    tests will be run on CPU-only nodes and on nodes with GPUS.
+

Review comment:
       Use numpydoc style to document all the arguments

##########
File path: python/tvm/testing.py
##########
@@ -285,4 +288,105 @@ def _check_forward(constraints1, constraints2, varmap, 
backvarmap):
                    constraints_trans.dst_to_src, constraints_trans.src_to_dst)
 
 
+def gpu(f):
+    """Mark to differentiate tests that use the GPU is some capacity. These
+    tests will be run on CPU-only nodes and on nodes with GPUS.
+
+    To mark a test that must have a GPU present to run, use `@requires_gpu`.
+    """
+    return pytest.mark.gpu(f)
+
+
+def requires_gpu(f):

Review comment:
       Perhaps it is more useful to mark a region besides mark a function. e.g. 
   
   ```python
   with tvm.testing.cuda_region():
       pass
   ```

##########
File path: python/tvm/testing.py
##########
@@ -285,4 +288,105 @@ def _check_forward(constraints1, constraints2, varmap, 
backvarmap):
                    constraints_trans.dst_to_src, constraints_trans.src_to_dst)
 
 
+def gpu(f):
+    """Mark to differentiate tests that use the GPU is some capacity. These
+    tests will be run on CPU-only nodes and on nodes with GPUS.
+
+    To mark a test that must have a GPU present to run, use `@requires_gpu`.
+    """
+    return pytest.mark.gpu(f)
+
+
+def requires_gpu(f):
+    """Mark a test as requiring a GPU to run. Tests with this mark will not be
+    run unless a gpu is present.
+    """
+    return pytest.mark.skipif(not tvm.gpu().exist, reason="No GPU 
present")(gpu(f))
+
+
+def requires_cuda(f):
+    """Mark a test as requiring the CUDA runtime. This does not mean the tests
+    also requires a gpu. For that, use `@requires_gpu` and `@requires_cuda`
+    """
+    return pytest.mark.cuda(
+        pytest.mark.skipif(
+            not tvm.runtime.enabled("cuda"), reason="CUDA support not enabled"
+        )(requires_gpu(f))
+    )
+
+
+def requires_opencl(f):
+    """Mark a test as requiring the OpenCL runtime. This does not mean the 
tests
+    also requires a gpu. For that, use `@requires_gpu` and `@requires_cuda`.
+    """
+    return pytest.mark.opencl(
+        pytest.mark.skipif(
+            not tvm.runtime.enabled("opencl"), reason="OpenCL support not 
enabled"
+        )(f)
+    )
+
+
+def requires_tpu(f):

Review comment:
       requires_tensorcore

##########
File path: tests/python/topi/python/test_topi_conv2d_nhwc_winograd.py
##########
@@ -114,6 +111,8 @@ def check_device(device):
     check_device(devices)
 
 
+@requires_cuda

Review comment:
       requires_cuda imply requires gpu?

##########
File path: python/tvm/_ffi/runtime_ctypes.py
##########
@@ -197,6 +199,10 @@ def _GetDeviceAttr(self, device_type, device_id, attr_id):
     @property
     def exist(self):
         """Whether this device exist."""
+        allowed_ctxs = os.environ.get("TVM_TEST_CTXS")

Review comment:
       This seems to be a hack that we should not put in here, but instead put 
in tvm.testing

##########
File path: python/tvm/testing.py
##########
@@ -285,4 +288,105 @@ def _check_forward(constraints1, constraints2, varmap, 
backvarmap):
                    constraints_trans.dst_to_src, constraints_trans.src_to_dst)
 
 
+def gpu(f):

Review comment:
       the function name is not informative. e.g. use_gpu?

##########
File path: tests/python/topi/python/test_topi_conv2d_nhwc_winograd.py
##########
@@ -114,6 +111,8 @@ def check_device(device):
     check_device(devices)
 
 
+@requires_cuda

Review comment:
       perhaps it is better to use the abs name: `tvm.testing.requires_cuda` to 
give better context, do the same thing for other annotations

##########
File path: tests/scripts/setup-pytest-env.sh
##########
@@ -26,5 +26,20 @@ else
 fi
 set -u
 
+export TVM_TEST_DEVICES=""
+while test $# -gt 0
+do
+    case "$1" in
+        cpu) export TVM_TEST_DEVICES="llvm;llvm 
-device=arm_cpu;$TVM_TEST_DEVICES"
+            ;;

Review comment:
       I feel it is a bit overly complicated to have two level of directions 
here:
   - D0: arguments in the test script
   - D1: env variable(TVM_TEST_DEVICES)
   - D2: pytest flag.
   
   It would be awsome if we can reduce it to a single level e.g. an environment 
variable, and ensure good default behavior so that we can:
   - Directly run a specific test via pytest without worrying about setting up 
the env and run setup-pytest-denv
   - Have good default when nothing is set 




----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

For queries about this service, please contact Infrastructure at:
[email protected]


Reply via email to