machichima commented on code in PR #745:
URL: https://github.com/apache/mahout/pull/745#discussion_r2636959525
##########
qdp/qdp-python/src/lib.rs:
##########
@@ -94,8 +94,22 @@ impl QuantumTensor {
/// Returns:
/// Tuple of (device_type, device_id) where device_type=2 for CUDA
fn __dlpack_device__(&self) -> PyResult<(i32, i32)> {
- // DLDeviceType::kDLCUDA = 2, device_id = 0
- Ok((2, 0))
+ if self.ptr.is_null() {
+ return Err(PyRuntimeError::new_err("Invalid DLPack tensor
pointer"));
+ }
+
+ unsafe {
+ // Read device_id from DLPack tensor metadata
+ // DLDeviceType::kDLCUDA = 2 (from dlpack.h)
Review Comment:
nit: remove? Seems duplicated with following comments
##########
qdp/qdp-python/src/lib.rs:
##########
@@ -94,8 +94,22 @@ impl QuantumTensor {
/// Returns:
/// Tuple of (device_type, device_id) where device_type=2 for CUDA
fn __dlpack_device__(&self) -> PyResult<(i32, i32)> {
- // DLDeviceType::kDLCUDA = 2, device_id = 0
- Ok((2, 0))
+ if self.ptr.is_null() {
+ return Err(PyRuntimeError::new_err("Invalid DLPack tensor
pointer"));
+ }
+
+ unsafe {
+ // Read device_id from DLPack tensor metadata
+ // DLDeviceType::kDLCUDA = 2 (from dlpack.h)
+ let tensor = &(*self.ptr).dl_tensor;
+ // device_type is an enum, convert to integer
+ // kDLCUDA = 2, kDLCPU = 1
Review Comment:
```suggestion
// kDLCUDA = 2, kDLCPU = 1
// Ref:
https://github.com/dmlc/dlpack/blob/6ea9b3eb64c881f614cd4537f95f0e125a35555c/include/dlpack/dlpack.h#L76-L80
```
nit: add ref for enum definition
##########
qdp/qdp-python/src/lib.rs:
##########
@@ -94,8 +94,22 @@ impl QuantumTensor {
/// Returns:
/// Tuple of (device_type, device_id) where device_type=2 for CUDA
fn __dlpack_device__(&self) -> PyResult<(i32, i32)> {
- // DLDeviceType::kDLCUDA = 2, device_id = 0
- Ok((2, 0))
+ if self.ptr.is_null() {
+ return Err(PyRuntimeError::new_err("Invalid DLPack tensor
pointer"));
+ }
+
+ unsafe {
+ // Read device_id from DLPack tensor metadata
Review Comment:
Maybe we can put // Read device_id from DLPack tensor metadata above line
111, where we actually read the devince_id
--
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]