From bc7e8f374d2dd9630a9e0f2191bedf290a8178ce Mon Sep 17 00:00:00 2001 From: Gene Merewether Date: Mon, 3 Nov 2025 11:33:36 -0500 Subject: [PATCH] Specify cuda device (or host) in ogn --- .../include/isaacsim/ros2/bridge/Ros2Message.h | 4 +++- .../library/backend/Ros2Impl.h | 4 +++- .../library/backend/Ros2Message.cpp | 17 ++++++++++------- .../nodes/OgnROS2PublishJointState.cpp | 2 +- .../nodes/OgnROS2PublishJointState.ogn | 11 ++++++++--- 5 files changed, 25 insertions(+), 13 deletions(-) diff --git a/source/extensions/isaacsim.ros2.bridge/include/isaacsim/ros2/bridge/Ros2Message.h b/source/extensions/isaacsim.ros2.bridge/include/isaacsim/ros2/bridge/Ros2Message.h index e45911d8..b64cefb3 100644 --- a/source/extensions/isaacsim.ros2.bridge/include/isaacsim/ros2/bridge/Ros2Message.h +++ b/source/extensions/isaacsim.ros2.bridge/include/isaacsim/ros2/bridge/Ros2Message.h @@ -427,6 +427,7 @@ class Ros2JointStateMessage : public Ros2Message * @param[in] jointEfforts Joint efforts. * @param[in] dofTypes Articulation DOF types. * @param[in] stageUnits Unit scale of the stage. + * @param[in] cudaDeviceIndex Index of the device where the data lives (-1 for host data) */ virtual void writeData(const double& timeStamp, omni::physics::tensors::IArticulationView* articulation, @@ -435,7 +436,8 @@ class Ros2JointStateMessage : public Ros2Message std::vector& jointVelocities, std::vector& jointEfforts, std::vector& dofTypes, - const double& stageUnits) = 0; + const double& stageUnits, + const int& cudaDeviceIndex) = 0; /** * @brief Read the message field values. diff --git a/source/extensions/isaacsim.ros2.bridge/library/backend/Ros2Impl.h b/source/extensions/isaacsim.ros2.bridge/library/backend/Ros2Impl.h index df9aec2d..0e306f80 100644 --- a/source/extensions/isaacsim.ros2.bridge/library/backend/Ros2Impl.h +++ b/source/extensions/isaacsim.ros2.bridge/library/backend/Ros2Impl.h @@ -450,6 +450,7 @@ class Ros2JointStateMessageImpl : public Ros2JointStateMessage, Ros2MessageInter * @param[in] jointEfforts Vector of joint efforts * @param[in] dofTypes Vector of DOF types * @param[in] stageUnits Stage unit scale factor + * @param[in] cudaDeviceIndex Index of the device where the data lives (-1 for host data) */ virtual void writeData(const double& timeStamp, omni::physics::tensors::IArticulationView* articulation, @@ -458,7 +459,8 @@ class Ros2JointStateMessageImpl : public Ros2JointStateMessage, Ros2MessageInter std::vector& jointVelocities, std::vector& jointEfforts, std::vector& dofTypes, - const double& stageUnits); + const double& stageUnits, + const int& cudaDeviceIndex); /** * @brief Reads the joint state data diff --git a/source/extensions/isaacsim.ros2.bridge/library/backend/Ros2Message.cpp b/source/extensions/isaacsim.ros2.bridge/library/backend/Ros2Message.cpp index 2ed78ec6..980eeb28 100644 --- a/source/extensions/isaacsim.ros2.bridge/library/backend/Ros2Message.cpp +++ b/source/extensions/isaacsim.ros2.bridge/library/backend/Ros2Message.cpp @@ -998,7 +998,8 @@ template static void createTensorDesc(omni::physics::tensors::TensorDesc& tensorDesc, std::vector& buffer, int numElements, - omni::physics::tensors::TensorDataType type) + omni::physics::tensors::TensorDataType type, + int cudaDeviceIndex) { buffer.resize(numElements); tensorDesc.dtype = type; @@ -1006,7 +1007,7 @@ static void createTensorDesc(omni::physics::tensors::TensorDesc& tensorDesc, tensorDesc.dims[0] = numElements; tensorDesc.data = buffer.data(); tensorDesc.ownData = true; - tensorDesc.device = -1; + tensorDesc.device = cudaDeviceIndex; } void Ros2JointStateMessageImpl::writeData(const double& timeStamp, @@ -1016,7 +1017,8 @@ void Ros2JointStateMessageImpl::writeData(const double& timeStamp, std::vector& jointVelocities, std::vector& jointEfforts, std::vector& dofTypes, - const double& stageUnits) + const double& stageUnits, + const int& cudaDeviceIndex) { if (!m_msg) { @@ -1030,10 +1032,11 @@ void Ros2JointStateMessageImpl::writeData(const double& timeStamp, omni::physics::tensors::TensorDesc velocityTensor; omni::physics::tensors::TensorDesc effortTensor; omni::physics::tensors::TensorDesc dofTypeTensor; - createTensorDesc(positionTensor, jointPositions, numDofs, omni::physics::tensors::TensorDataType::eFloat32); - createTensorDesc(velocityTensor, jointVelocities, numDofs, omni::physics::tensors::TensorDataType::eFloat32); - createTensorDesc(effortTensor, jointEfforts, numDofs, omni::physics::tensors::TensorDataType::eFloat32); - createTensorDesc(dofTypeTensor, dofTypes, numDofs, omni::physics::tensors::TensorDataType::eUint8); + createTensorDesc(positionTensor, jointPositions, numDofs, omni::physics::tensors::TensorDataType::eFloat32, cudaDeviceIndex); + createTensorDesc(velocityTensor, jointVelocities, numDofs, omni::physics::tensors::TensorDataType::eFloat32, cudaDeviceIndex); + createTensorDesc(effortTensor, jointEfforts, numDofs, omni::physics::tensors::TensorDataType::eFloat32, cudaDeviceIndex); + // The DOF type data always lives on host. + createTensorDesc(dofTypeTensor, dofTypes, numDofs, omni::physics::tensors::TensorDataType::eUint8, -1); bool hasDofStates = true; if (!articulation->getDofPositions(&positionTensor)) { diff --git a/source/extensions/isaacsim.ros2.bridge/nodes/OgnROS2PublishJointState.cpp b/source/extensions/isaacsim.ros2.bridge/nodes/OgnROS2PublishJointState.cpp index eb197d56..173743c1 100644 --- a/source/extensions/isaacsim.ros2.bridge/nodes/OgnROS2PublishJointState.cpp +++ b/source/extensions/isaacsim.ros2.bridge/nodes/OgnROS2PublishJointState.cpp @@ -164,7 +164,7 @@ class OgnROS2PublishJointState : public Ros2Node m_stage = pxr::UsdUtilsStageCache::Get().Find(pxr::UsdStageCache::Id::FromLongInt(stageId)); state.m_message->writeData(db.inputs.timeStamp(), m_articulation, m_stage, m_jointPositions, m_jointVelocities, - m_jointEfforts, m_dofTypes, stageUnits); + m_jointEfforts, m_dofTypes, stageUnits, db.inputs.cudaDeviceIndex()); state.m_publisher.get()->publish(state.m_message->getPtr()); return true; } diff --git a/source/extensions/isaacsim.ros2.bridge/nodes/OgnROS2PublishJointState.ogn b/source/extensions/isaacsim.ros2.bridge/nodes/OgnROS2PublishJointState.ogn index 6ce91b80..aded38e9 100644 --- a/source/extensions/isaacsim.ros2.bridge/nodes/OgnROS2PublishJointState.ogn +++ b/source/extensions/isaacsim.ros2.bridge/nodes/OgnROS2PublishJointState.ogn @@ -1,6 +1,6 @@ { "ROS2PublishJointState":{ - "version": 1, + "version": 2, "icon": "icons/isaac-sim.svg", "description": [ "This node publishes joint states of a robot in ROS2 JointState message" @@ -49,10 +49,15 @@ "description": "ROS2 Timestamp in seconds", "uiName": "Timestamp", "default": 0.0 - + + }, + "cudaDeviceIndex": { + "type": "int", + "description": "Index of the device where the data lives (-1 for host data)", + "default": -1 } } } -} \ No newline at end of file +}