gemini-code-assist[bot] commented on code in PR #605:
URL: https://github.com/apache/tvm-ffi/pull/605#discussion_r3354039292


##########
python/tvm_ffi/cpp/extension.py:
##########
@@ -162,7 +162,11 @@ def _find_cuda_home() -> str:
 
 
 def _get_cuda_target() -> str:
-    """Get the CUDA target architecture flag."""
+    """Get the CUDA target architecture flag.
+
+    Set ``TVM_FFI_CUDA_ARCH_LIST`` to override automatic detection with a
+    space-separated architecture list, for example ``"8.9 9.0a"``.

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   The example `"8.9 9.0a"` in the docstring includes `"9.0a"`, which triggers 
a compilation failure in NVCC because `_get_cuda_target()` generates 
`-gencode=arch=compute_90a,code=sm_90a`. Since `compute_90a` is an invalid 
virtual architecture, NVCC will fail. Please use an example without suffixes, 
such as `"8.0 8.9"`.



##########
docs/guides/kernel_library_guide.rst:
##########
@@ -173,6 +173,20 @@ This creates a symbol ``__tvm_ffi_scale`` in the shared 
library.
        $(tvm-ffi-config --ldflags) \
        $(tvm-ffi-config --libs)
 
+.. note::
+
+   When using Python JIT build helpers such as :py:func:`tvm_ffi.cpp.load`,
+   :py:func:`tvm_ffi.cpp.load_inline`, or :py:func:`tvm_ffi.cpp.build_inline`
+   with CUDA sources, TVM-FFI automatically detects the GPU compute capability
+   for NVCC. On machines with old CUDA drivers or GPUs that cannot be detected,
+   set ``TVM_FFI_CUDA_ARCH_LIST`` before building:
+
+   .. code-block:: bash
+
+      export TVM_FFI_CUDA_ARCH_LIST="8.9"
+
+   The value is a space-separated architecture list, for example ``"8.9 
9.0a"``.

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   The example `"8.9 9.0a"` includes `"9.0a"`, which will cause a compilation 
failure in NVCC due to a bug in `_get_cuda_target()`. The parsing logic splits 
`"9.0a"` into `major="9"` and `minor="0a"`, and then generates 
`-gencode=arch=compute_90a,code=sm_90a`. Since `compute_90a` is an invalid 
virtual architecture for NVCC, this results in a compilation error. Please 
update the documentation to use an example without suffixes, such as `"8.0 
8.9"`.



##########
python/tvm_ffi/cpp/extension.py:
##########
@@ -202,7 +206,9 @@ def _get_cuda_target() -> str:
             except (subprocess.CalledProcessError, FileNotFoundError):
                 pass
             raise RuntimeError(
-                "Could not detect CUDA compute_cap automatically. Please set 
TVM_FFI_CUDA_ARCH_LIST environment variable."
+                "Could not detect CUDA compute_cap automatically. Set "
+                "TVM_FFI_CUDA_ARCH_LIST to a space-separated CUDA architecture 
list, "
+                'for example "8.9 9.0a".'

Review Comment:
   ![high](https://www.gstatic.com/codereviewagent/high-priority.svg)
   
   Using `"9.0a"` as an example of a CUDA architecture in the error message is 
problematic because of a bug in the parsing logic of `_get_cuda_target()`. 
Specifically, at lines 173-177, the code splits the architecture string by `.` 
and directly appends the major and minor versions to both `compute_` and `sm_` 
prefixes. For `"9.0a"`, this generates `-gencode=arch=compute_90a,code=sm_90a`. 
However, `compute_90a` is an invalid virtual architecture for NVCC (only 
`compute_90` is valid, while `sm_90a` is a valid real architecture), which 
causes NVCC to fail with `nvcc fatal : Unsupported gpu architecture 
'compute_90a'`. To avoid misleading users, please use an example without 
suffixes, such as `"8.0 8.9"`.
   
   ```suggestion
                   "Could not detect CUDA compute_cap automatically. Set "
                   "TVM_FFI_CUDA_ARCH_LIST to a space-separated CUDA 
architecture list, "
                   'for example "8.0 8.9".'
   ```



-- 
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.

To unsubscribe, e-mail: [email protected]

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


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to