Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
8a35c7f
Computing the distance between two objects based on their object orie…
Lucaweihs Apr 5, 2022
9284465
Handling case where no BoundingBox object was assigned in the editor.
Lucaweihs Apr 6, 2022
5e3ddcc
Adding CheckUnobstructedPathBetweenObjectCenters method to check adja…
Lucaweihs Apr 7, 2022
536d771
Adding CheckWhatObjectOn and CheckWhatObjectsOn methods to check what…
Lucaweihs Apr 7, 2022
e65fb1e
Simplifying code reporting which objects an agent is touching with th…
Lucaweihs Apr 7, 2022
807c67b
Merge branch 'nanna-culling' of github.com:allenai/ai2thor into bbox_…
Lucaweihs Apr 21, 2022
4454e5f
Removing redundant code from stretch robot controller (similarly as w…
Lucaweihs Apr 21, 2022
fd09cc7
Fixing a bug in the `PointOnObjectsCollidersClosestToPoint` action wh…
Lucaweihs Apr 22, 2022
123c428
Merge branch 'nanna-culling' of github.com:allenai/ai2thor into bbox_…
Lucaweihs Apr 25, 2022
852177d
Merge branch 'nanna' into bbox_distance
mattdeitke Apr 29, 2022
f58eb5d
Merge branch 'nanna' of github.com:allenai/ai2thor into bbox_distance
Lucaweihs May 16, 2022
dcd14d7
Merge branch 'bbox_distance' of github.com:allenai/ai2thor into bbox_…
Lucaweihs May 16, 2022
dd162d0
Merge branch 'nanna' into bbox_distance
mattdeitke May 27, 2022
f9de6c0
Adding `#if UNITY_EDITOR` block around debug print statement.
Lucaweihs May 31, 2022
55ded55
Merge branch 'bbox_distance' of github.com:allenai/ai2thor into bbox_…
Lucaweihs May 31, 2022
88d7c99
Merge branch 'bbox_distance' into nanna-bboxdist
Lucaweihs May 31, 2022
82097ea
Sorting object ids rather than sim objects.
Lucaweihs Jun 1, 2022
28692f1
Merge branch 'nanna' of github.com:allenai/ai2thor into nanna-bboxdist
Lucaweihs Aug 17, 2022
0b1f85f
Format change to prompt new build.
Lucaweihs Aug 17, 2022
34e9162
Fixing LGTM message and adding pitch/roll to RotateWristRelative of s…
Lucaweihs Aug 18, 2022
8e70929
Adding a public `GetVisibleObjects` function to mirror `ObjectsVisibl…
Lucaweihs Aug 18, 2022
69da492
Fix bug where GetAllVisibleSimObjPhysicsDistance ignored the maxDista…
Lucaweihs Aug 26, 2022
39c5873
Tiny change to prompt build.
Lucaweihs Aug 31, 2022
8708ebe
Adding function to get metadata for a set of given object ids.
Lucaweihs Sep 12, 2022
35400bf
Fixing merge conflict with nanna
Lucaweihs Sep 12, 2022
01c3d9c
Fixing which objects are being filtered by.
Lucaweihs Sep 12, 2022
663dd36
Reverting gpu relabeling for CloudRendering. This relabeling no longe…
Lucaweihs Sep 14, 2022
14c5a8f
Updating code used to map vulkan GPU indices to cuda devices. This is…
Lucaweihs Sep 15, 2022
267c483
Minor fix to gpu remapping code.
Lucaweihs Sep 15, 2022
d16b3df
Fixing apt install suggestion.
Lucaweihs Sep 15, 2022
7f0c32f
Apparently subprocess.run(...) can throw a FileNotFoundException.
Lucaweihs Sep 16, 2022
5676b78
Addressing PR comments.
Lucaweihs Sep 28, 2022
34489ea
Merge branch 'nanna' of github.com:allenai/ai2thor into nanna-bboxdist
Lucaweihs Sep 28, 2022
55ccf96
Fixing wrong comment character.
Lucaweihs Sep 28, 2022
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 80 additions & 6 deletions ai2thor/controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -1029,12 +1029,86 @@ def unity_command(self, width, height, headless):

if self.gpu_device is not None:
# This parameter only applies to the CloudRendering platform.
# Vulkan maps the passed in parameter to device-index - 1 when compared
# to the nvidia-smi device ids
device_index = (
self.gpu_device if self.gpu_device < 1 else self.gpu_device + 1
)
command += " -force-device-index %d" % device_index
# Vulkan device ids need not correspond to CUDA device ids. The below
# code finds the device_uuids for each GPU and then figures out the mapping
# between the CUDA device ids and the Vulkan device ids.

cuda_vulkan_mapping_path = os.path.join(self.base_dir, "cuda-vulkan-mapping.json")
with LockEx(cuda_vulkan_mapping_path):
if not os.path.exists(cuda_vulkan_mapping_path):
vulkan_result = None
try:
vulkan_result = subprocess.run(
["vulkaninfo"],
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL,
universal_newlines=True
)
except FileNotFoundError:
pass
if vulkan_result is None or vulkan_result.returncode != 0:
raise RuntimeError(
"vulkaninfo failed to run, please ask your administrator to"
" install `vulkaninfo` (e.g. on Ubuntu systems this requires running"
" `sudo apt install vulkan-tools`)."
)

current_gpu = None
device_uuid_to_vulkan_gpu_index = {}
for l in vulkan_result.stdout.splitlines():
gpu_match = re.match("GPU([0-9]+):", l)
if gpu_match is not None:
current_gpu = int(gpu_match.group(1))
elif "deviceUUID" in l:
device_uuid = l.split("=")[1].strip()
if device_uuid in device_uuid_to_vulkan_gpu_index:
assert current_gpu == device_uuid_to_vulkan_gpu_index[device_uuid]
else:
device_uuid_to_vulkan_gpu_index[device_uuid] = current_gpu

nvidiasmi_result = None
try:
nvidiasmi_result = subprocess.run(
["nvidia-smi", "-L"],
stdout=subprocess.PIPE,
stderr=subprocess.DEVNULL,
universal_newlines=True
)
except FileNotFoundError:
pass
if nvidiasmi_result is None or nvidiasmi_result.returncode != 0:
raise RuntimeError(
"`nvidia-smi` failed to run. To use CloudRendering, please ensure you have nvidia GPUs"
" installed."
)

nvidia_gpu_index_to_device_uuid = {}
for l in nvidiasmi_result.stdout.splitlines():
gpu_match = re.match("GPU ([0-9]+):", l)
if gpu_match is None:
continue

current_gpu = int(gpu_match.group(1))
uuid_match = re.match(".*\\(UUID: GPU-([^)]+)\\)", l)
nvidia_gpu_index_to_device_uuid[current_gpu] = uuid_match.group(1)

cuda_vulkan_mapping = {}
for cuda_gpu_index, device_uuid in nvidia_gpu_index_to_device_uuid.items():
if device_uuid not in device_uuid_to_vulkan_gpu_index:
raise RuntimeError(
f"Could not find a Vulkan device corresponding"
f" to the CUDA device with UUID {device_uuid}."
)
cuda_vulkan_mapping[cuda_gpu_index] = device_uuid_to_vulkan_gpu_index[device_uuid]

with open(cuda_vulkan_mapping_path, "w") as f:
json.dump(cuda_vulkan_mapping, f)
else:
with open(cuda_vulkan_mapping_path, "r") as f:
# JSON dictionaries always have strings as keys, need to re-map here
cuda_vulkan_mapping = {int(k):v for k, v in json.load(f).items()}

command += f" -force-device-index {cuda_vulkan_mapping[self.gpu_device]}"

return shlex.split(command)

Expand Down
136 changes: 71 additions & 65 deletions ai2thor/tests/test_controller.py
Original file line number Diff line number Diff line change
Expand Up @@ -438,72 +438,78 @@ def test_last_action(mocker):
assert e.metadata["lastActionSuccess"]

def test_unity_command_force_device_index(mocker):
mocker.patch("ai2thor.controller.platform_system", fake_linux_system)
mocker.patch("ai2thor.controller.ai2thor.build.Build.exists", fake_exists)
mocker.patch("ai2thor.controller.ai2thor.build.Build.download", noop_download)
mocker.patch("ai2thor.controller.ai2thor.platform.select_platforms", select_platforms_linux_cr)
mocker.patch(
"ai2thor.controller.ai2thor.platform.CloudRendering.validate", fake_validate
)
mocker.patch(
"ai2thor.controller.ai2thor.platform.Linux64.validate",
fake_invalid_linux64_validate,
)

mocker.patch("ai2thor.platform.CloudRendering.enabled", True)
original_visible_devices = os.environ.get("CUDA_VISIBLE_DEVICES")
try:
os.environ["CUDA_VISIBLE_DEVICES"] = "2,3,4"

c = controller(platform=CloudRendering, gpu_device=1)
assert c.unity_command(650, 550, False) == [
c._build.executable_path,
"-screen-fullscreen",
"0",
"-screen-quality",
"7",
"-screen-width",
"650",
"-screen-height",
"550",
'-force-device-index',
'4'
]
finally:
if original_visible_devices:
os.environ["CUDA_VISIBLE_DEVICES"] = original_visible_devices
else:
del os.environ["CUDA_VISIBLE_DEVICES"]

c = controller(platform=CloudRendering, gpu_device=5)
assert c.unity_command(650, 550, False) == [
c._build.executable_path,
"-screen-fullscreen",
"0",
"-screen-quality",
"7",
"-screen-width",
"650",
"-screen-height",
"550",
'-force-device-index',
'6'
]
pass

c = controller(platform=CloudRendering, gpu_device=0)
assert c.unity_command(650, 550, False) == [
c._build.executable_path,
"-screen-fullscreen",
"0",
"-screen-quality",
"7",
"-screen-width",
"650",
"-screen-height",
"550",
'-force-device-index',
'0'
]
# TODO: this test is no longer valid as the mapping between CUDA/Vulkan
# devices and CUDA devices is more arbitrary than we first believed.
# We should find a way to test this in a more robust way.

# mocker.patch("ai2thor.controller.platform_system", fake_linux_system)
# mocker.patch("ai2thor.controller.ai2thor.build.Build.exists", fake_exists)
# mocker.patch("ai2thor.controller.ai2thor.build.Build.download", noop_download)
# mocker.patch("ai2thor.controller.ai2thor.platform.select_platforms", select_platforms_linux_cr)
# mocker.patch(
# "ai2thor.controller.ai2thor.platform.CloudRendering.validate", fake_validate
# )
# mocker.patch(
# "ai2thor.controller.ai2thor.platform.Linux64.validate",
# fake_invalid_linux64_validate,
# )
#
# mocker.patch("ai2thor.platform.CloudRendering.enabled", True)
# original_visible_devices = os.environ.get("CUDA_VISIBLE_DEVICES")
# try:
# os.environ["CUDA_VISIBLE_DEVICES"] = "2,3,4"
#
# c = controller(platform=CloudRendering, gpu_device=1)
# assert c.unity_command(650, 550, False) == [
# c._build.executable_path,
# "-screen-fullscreen",
# "0",
# "-screen-quality",
# "7",
# "-screen-width",
# "650",
# "-screen-height",
# "550",
# '-force-device-index',
# '4'
# ]
# finally:
# if original_visible_devices:
# os.environ["CUDA_VISIBLE_DEVICES"] = original_visible_devices
# else:
# del os.environ["CUDA_VISIBLE_DEVICES"]
#
# c = controller(platform=CloudRendering, gpu_device=5)
# assert c.unity_command(650, 550, False) == [
# c._build.executable_path,
# "-screen-fullscreen",
# "0",
# "-screen-quality",
# "7",
# "-screen-width",
# "650",
# "-screen-height",
# "550",
# '-force-device-index',
# '6'
# ]
#
# c = controller(platform=CloudRendering, gpu_device=0)
# assert c.unity_command(650, 550, False) == [
# c._build.executable_path,
# "-screen-fullscreen",
# "0",
# "-screen-quality",
# "7",
# "-screen-width",
# "650",
# "-screen-height",
# "550",
# '-force-device-index',
# '0'
# ]



Expand Down
3 changes: 3 additions & 0 deletions unity/Assets/Scripts/AgentManager.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1558,6 +1558,9 @@ public class ArmMetadata {
// all sim objects that are both pickupable and inside the hand sphere
public List<String> pickupableObjects;

// all sim objects that are inside the hand sphere, excluding those currently held
public List<String> touchedNotHeldObjects;

// world coordinates of the center of the hand's sphere
public Vector3 handSphereCenter;

Expand Down
Loading