tensors#
Fully qualified name: isaacsim::physics::newton::tensors
-
namespace tensors#
Classes Summary#
- ArticulationMetatype
Articulation topology descriptor for a single articulation in the view.
- BaseArticulationView
Base articulation view implementing IArticulationView for Newton.
- BaseRigidBodyView
Base rigid body view implementing IRigidBodyView for Newton.
- BaseRigidContactView
Base contact view implementing IRigidContactView for Newton.
- BaseSimulationView
Base simulation view implementing ISimulationView for the Newton backend.
- CpuArticulationView
CPU articulation view. Implements getters/setters using host-side gather/scatter loops. Reusable scratch vectors (m_scratchSourceOffset, m_scratchDestinationIndex) avoid per-call heap allocation.
- CpuRigidBodyView
CPU rigid body view. Implements getters/setters using host-side gather/scatter loops.
- CpuRigidContactView
CPU contact view. Iterates the contact buffer on the host to compute net forces, force matrices, and per-contact data. Uses host-side zero buffers as fallbacks when optional contact arrays (point0/1, thickness0/1) are not present.
- CpuSimulationView
CPU simulation view. Reports device ordinal -1 and creates Cpu* child views.
- GpuArticulationView
GPU articulation view. Implements getters via CUDA gather kernels with D2H staging, and setters via fused CUDA scatter kernels. Supports GC (GPU sim, CPU view tensors) by staging CPU index/source data into pre-allocated device buffers.
- GpuRigidBodyView
GPU rigid body view. Implements getters via CUDA gather kernels with D2H staging, and setters via fused CUDA scatter kernels. Supports GC configuration.
- GpuRigidContactView
GPU contact view. Uses CUDA kernels for net force, force matrix, and per-contact data computation. Device-side zero buffers serve as fallbacks for optional contact arrays.
- GpuSimulationView
GPU simulation view. Reports the CUDA device ordinal and creates Gpu* child views.
- SimulationBackend
Newton tensor backend entry point.
Functions Summary#
- void cpuContactData(const int *contactCount, const int *shape0, const int *shape1, const float *point0, const float *point1, const float *normal, const float *contactForce, const float *thickness0, const float *thickness1, const int *shapeBody, const float *bodyQ, const int *bodySensorMap, int bodySensorMapSize, const int *bodyFilterMap, int numBodies, int filterCount, int worldBodyIdx, float dtScale, int maxContactDataCount, float *outForces, float *outPoints, float *outNormals, float *outSeparations, uint32_t *outCounts, const uint32_t *startIndices, int rigidContactMax, bool pointsInWorldSpace=false)
- void cpuContactForceMatrix(const int *contactCount, const int *shape0, const int *shape1, const float *contactForce, const int *shapeBody, const int *bodySensorMap, int bodySensorMapSize, const int *bodyFilterMap, int numBodies, int worldBodyIdx, float dtScale, int filterCount, float *forceMatrix, int rigidContactMax)
- void cpuCountContactsPerPair(const int *contactCount, const int *shape0, const int *shape1, const int *shapeBody, const int *bodySensorMap, int bodySensorMapSize, const int *bodyFilterMap, int numBodies, int filterCount, int worldBodyIdx, uint32_t *counts, int rigidContactMax)
- void cpuCountRawContactsPerSensor(const int *contactCount, const int *shape0, const int *shape1, const int *shapeBody, const int *bodySensorMap, int bodySensorMapSize, int worldBodyIdx, uint32_t *counts, int rigidContactMax)
- void cpuExtractVec3FromSpatial(const float *spatialSrc, float *vec3Dst, int n)
- void cpuNetContactForces(const int *contactCount, const int *shape0, const int *shape1, const float *contactForce, const int *shapeBody, const int *bodySensorMap, int bodySensorMapSize, int worldBodyIdx, float dtScale, float *netForces, int rigidContactMax)
- void cpuRawContactData(const int *contactCount, const int *shape0, const int *shape1, const float *point0, const float *point1, const float *normal, const float *contactForce, const float *thickness0, const float *thickness1, const int *shapeBody, const float *bodyQ, const int *bodySensorMap, int bodySensorMapSize, int worldBodyIdx, float dtScale, int maxContactDataCount, float *outForces, float *outPoints, float *outNormals, float *outSeparations, uint32_t *outCounts, const uint32_t *startIndices, uint64_t *otherActorIds, int rigidContactMax, bool pointsInWorldSpace=false)
- const float * ensureGpuSrc(const TensorDesc *srcTensor, float *devStagingBuf, size_t maxFloats)
Ensures source data resides on the GPU. If srcTensor is already on device, returns its pointer. If on CPU, performs H2D copy into devStagingBuf. Returns nullptr on error.
- void gatherCenterOfMass(const wp::vec3 *src, float *dst, const int *indices, size_t n, const float *cachedOrientation)
- void gatherFloat(const float *src, float *dst, const int *indices, size_t n)
- void gatherMat33(const wp::mat33 *src, float *dst, const int *indices, size_t n)
- void gatherPairedFloat(const float *srcA, const float *srcB, float *dst, const int *indices, size_t n)
- void gatherSpatialVector(const wp::spatial_vector *src, float *dst, const int *indices, size_t n)
- void gatherTransform(const wp::transform *src, float *dst, const int *indices, size_t n)
- int getWarpArrayDevice(py::object pyArray)
Returns the CUDA device ordinal of a wp.array (-1 for CPU, >= 0 for GPU).
- std::vector< int64_t > getWarpArrayShape(py::object pyArray)
Returns the shape of a wp.array as a vector of dimension sizes.
- size_t getWarpArraySize(py::object pyArray)
Returns the total number of elements in a wp.array (product of all dimensions).
- bool gpuGather(LaunchFn &&launch, const TensorDesc *dstTensor, int n, size_t elemFloats, float *stagingBuffer)
Launches a CUDA gather kernel and stages the result to dstTensor.
- void indirectAddFloat(const float *src, float *dst, const int *srcOffsets, const int *dstIndices, size_t n)
- void indirectScatterFloat(const float *src, float *dst, const int *srcOffsets, const int *dstIndices, size_t n)
- bool launchContactData(const int *contactCount, const int *shape0, const int *shape1, const float *point0, const float *point1, const float *normal, const float *contactForce, const float *thickness0, const float *thickness1, const int *shapeBody, const float *bodyQ, const int *bodySensorMap, int bodySensorMapSize, const int *bodyFilterMap, int numBodies, int filterCount, int worldBodyIdx, float dtScale, int maxContactDataCount, float *outForces, float *outPoints, float *outNormals, float *outSeparations, uint32_t *outCounts, const uint32_t *startIndices, int rigidContactMax, bool pointsInWorldSpace=false, void *stream=nullptr)
Emit per-contact data (force, point, normal, separation) for each sensor/filter pair.
- bool launchContactForceMatrix(const int *contactCount, const int *shape0, const int *shape1, const float *contactForce, const int *shapeBody, const int *bodySensorMap, int bodySensorMapSize, const int *bodyFilterMap, int numBodies, int worldBodyIdx, float dtScale, int filterCount, float *forceMatrix, int rigidContactMax, void *stream=nullptr)
Accumulate per-(sensor, filter) contact forces into a dense matrix.
- bool launchCopyUint8(const uint8_t *src, uint8_t *dst, int n, void *stream=nullptr)
Device-to-device byte copy of a flat
uint8buffer.- bool launchCountContactsPerPair(const int *contactCount, const int *shape0, const int *shape1, const int *shapeBody, const int *bodySensorMap, int bodySensorMapSize, const int *bodyFilterMap, int numBodies, int filterCount, int worldBodyIdx, uint32_t *counts, int rigidContactMax, void *stream=nullptr)
Count the number of contacts per
(sensor, filter)pair.- bool launchCountRawContactsPerSensor(const int *contactCount, const int *shape0, const int *shape1, const int *shapeBody, const int *bodySensorMap, int bodySensorMapSize, int worldBodyIdx, uint32_t *counts, int rigidContactMax, void *stream=nullptr)
Count raw contacts per sensor (ignoring filters).
- bool launchExtractVec3FromSpatial(const float *spatialSrc, float *vec3Dst, int n, void *stream=nullptr)
Extract the linear component of each :class:
wp::spatial_vectorinto a vec3.- bool launchFusedDofScatter(const float *src, float *dst, const int *devArtiIndices, const int *devDofMapping, int numArti, int maxDofs, void *stream=nullptr)
Fused indexed DOF scatter: writes view-scoped DOF values into a flat model DOF array.
- bool launchFusedLinkAdd(const float *src, float *dst, const int *devArtiIndices, const int *devLinkMapping, int numArti, int maxLinks, int srcElemSize, int dstElemSize, int dstElemOffset, int numComponents, void *stream=nullptr)
Same as :func:
launchFusedLinkScatterbut performs an atomic add intodst.- bool launchFusedLinkScatter(const float *src, float *dst, const int *devArtiIndices, const int *devLinkMapping, int numArti, int maxLinks, int srcElemSize, int dstElemSize, int dstElemOffset, int numComponents, void *stream=nullptr)
Fused link scatter for articulation link properties.
- bool launchFusedPairedDofScatter(const float *src, float *dstA, float *dstB, const int *devArtiIndices, const int *devDofMapping, int numArti, int maxDofs, void *stream=nullptr)
Fused indexed DOF scatter that writes the same value into two destinations.
- bool launchFusedRootFlatScatter(const float *src, float *dst, const int *devArtiIndices, const int *devRootFlatMapping, int numArti, int elemSize, void *stream=nullptr)
Fused scatter for articulation root into a flat joint-qd-style layout.
- bool launchFusedRootScatter(const float *src, float *dst, const int *devArtiIndices, const int *devRootMapping, int numArti, int elemSize, void *stream=nullptr)
Fused scatter for articulation root properties (transforms, velocities).
- bool launchGatherCenterOfMass(const wp::vec3 *src, float *dst, const int *devIndices, int numIndices, const float *cachedOrientation, void *stream=nullptr)
Gather center-of-mass vec3 entries and pair with cached orientation quaternions.
- bool launchGatherFloat(const float *src, float *dst, const int *devIndices, int numIndices, void *stream=nullptr)
Gather scalar floats by index, writing zero for
-1entries.- bool launchGatherMat33(const wp::mat33 *src, float *dst, const int *devIndices, int numIndices, void *stream=nullptr)
Gather :class:
wp::mat33entries (9 floats each, row-major).- bool launchGatherPairedFloat(const float *srcA, const float *srcB, float *dst, const int *devIndices, int numIndices, void *stream=nullptr)
Interleaved gather from two parallel source arrays.
- bool launchGatherSpatialVector(const wp::spatial_vector *src, float *dst, const int *devIndices, int numIndices, void *stream=nullptr)
Gather :class:
wp::spatial_vectorentries (6 floats each).- bool launchGatherTransform(const wp::transform *src, float *dst, const int *devIndices, int numIndices, void *stream=nullptr)
Gather :class:
wp::transformentries (7 floats each) into a packed output.- bool launchNetContactForces(const int *contactCount, const int *shape0, const int *shape1, const float *contactForce, const int *shapeBody, const int *bodySensorMap, int bodySensorMapSize, int worldBodyIdx, float dtScale, float *netForces, int rigidContactMax, void *stream=nullptr)
Accumulate per-sensor net contact forces.
- bool launchRawContactData(const int *contactCount, const int *shape0, const int *shape1, const float *point0, const float *point1, const float *normal, const float *contactForce, const float *thickness0, const float *thickness1, const int *shapeBody, const float *bodyQ, const int *bodySensorMap, int bodySensorMapSize, int worldBodyIdx, float dtScale, int maxContactDataCount, float *outForces, float *outPoints, float *outNormals, float *outSeparations, uint32_t *outCounts, const uint32_t *startIndices, uint64_t *otherActorIds, int rigidContactMax, bool pointsInWorldSpace=false, void *stream=nullptr)
Emit raw per-sensor contact data with the "other actor" identifier.
- bool launchScatterComOrientation(const float *src, float *dst, const int *devArtiIndices, int count, int elemPerSlot, int srcStride, void *stream=nullptr)
Extract orientation quaternions from a COM tensor and scatter to a flat cache.
- bool launchUpdateInverseInertia(const wp::mat33 *inertia, wp::mat33 *inverseInertia, int n, void *stream=nullptr)
Compute per-element inverse inertia matrix on device.
- bool launchUpdateInverseMass(const float *mass, float *inverseMass, int n, void *stream=nullptr)
Compute per-element inverse mass on device.
- GpuIndexGuard resolveGpuViewIndices(const TensorDesc *indexTensor, uint32_t defaultCount, int *devScratchBuf=nullptr)
Resolves an index tensor for GPU kernel use. If the tensor is on GPU, returns its pointer directly. If on CPU and devScratchBuf is provided, performs H2D copy into the scratch buffer. If indexTensor is null, returns count = defaultCount with ptr = nullptr (signaling identity/all-elements to the kernel).
- void resolveViewIndices(const TensorDesc *indexTensor, uint32_t defaultCount, std::vector< uint32_t > &out)
Resolves an index tensor into a list of uint32_t view indices. If indexTensor is null, fills out with [0, 1, …, defaultCount-1]. Writes into the caller-provided vector to avoid per-call allocation. Handles both CPU and GPU source tensors (D2H copy for GPU).
- void safeCudaFree(void *p)
Safely frees a CUDA pointer, clearing any pending error state.
- bool updateInverseInertia(float *inertia, float *inverseInertia, int deviceOrdinal, size_t count)
- bool updateInverseMass(float *mass, float *inverseMass, int deviceOrdinal, size_t count)
Recompute inverse mass/inertia arrays from their forward counterparts. Dispatches to CPU or GPU based on deviceOrdinal (-1 = CPU, >= 0 = GPU).
- bool validateCudaContext(int deviceOrdinal)
Validates that a CUDA context exists for the given device ordinal, creating one if needed.
- bool validateFloat32Tensor(const TensorDesc *tensor, int expectedDevice, size_t expectedElements, const char *tensorName, const char *funcName)
Validates that a tensor is non-null, resides on the expected device, is float32, and has an exact total element count. Logs a descriptive error and returns false on any mismatch.
- bool validateFloat32TensorAnyDevice(const TensorDesc *tensor, size_t expectedElements, const char *tensorName, const char *funcName)
Validates a float32 tensor's dtype and size but allows the tensor to reside on any device. Used by GPU views that internally stage CPU tensors via H2D copy (GC configuration).
- bool validateOptionalIndexTensor(const TensorDesc *indexTensor, int expectedDevice, const char *funcName)
Validates an optional index tensor. If provided, it must reside on the expected device and be int32/uint32. A null/empty index tensor is accepted (identity mapping).
- bool validateOptionalIndexTensorAnyDevice(const TensorDesc *indexTensor, const char *funcName)
Validates an optional index tensor's dtype (int32/uint32) but allows any device. Used by GPU views that internally stage CPU index tensors via H2D copy (GC configuration).
- bool validateUint8Tensor(const TensorDesc *tensor, int expectedDevice, size_t expectedElements, const char *tensorName, const char *funcName)
Validates that a tensor is non-null, resides on the expected device, and has an exact total element count. The data type check is skipped (caller should pick the appropriate variant above when a dtype constraint applies).
- wp::array_t< T > warpArrayFromPython(py::object pyArray)
Extracts a wp::array_t<T> descriptor from a Python wp.array, reading ptr, shape, strides.
Structs Summary#
- GpuIndexGuard
Holds a device-side index pointer and count for GPU kernel dispatch.
- SimViewInit
Initialization data extracted from the Python Newton stage. Produced by BaseSimulationView::initNewton() and consumed by Cpu/GpuSimulationView constructors.