---
name: "hwloc_opencl_get_device_osdev"
section: "3"
platform: "linux"
package: "hwloc"
version: "2.15.0-1"
release: "Arch Linux 2026-11-01"
platforms: ["linux"]
url: "https://new.carta.tech/hwlocality_opencl"
---

# hwloc\_opencl\_get\_device\_osdev(3)

Interoperability with OpenCL

Part of [hwlocality\_opencl(3)](/hwlocality_opencl/3.md).

## NAME

hwlocality\_opencl - Interoperability with OpenCL

## SYNOPSIS

### Functions

int **hwloc\_opencl\_get\_device\_pci\_busid** (cl\_device\_id device, unsigned \*domain, unsigned \*bus, unsigned \*dev, unsigned \*func)\
 int **hwloc\_opencl\_get\_device\_cpuset** (**hwloc\_topology\_t** topology, cl\_device\_id device, **hwloc\_cpuset\_t** set)\
 **hwloc\_obj\_t** **hwloc\_opencl\_get\_device\_osdev\_by\_index** (**hwloc\_topology\_t** topology, unsigned platform\_index, unsigned device\_index)\
 **hwloc\_obj\_t** **hwloc\_opencl\_get\_device\_osdev** (**hwloc\_topology\_t** topology, cl\_device\_id device)\

## Detailed Description

This interface offers ways to retrieve topology information about OpenCL devices.

Only AMD and NVIDIA OpenCL implementations currently offer useful locality information about their devices.

## Function Documentation

### int hwloc\_opencl\_get\_device\_cpuset (hwloc\_topology\_t topology, cl\_device\_id device, hwloc\_cpuset\_t set) \[inline\]

Get the CPU set of processors that are physically close to OpenCL device device. Store in set the CPU-set describing the locality of the OpenCL device device.

Topology topology and device device must match the local machine. I/O devices detection and the OpenCL component are not needed in the topology.

The function only returns the locality of the device. If more information about the device is needed, OS objects should be used instead, see **hwloc\_opencl\_get\_device\_osdev()** and **hwloc\_opencl\_get\_device\_osdev\_by\_index()**.

This function is currently only implemented in a meaningful way for Linux with the AMD or NVIDIA OpenCL implementation; other systems will simply get the cpuset of the entire topology.

**Returns**

0 on success.

\-1 on error, for instance if the device could not be found.

### hwloc\_obj\_t hwloc\_opencl\_get\_device\_osdev (hwloc\_topology\_t topology, cl\_device\_id device) \[inline\]

Get the hwloc OS device object corresponding to OpenCL device deviceX.

**Returns**

The hwloc OS device object corresponding to the given OpenCL device device.

NULL if none could be found, for instance if required OpenCL attributes are not available.

This function currently only works on AMD and NVIDIA OpenCL devices that support relevant OpenCL extensions. **hwloc\_opencl\_get\_device\_osdev\_by\_index()** should be preferred whenever possible, i.e. when platform and device index are known.

Topology topology and device device must match the local machine. I/O devices detection and the OpenCL component must be enabled in the topology. If not, the locality of the object may still be found using **hwloc\_opencl\_get\_device\_cpuset()**.

**Note**

This function cannot work if PCI devices are filtered out.

The corresponding hwloc PCI device may be found by looking at the result parent pointer (unless PCI devices are filtered out).

### hwloc\_obj\_t hwloc\_opencl\_get\_device\_osdev\_by\_index (hwloc\_topology\_t topology, unsigned platform\_index, unsigned device\_index) \[inline\]

Get the hwloc OS device object corresponding to the OpenCL device for the given indexes.

**Returns**

The hwloc OS device object describing the OpenCL device whose platform index is platform\_index, and whose device index within this platform if device\_index.

NULL if there is none.

The topology topology does not necessarily have to match the current machine. For instance the topology may be an XML import of a remote host. I/O devices detection and the OpenCL component must be enabled in the topology.

**Note**

The corresponding PCI device object can be obtained by looking at the OS device parent object (unless PCI devices are filtered out).

### int hwloc\_opencl\_get\_device\_pci\_busid (cl\_device\_id device, unsigned \* domain, unsigned \* bus, unsigned \* dev, unsigned \* func) \[inline\]

Return the domain, bus and device IDs of the OpenCL device device. Device device must match the local machine.

**Returns**

0 on success.

\-1 on error, for instance if device information could not be found.

## Author

Generated automatically by Doxygen for Hardware Locality (hwloc) from the source code.
