Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
13 changes: 7 additions & 6 deletions doc/source/ray-core/scheduling/accelerators.rst
Original file line number Diff line number Diff line change
Expand Up @@ -79,10 +79,11 @@ If you need to, you can :ref:`override <specify-node-resources>` this.

.. tip::

You can set the ``ONEAPI_DEVICE_SELECTOR`` environment variable before starting a Ray node
You can set the ``ZE_AFFINITY_MASK`` environment variable before starting a Ray node
to limit the Intel GPUs that are visible to Ray.
For example, ``ONEAPI_DEVICE_SELECTOR=1,3 ray start --head --num-gpus=2``
For example, ``ZE_AFFINITY_MASK=1,3 ray start --head --num-gpus=2``
lets Ray only see devices 1 and 3.
``ONEAPI_DEVICE_SELECTOR`` is still read as a fallback for backward compatibility.

.. tab-item:: AWS Neuron Core
:sync: AWS Neuron Core
Expand Down Expand Up @@ -282,12 +283,12 @@ and assign accelerators to the task or actor by setting the corresponding enviro
class GPUActor:
def ping(self):
print("GPU IDs: {}".format(ray.get_runtime_context().get_accelerator_ids()["GPU"]))
print("ONEAPI_DEVICE_SELECTOR: {}".format(os.environ["ONEAPI_DEVICE_SELECTOR"]))
print("ZE_AFFINITY_MASK: {}".format(os.environ["ZE_AFFINITY_MASK"]))

@ray.remote(num_gpus=1)
def gpu_task():
print("GPU IDs: {}".format(ray.get_runtime_context().get_accelerator_ids()["GPU"]))
print("ONEAPI_DEVICE_SELECTOR: {}".format(os.environ["ONEAPI_DEVICE_SELECTOR"]))
print("ZE_AFFINITY_MASK: {}".format(os.environ["ZE_AFFINITY_MASK"]))

gpu_actor = GPUActor.remote()
ray.get(gpu_actor.ping.remote())
Expand All @@ -298,9 +299,9 @@ and assign accelerators to the task or actor by setting the corresponding enviro
:options: +MOCK

(GPUActor pid=52420) GPU IDs: [0]
(GPUActor pid=52420) ONEAPI_DEVICE_SELECTOR: 0
(GPUActor pid=52420) ZE_AFFINITY_MASK: 0
(gpu_task pid=51830) GPU IDs: [1]
(gpu_task pid=51830) ONEAPI_DEVICE_SELECTOR: 1
(gpu_task pid=51830) ZE_AFFINITY_MASK: 1

.. tab-item:: AWS Neuron Core
:sync: AWS Neuron Core
Expand Down
1 change: 1 addition & 0 deletions doc/source/serve/llm/user-guides/sglang.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ Set the following environment variable before running any example:

- **CUDA:** `RAY_EXPERIMENTAL_NOSET_CUDA_VISIBLE_DEVICES=0`
- **ROCm:** `RAY_EXPERIMENTAL_NOSET_HIP_VISIBLE_DEVICES=0`
- **Intel GPU:** `RAY_EXPERIMENTAL_NOSET_ZE_AFFINITY_MASK=0`

## Online serving (single node)

Expand Down
2 changes: 1 addition & 1 deletion java/dependencies.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ def gen_java_deps():
artifacts = [
"com.fasterxml.jackson.core:jackson-databind:2.18.8",
"com.github.java-json-tools:json-schema-validator:2.2.14",
"com.google.code.gson:gson:2.9.1",
"com.google.code.gson:gson:2.11.0",
"com.google.guava:guava:32.0.1-jre",
"com.google.protobuf:protobuf-java:3.23.4",
"com.google.protobuf:protobuf-java-util:3.23.4",
Expand Down
44 changes: 27 additions & 17 deletions python/ray/_private/accelerators/intel_gpu.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,10 @@

logger = logging.getLogger(__name__)

ZE_AFFINITY_MASK_ENV_VAR = "ZE_AFFINITY_MASK"
NOSET_ZE_AFFINITY_MASK_ENV_VAR = "RAY_EXPERIMENTAL_NOSET_ZE_AFFINITY_MASK"

ONEAPI_DEVICE_SELECTOR_ENV_VAR = "ONEAPI_DEVICE_SELECTOR"
NOSET_ONEAPI_DEVICE_SELECTOR_ENV_VAR = "RAY_EXPERIMENTAL_NOSET_ONEAPI_DEVICE_SELECTOR"
ONEAPI_DEVICE_BACKEND_TYPE = "level_zero"
ONEAPI_DEVICE_TYPE = "gpu"

Expand All @@ -22,25 +24,29 @@ def get_resource_name() -> str:

@staticmethod
def get_visible_accelerator_ids_env_var() -> str:
return ONEAPI_DEVICE_SELECTOR_ENV_VAR
return ZE_AFFINITY_MASK_ENV_VAR

@staticmethod
def get_current_process_visible_accelerator_ids() -> Optional[List[str]]:
oneapi_visible_devices = os.environ.get(
IntelGPUAcceleratorManager.get_visible_accelerator_ids_env_var(), None
)
# Primary: ZE_AFFINITY_MASK uses bare IDs ("0,1,2"), like CUDA_VISIBLE_DEVICES.
ze_mask = os.environ.get(ZE_AFFINITY_MASK_ENV_VAR, None)
if ze_mask is not None:
if ze_mask == "":
return []
return list(ze_mask.split(","))

# Fallback: ONEAPI_DEVICE_SELECTOR for backward compatibility.
oneapi_visible_devices = os.environ.get(ONEAPI_DEVICE_SELECTOR_ENV_VAR, None)
if oneapi_visible_devices is None:
return None

if oneapi_visible_devices == "":
return []

if oneapi_visible_devices == "NoDevFiles":
if oneapi_visible_devices == "" or oneapi_visible_devices == "NoDevFiles":
return []

prefix = ONEAPI_DEVICE_BACKEND_TYPE + ":"

return list(oneapi_visible_devices.split(prefix)[1].split(","))
if prefix in oneapi_visible_devices:
return list(oneapi_visible_devices.split(prefix)[1].split(","))
# bare IDs without prefix (e.g. "0,1") — accepted as-is
return list(oneapi_visible_devices.split(","))

@staticmethod
def get_current_node_num_accelerators() -> int:
Expand Down Expand Up @@ -95,10 +101,14 @@ def validate_resource_request_quantity(
def set_current_process_visible_accelerator_ids(
visible_xpu_devices: List[str],
) -> None:
if env_bool(NOSET_ONEAPI_DEVICE_SELECTOR_ENV_VAR, False):
if env_bool(NOSET_ZE_AFFINITY_MASK_ENV_VAR, False):
return

prefix = ONEAPI_DEVICE_BACKEND_TYPE + ":"
os.environ[
IntelGPUAcceleratorManager.get_visible_accelerator_ids_env_var()
] = prefix + ",".join([str(i) for i in visible_xpu_devices])
# ZE_AFFINITY_MASK masks devices at the Level Zero driver, below oneAPI/SYCL
# and torch-xpu, so it fully restricts visibility on its own. It uses bare
# IDs ("0,1,2") like CUDA_VISIBLE_DEVICES. Ray only sets this one env var:
# writing ONEAPI_DEVICE_SELECTOR too would collide with frameworks (e.g.
# SGLang) that manage it themselves, and would need a separate save/restore.
os.environ[ZE_AFFINITY_MASK_ENV_VAR] = ",".join(
[str(i) for i in visible_xpu_devices]
)
Loading
Loading