OpenMPI 0.1.1

- Main Page
- Related Pages
- Modules
- Data Structures
- Files

- File List
- Globals

cudart.h
Go to the documentation of this file.
1 /*
2 * Copyright © 2010 inria. All rights reserved.
3 * Copyright © 2010 Université Bordeaux 1
4 * Copyright © 2011 Cisco Systems, Inc. All rights reserved.
5 * See COPYING in top-level directory.
6 */
7
8 /** \file
9 * \brief Macros to help interaction between hwloc and the CUDA Runtime API.
10 *
11 * Applications that use both hwloc and the CUDA Runtime API may want to
12 * include this file so as to get topology information for CUDA devices.
13 *
14 */
15
16 #ifndef HWLOC_CUDART_H
17 #define HWLOC_CUDART_H
18
19 #include <hwloc.h>
20 #include <hwloc/autogen/config.h>
21 #include <hwloc/linux.h>
22
23 #include <cuda_runtime_api.h>
24
25
26 #ifdef __cplusplus
27 extern "C" {
28 #endif
29
30
31 /** \defgroup hwlocality_cudart CUDA Runtime API Specific Functions
32 * @{
33 */
34
35 /** \brief Get the CPU set of logical processors that are physically
36 * close to device \p cudevice.
37 *
38 * For the given CUDA Runtime API device \p cudevice, read the corresponding
39 * kernel-provided cpumap file and return the corresponding CPU set.
40 * This function is currently only implemented in a meaningful way for
41 * Linux; other systems will simply get a full cpuset.
42 */
43 static __hwloc_inline int
44 hwloc_cudart_get_device_cpuset(hwloc_topology_t topology __hwloc_attribute_unused,
45 int device, hwloc_cpuset_t set)
46 {
47 #ifdef HWLOC_LINUX_SYS
48 /* If we're on Linux, use the sysfs mechanism to get the local cpus */
49 #define HWLOC_CUDART_DEVICE_SYSFS_PATH_MAX 128
50 cudaError_t cerr;
51 struct cudaDeviceProp prop;
52 char path[HWLOC_CUDART_DEVICE_SYSFS_PATH_MAX];
53 FILE *sysfile = NULL;
54 int pciDomainID = 0;
55
56 cerr = cudaGetDeviceProperties(&prop, device);
57 if (cerr) {
58 errno = ENOSYS;
59 return -1;
60 }
61
62 #if CUDART_VERSION >= 4000
63 pciDomainID = prop.pciDomainID;
64 #endif
65
66 sprintf(path, "/sys/bus/pci/devices/%04x:%02x:%02x.0/local_cpus", pciDomainID, prop.pciBusID, prop.pciDeviceID);
67 sysfile = fopen(path, "r");
68 if (!sysfile)
69 return -1;
70
71 hwloc_linux_parse_cpumap_file(sysfile, set);
72
73 fclose(sysfile);
74 #else
75 /* Non-Linux systems simply get a full cpuset */
76 hwloc_bitmap_copy(set, hwloc_topology_get_complete_cpuset(topology));
77 #endif
78 return 0;
79 }
80
81 /** @} */
82
83
84 #ifdef __cplusplus
85 } /* extern "C" */
86 #endif
87
88
89 #endif /* HWLOC_CUDART_H */
hwloc_bitmap_copy
HWLOC_DECLSPEC void hwloc_bitmap_copy(hwloc_bitmap_t dst, hwloc_const_bitmap_t src)
Copy the contents of bitmap src into the already allocated bitmap dst.
hwloc_cudart_get_device_cpuset
static __hwloc_inline int hwloc_cudart_get_device_cpuset(hwloc_topology_t topology __hwloc_attribute_unused, int device, hwloc_cpuset_t set)
Get the CPU set of logical processors that are physically close to device cudevice.
Definition: cudart.h:44
hwloc_topology_get_complete_cpuset
static __hwloc_inline hwloc_const_cpuset_t __hwloc_attribute_pure hwloc_topology_get_complete_cpuset(hwloc_topology_t topology)
Get complete CPU set.
Definition: helper.h:729
linux.h
Macros to help interaction between hwloc and Linux.
hwloc_linux_parse_cpumap_file
HWLOC_DECLSPEC int hwloc_linux_parse_cpumap_file(FILE *file, hwloc_cpuset_t set)
Convert a linux kernel cpumap file file into hwloc CPU set.
Definition: topology-linux.c:1332
hwloc_topology
Definition: private.h:56
hwloc_bitmap_s
Definition: cpuset.c:38