Performance issue when updating PointInstancer

Hello,

I’m running into issues updating an UsdGeom.pointinstancer.
For a reason, the code below hangs on the attr.Set() call.
While it hangs, I can see a single thread of my CPU running at 100%, always the same thread.

    print(ids.shape)
    print(np.isnan(ids).any())
    print(np.isinf(ids).any())
    print(np.max(ids))
    print(np.min(ids))
    convert = Vt.IntArray(ids.tolist())
    print("converted OK")
    attr = instancer_prim.GetAttribute("protoIndices")
    print("Got attribute")
    attr.Set(convert)
    print("Done?")

It outputs:

setting ids
(80002,)
False
False
49
0
converted OK
Got attribute

And holds for up to 2 minutes. The code resumes operation after that as if nothing had happened. I’m a bit confused as to why this would happen. I have already used instancers with way more instances, or points. Any ideas?

This is running in Linux in IsaacSim on a relatively powerful machine, I would not expect any lags for this kind of ops. (32 cores, 64 Gb RAM, 24Gb of VRAM)

Thanks in advance,

Best,

Antoine

For completeness, I have attached the creation/update code for the instancers.
After further debuging I also have a lot of error messages but I’m not quite sure why… (The prims have colliders)

Both are available below, I’m sure I forgot something when instantiating the instancer.

Best,

Antoine

Instancer code:

class Instancer:
    """
    Point instancer.
    """

    def __init__(self, instancer_path: str, assets_path: str, seed: int):
        """
        Args:
            instancer_path (str): The path to the instancer.
            assets_path (str): The path to the assets folder.
            seed (int): The seed for the random number generator.
        """

        self.instancer_path = instancer_path
        self.stage = omni.usd.get_context().get_stage()
        self.assets_path = assets_path
        self.prototypes = []
        self.get_asset_list()
        self.createInstancer()
        self.rng = np.random.default_rng(seed=seed)

    def get_asset_list(self):
        """
        Get the list of assets in the assets folder.
        """

        self.file_paths = [
            os.path.join(self.assets_path, file)
            for file in os.listdir(self.assets_path)
            if file.endswith(".usd")
        ]
        print(self.file_paths)
        print(len(self.file_paths))

    def createInstancer(self):
        """
        Create the instancer.
        """

        self.instancer_path = omni.usd.get_stage_next_free_path(
            self.stage, self.instancer_path, False
        )
        self.instancer_prim = self.stage.DefinePrim(self.instancer_path, "Xform")
        self.instancer = UsdGeom.PointInstancer.Define(self.stage, self.instancer_path)

        for i, file_path in enumerate(self.file_paths):
            prim = self.stage.DefinePrim(
                os.path.join(self.instancer_path, "asset_" + str(i)), "Xform"
            )
            prim.GetReferences().AddReference(file_path)
            self.instancer.GetPrototypesRel().AddTarget(prim.GetPath())

        self.setInstancerParameters(
            np.array([[0, 0, 0]]),
            np.array([[0, 0, 0, 1]]),
            np.array([[1, 1, 1]]),
            np.array([0]),
        )

    def setInstancerParameters(self, positions, orientations, scales, ids):
        """
        Set the instancer parameters.
        """

        print("positions shape", positions.shape)
        print("orientations shape", orientations.shape)
        print("scales shape", scales.shape)
        print("ids shape", ids.shape)
        print("num prototypes rel", len(self.instancer.GetPrototypesRel().GetTargets()))
        start = time.time()
        self.instancer.GetPositionsAttr().Set(positions)
        self.instancer.GetOrientationsAttr().Set(orientations)
        self.instancer.GetScalesAttr().Set(scales)
        self.instancer.GetProtoIndicesAttr().Set(ids)
        end = time.time()
        print("Set instancer parameters took", end - start, "seconds")

Print outputs from code:

positions shape (80002, 3)
orientations shape (80002, 4)
scales shape (80002, 3)
ids shape (80002,)
num prototypes rel 23
Set instancer parameters took 66.27125883102417 seconds

Some of the warnings being raised all the time:

2024-08-25 13:46:31 [13,424ms] [Warning] [omni.usd] Warning: in GetInstanceIndices at line 2190 of /buildAgent/work/ac88d7d902b57417/USD/pxr/usdImaging/usdImaging/pointInstancerAdapter.cpp -- ProtoIndex 5 out of bounds (prototypes size = 1) for (/World/rock_instancers/very_small_rock_instancer, /World/rock_instancers/very_small_rock_instancer.proto5_rock_37_id0)

2024-08-25 13:46:31 [13,424ms] [Warning] [omni.usd] Warning (secondary thread): in GetInstanceIndices at line 2190 of /buildAgent/work/ac88d7d902b57417/USD/pxr/usdImaging/usdImaging/pointInstancerAdapter.cpp -- ProtoIndex 11 out of bounds (prototypes size = 1) for (/World/rock_instancers/large_rock_instancer, /World/rock_instancers/large_rock_instancer.proto11_rock_3_id0)

2024-08-25 13:46:31 [13,424ms] [Warning] [omni.usd] Warning (secondary thread): in GetInstanceIndices at line 2190 of /buildAgent/work/ac88d7d902b57417/USD/pxr/usdImaging/usdImaging/pointInstancerAdapter.cpp -- ProtoIndex 3 out of bounds (prototypes size = 1) for (/World/rock_instancers/large_rock_instancer, /World/rock_instancers/large_rock_instancer.proto3_rock_45_id0)

