Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adds throughput benchmarking scripts for different learning workflows #759

Merged
merged 9 commits into from
Aug 2, 2024
3 changes: 0 additions & 3 deletions source/apps/isaaclab.python.headless.kit
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,11 @@ app.version = "4.1.0"
# Omniverse related dependencies #
##################################
[dependencies]
"omni.kit.window.title" = {}
"omni.physx" = {}
"omni.physx.tensors" = {}
"omni.physx.fabric" = {}
"omni.warp.core" = {}
"usdrt.scenegraph" = {}
"omni.kit.primitive.mesh" = {}
"omni.kit.mainwindow" = {}
"omni.kit.telemetry" = {}


Expand Down
3 changes: 3 additions & 0 deletions source/apps/isaaclab.python.headless.rendering.kit
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ rtx-transient.dlssg.enabled = false
rtx.sceneDb.ambientLightIntensity = 1.0
rtx.directLighting.sampledLighting.enabled = true

# Avoids unnecessary GPU context initialization
renderer.multiGpu.maxGpuCount=1

# Force synchronous rendering to improve training results
omni.replicator.asyncRendering = false

Expand Down
3 changes: 3 additions & 0 deletions source/apps/isaaclab.python.kit
Original file line number Diff line number Diff line change
Expand Up @@ -182,6 +182,9 @@ rtx.newDenoiser.enabled = true
# Enable Iray and pxr by setting this to "rtx,iray,pxr"
renderer.enabled = "rtx"

# Avoids unnecessary GPU context initialization
renderer.multiGpu.maxGpuCount=1

### async rendering settings
omni.replicator.asyncRendering = false
app.asyncRendering = false
Expand Down
3 changes: 3 additions & 0 deletions source/apps/isaaclab.python.rendering.kit
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,9 @@ rtx-transient.dlssg.enabled = false
rtx.sceneDb.ambientLightIntensity = 1.0
rtx.directLighting.sampledLighting.enabled = true

# Avoids unnecessary GPU context initialization
renderer.multiGpu.maxGpuCount=1

# Force synchronous rendering to improve training results
omni.replicator.asyncRendering = false

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -464,6 +464,16 @@ def _config_resolution(self, launcher_args: dict):
if distributed_train:
self.device_id = self.local_rank
launcher_args["multi_gpu"] = False
# limit CPU threads to minimize thread context switching
kellyguo11 marked this conversation as resolved.
Show resolved Hide resolved
# this ensures processes do not take up all available threads and fight for resources
num_cpu_cores = os.cpu_count()
num_threads_per_process = num_cpu_cores // int(os.getenv("WORLD_SIZE", 1))
# set environment variables to limit CPU threads
os.environ["PXR_WORK_THREAD_LIMIT"] = str(num_threads_per_process)
os.environ["OPENBLAS_NUM_THREADS"] = str(num_threads_per_process)
# pass command line variable to kit
sys.argv.append(f"--/plugins/carb.tasking.plugin/threadCount={num_threads_per_process}")

