1#ifndef helperfunctions_h
2#define helperfunction_h
13#include "cuda_runtime_api.h"
18inline int topo_get_numNode(
int GPU_rank)
23 int pciBus, pciDomain, pciDevice;
24 cudaDeviceGetAttribute(&pciBus, cudaDevAttrPciBusId, GPU_rank);
25 cudaDeviceGetAttribute(&pciDevice, cudaDevAttrPciDeviceId, GPU_rank);
26 cudaDeviceGetAttribute(&pciDomain, cudaDevAttrPciDomainId, GPU_rank);
32 int ret = snprintf(fname, 1023,
"/sys/bus/pci/devices/0000:%02x:%02x.%1x/numa_node", pciBus, pciDevice, pciDomain);
36 FILE* fp = fopen(fname,
"r");
39 ret = fread(buff,
sizeof(
char), 99, fp);
40 int numaNodeID = atoi(buff);
52inline int read_numa_threads(
int numa_node,
int** hwthread_list)
55 int total_hwthreads = sysconf(_SC_NPROCESSORS_CONF);
57 int* cpulist =
new int[total_hwthreads];
63 for (
int i = 0; i < total_hwthreads; i++)
65 int ret = snprintf(path, 1023,
"/sys/devices/system/node/node%d/cpu%d", numa_node, i);
66 if (!access(path, F_OK))
69 printf(
"HWthread %d located in NUMA domain %d\n", i, numa_node);
71 cpulist[cpuidx++] = i;
74 *hwthread_list = cpulist;
76 printf(
"NUMA domain %d has %d HWThreads\n", numa_node, cpuidx);
82inline int pin_hwthreads(
int count,
int* hwthread_list)
89 for (
int i = 0; i < count; i++)
91 CPU_SET(hwthread_list[i], &cpuset);
93 printf(
" %d", hwthread_list[i]);
99 return sched_setaffinity(0,
sizeof(cpu_set_t), &cpuset);