2024-08-25 13:46:31 [13,424ms] [Warning] [omni.usd] Warning: in GetInstanceIndices at line 3256 of /buildAgent/work/ac88d7d902b57417/USD/pxr/usdImaging/usdImaging/delegate.cpp -- Empty InstanceIndices (/World/rock_instancers/very_small_rock_instancer, /World/rock_instancers/very_small_rock_instancer.proto5_rock_37_id0)


2024-08-25 13:46:31 [13,424ms] [Warning] [omni.usd] Warning (secondary thread): in GetInstanceIndices at line 3256 of /buildAgent/work/ac88d7d902b57417/USD/pxr/usdImaging/usdImaging/delegate.cpp -- Empty InstanceIndices (/World/rock_instancers/large_rock_instancer, /World/rock_instancers/large_rock_instancer.proto3_rock_45_id0)


2024-08-25 13:46:31 [13,424ms] [Warning] [omni.usd] Warning (secondary thread): in GetInstanceIndices at line 2190 of /buildAgent/work/ac88d7d902b57417/USD/pxr/usdImaging/usdImaging/pointInstancerAdapter.cpp -- ProtoIndex 5 out of bounds (prototypes size = 1) for (/World/rock_instancers/large_rock_instancer, /World/rock_instancers/large_rock_instancer.proto5_rock_37_id0)

2024-08-25 13:46:31 [13,424ms] [Warning] [omni.usd] Warning (secondary thread): in GetInstanceIndices at line 3256 of /buildAgent/work/ac88d7d902b57417/USD/pxr/usdImaging/usdImaging/delegate.cpp -- Empty InstanceIndices (/World/rock_instancers/large_rock_instancer, /World/rock_instancers/large_rock_instancer.proto11_rock_3_id0)


2024-08-25 13:46:31 [13,424ms] [Warning] [omni.usd] Warning (secondary thread): in GetInstanceIndices at line 2190 of /buildAgent/work/ac88d7d902b57417/USD/pxr/usdImaging/usdImaging/pointInstancerAdapter.cpp -- ProtoIndex 20 out of bounds (prototypes size = 1) for (/World/rock_instancers/large_rock_instancer, /World/rock_instancers/large_rock_instancer.proto20_rock_21_id0)

2024-08-25 13:46:31 [13,424ms] [Warning] [omni.usd] Warning (secondary thread): in GetInstanceIndices at line 2190 of /buildAgent/work/ac88d7d902b57417/USD/pxr/usdImaging/usdImaging/pointInstancerAdapter.cpp -- ProtoIndex 1 out of bounds (prototypes size = 1) for (/World/rock_instancers/very_small_rock_instancer, /World/rock_instancers/very_small_rock_instancer.proto1_rock_17_id0)

2024-08-25 13:46:31 [13,424ms] [Warning] [omni.usd] Warning (secondary thread): in GetInstanceIndices at line 2190 of /buildAgent/work/ac88d7d902b57417/USD/pxr/usdImaging/usdImaging/pointInstancerAdapter.cpp -- ProtoIndex 4 out of bounds (prototypes size = 1) for (/World/rock_instancers/very_small_rock_instancer, /World/rock_instancers/very_small_rock_instancer.proto4_rock_48_id0)

2024-08-25 13:46:31 [13,424ms] [Warning] [omni.usd] Warning (secondary thread): in GetInstanceIndices at line 2190 of /buildAgent/work/ac88d7d902b57417/USD/pxr/usdImaging/usdImaging/pointInstancerAdapter.cpp -- ProtoIndex 17 out of bounds (prototypes size = 1) for (/World/rock_instancers/very_small_rock_instancer, /World/rock_instancers/very_small_rock_instancer.proto17_rock_31_id0)

2024-08-25 13:46:31 [13,424ms] [Warning] [omni.usd] Warning (secondary thread): in GetInstanceIndices at line 2190 of /buildAgent/work/ac88d7d902b57417/USD/pxr/usdImaging/usdImaging/pointInstancerAdapter.cpp -- ProtoIndex 1 out of bounds (prototypes size = 1) for (/World/rock_instancers/large_rock_instancer, /World/rock_instancers/large_rock_instancer.proto1_rock_17_id0)

2024-08-25 13:46:31 [13,424ms] [Warning] [omni.usd] Warning (secondary thread): in GetInstanceIndices at line 2190 of /buildAgent/work/ac88d7d902b57417/USD/pxr/usdImaging/usdImaging/pointInstancerAdapter.cpp -- ProtoIndex 14 out of bounds (prototypes size = 1) for (/World/rock_instancers/very_small_rock_instancer, /World/rock_instancers/very_small_rock_instancer.proto14_rock_13_id0)

2024-08-25 13:46:31 [13,424ms] [Warning] [omni.hydra.scene_delegate.plugin] Calling getBypassRenderSkelMeshProcessing for prim /World/rock_instancers/large_rock_instancer.proto3_rock_45_id0 that has not been populated
2024-08-25 13:46:31 [13,424ms] [Warning] [omni.usd] Warning (secondary thread): in GetInstanceIndices at line 3256 of /buildAgent/work/ac88d7d902b57417/USD/pxr/usdImaging/usdImaging/delegate.cpp -- Empty InstanceIndices (/World/rock_instancers/very_small_rock_instancer, /World/rock_instancers/very_small_rock_instancer.proto4_rock_48_id0)

Given that there are omni.usd warnings in your output, this may be an issue in the Omniverse rendering pipeline. If you run the same script in usdview, what are the results?

For help with IsaacSim, are you able to post your entire repro along with minimal assets in Isaac Sim - NVIDIA Developer Forums ? Thanks~

Hi, it was an issue with the physx. I got around it by modifying my assets, it’s a lot faster now :).

1 Like