# set physics and rendering device
launcher_args["physics_gpu"] = self.device_id
launcher_args["active_gpu"] = self.device_id
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ def __init__(self, cfg: DirectRLEnvCfg, render_mode: str | None = None, **kwargs
carb.log_warn(msg)

# generate scene
with Timer("[INFO]: Time taken for scene creation"):
with Timer("[INFO]: Time taken for scene creation", "scene_creation"):
self.scene = InteractiveScene(self.cfg.scene)
self._setup_scene()
print("[INFO]: Scene manager: ", self.scene)
Expand All @@ -127,7 +127,7 @@ def __init__(self, cfg: DirectRLEnvCfg, render_mode: str | None = None, **kwargs
# note: when started in extension mode, first call sim.reset_async() and then initialize the managers
if builtins.ISAAC_LAUNCHED_FROM_TERMINAL is False:
print("[INFO]: Starting the simulation. This may take a few seconds. Please wait...")
with Timer("[INFO]: Time taken for simulation start"):
with Timer("[INFO]: Time taken for simulation start", "simulation_start"):
self.sim.reset()

# -- event manager used for randomization
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ def __init__(self, cfg: ManagerBasedEnvCfg):
self._sim_step_counter = 0

# generate scene
with Timer("[INFO]: Time taken for scene creation"):
with Timer("[INFO]: Time taken for scene creation", "scene_creation"):
self.scene = InteractiveScene(self.cfg.scene)
print("[INFO]: Scene manager: ", self.scene)

Expand All @@ -125,7 +125,7 @@ def __init__(self, cfg: ManagerBasedEnvCfg):
# note: when started in extension mode, first call sim.reset_async() and then initialize the managers
if builtins.ISAAC_LAUNCHED_FROM_TERMINAL is False:
print("[INFO]: Starting the simulation. This may take a few seconds. Please wait...")
with Timer("[INFO]: Time taken for simulation start"):
with Timer("[INFO]: Time taken for simulation start", "simulation_start"):
self.sim.reset()
# add timeline event to load managers
self.load_managers()
Expand Down
40 changes: 38 additions & 2 deletions source/extensions/omni.isaac.lab/omni/isaac/lab/utils/timer.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@

import time
from contextlib import ContextDecorator
from typing import Any
from typing import Any, ClassVar


class TimerError(Exception):
Expand Down Expand Up @@ -60,14 +60,25 @@ class Timer(ContextDecorator):
Reference: https://gist.github.com/sumeet/1123871
"""

def __init__(self, msg: str | None = None):
timing_info: ClassVar[dict[str, float]] = dict()
"""Dictionary for storing the elapsed time per timer instances globally.

This dictionary logs the timer information. The keys are the names given to the timer class
at its initialization. If no :attr:`name` is passed to the constructor, no time
is recorded in the dictionary.
"""

def __init__(self, msg: str | None = None, name: str | None = None):
"""Initializes the timer.

Args:
msg: The message to display when using the timer
class in a context manager. Defaults to None.
name: The name to use for logging times in a global
dictionary. Defaults to None.
"""
self._msg = msg
self._name = name
self._start_time = None
self._stop_time = None
self._elapsed_time = None
Expand Down Expand Up @@ -118,6 +129,9 @@ def stop(self):
self._elapsed_time = self._stop_time - self._start_time
self._start_time = None

if self._name:
Timer.timing_info[self._name] = self._elapsed_time
kellyguo11 marked this conversation as resolved.
Show resolved Hide resolved

"""
Context managers
"""
Expand All @@ -133,3 +147,25 @@ def __exit__(self, *exc_info: Any):
# print message
if self._msg is not None:
print(self._msg, f": {self._elapsed_time:0.6f} seconds")

"""
Static Methods
"""

@staticmethod
def get_timer_info(name: str) -> float:
"""Retrieves the time logged in the global dictionary
based on name.

Args:
name: Name of the the entry to be retrieved.

Raises:
TimerError: If name doesn't exist in the log.

Returns:
A float containing the time logged if the name exists.
"""
if name not in Timer.timing_info:
raise TimerError(f"Timer {name} does not exist")
return Timer.timing_info.get(name)
Original file line number Diff line number Diff line change
Expand Up @@ -65,12 +65,14 @@
import numpy as np

import omni.isaac.core.utils.prims as prim_utils
import omni.kit
import omni.kit.commands
from omni.isaac.cloner import GridCloner
from omni.isaac.core.materials import PhysicsMaterial, PreviewSurface
from omni.isaac.core.objects import DynamicSphere
from omni.isaac.core.prims import GeometryPrim, RigidPrim, RigidPrimView
from omni.isaac.core.simulation_context import SimulationContext
from omni.isaac.core.utils.extensions import enable_extension
from omni.isaac.core.utils.viewports import set_camera_view

import omni.isaac.lab.sim as sim_utils
Expand All @@ -79,6 +81,8 @@
from omni.isaac.lab.terrains.terrain_importer import TerrainImporter
from omni.isaac.lab.utils.assets import ISAAC_NUCLEUS_DIR

enable_extension("omni.kit.primitive.mesh")


def main():
"""Generates a terrain from isaaclab."""
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,11 +17,13 @@
import unittest

import omni.isaac.core.utils.prims as prim_utils
import omni.kit
import omni.kit.commands
from omni.isaac.cloner import GridCloner
from omni.isaac.core.materials import PhysicsMaterial, PreviewSurface
from omni.isaac.core.objects import DynamicSphere
from omni.isaac.core.prims import GeometryPrim, RigidPrim, RigidPrimView
from omni.isaac.core.utils.extensions import enable_extension

import omni.isaac.lab.terrains as terrain_gen
from omni.isaac.lab.sim import SimulationContext, build_simulation_context
Expand Down Expand Up @@ -260,6 +262,7 @@ def _populate_scene(self, sim: SimulationContext, num_balls: int = 2048, geom_sp
)
else:
# -- Ball geometry
enable_extension("omni.kit.primitive.mesh")
cube_prim_path = omni.kit.commands.execute("CreateMeshPrimCommand", prim_type="Sphere")[1]
prim_utils.move_prim(cube_prim_path, "/World/envs/env_0/ball")
# -- Ball physics
Expand Down
Loading