Skip to content
This repository was archived by the owner on Feb 16, 2023. It is now read-only.

Commit c0b09b4

Browse files
author
Stephanie Labasan
committed
Fix node topology mapping (fixes #30):
- Detect CPU topology using hwloc APIs and filling in array of structs, where the length of the array is the total number of threads. - Create struct to store topology information, including a toggle for correctly mapping a particular thread, core, and socket, to a unique integer. This deprecates CPU_DEV_VER. - Create generic loop iterators for load_socket_batch, load_core_batch, and load_thread_batch. Signed-off-by: Stephanie Labasan <[email protected]>
1 parent e01715e commit c0b09b4

File tree

5 files changed

+164
-133
lines changed

5 files changed

+164
-133
lines changed

CMakeLists.txt

-2
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ cmake_minimum_required(VERSION 2.8)
44
set(CMAKE_C_COMPILER "gcc")
55
set(CMAKE_CXX_COMPILER "g++")
66

7-
set(HWLOC_DIR "" CACHE FILEPATH "path to hwloc installation")
8-
97
# Add -Wall if it is not there already.
108
set(CMAKE_C_FLAGS "${CMAKE_C_FLAGS} -g -Wall -O3")
119

include/msr_core.h

+15
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,21 @@ enum libmsr_batch_op_type_e
129129
BATCH_READ,
130130
};
131131

132+
struct topo
133+
{
134+
struct hwthread *thread_map;
135+
int discontinuous_mapping;
136+
};
137+
138+
struct hwthread
139+
{
140+
int apic_id;
141+
int thread_id;
142+
int core_id;
143+
int socket_id;
144+
int sibling;
145+
};
146+
132147
// Depending on their scope, MSRs can be written to or read from at either the
133148
// socket (aka package/cpu) or core level, and possibly the hardware thread
134149
// level.

src/CMake/thirdparty/SetupHwloc.cmake

+45-21
Original file line numberDiff line numberDiff line change
@@ -1,25 +1,49 @@
1-
###############################################################################
2-
# Setup Hwloc
3-
# This file defines:
4-
# HWLOC_FOUND - If Hwloc was found
5-
# HWLOC_INCLUDE_DIRS - The Hwloc include directories
6-
#
7-
# If found, the Hwloc CMake targets will also be imported
8-
###############################################################################
9-
10-
# first check for HWLOC_DIR
11-
12-
if(NOT HWLOC_DIR)
13-
MESSAGE(FATAL_ERROR "Hwloc support needs explicit HWLOC_DIR")
14-
endif()
1+
# First check for user-specified HWLOC_DIR
2+
if(HWLOC_DIR)
3+
MESSAGE(STATUS "Looking for Hwloc using HWLOC_DIR = ${HWLOC_DIR}")
4+
5+
set(HWLOC_FOUND TRUE)
6+
set(HWLOC_INCLUDE_DIRS ${HWLOC_DIR}/include)
7+
set(HWLOC_LIBRARY ${HWLOC_DIR}/lib/libhwloc.so)
8+
9+
set(HWLOC_DIR ${HWLOC_DIR} CACHE PATH "" FORCE)
10+
11+
message(STATUS "FOUND Hwloc at ${HWLOC_DIR}")
12+
message(STATUS " HWLOC_INCLUDE_DIRS = ${HWLOC_INCLUDE_DIRS}")
13+
message(STATUS " HWLOC_LIBRARY = ${HWLOC_LIBRARY}")
14+
# If HWLOC_DIR not specified, then try to automatically find the HWLOC header
15+
# and library
16+
elseif(NOT HWLOC_DIR)
17+
find_path(HWLOC_INCLUDE_DIRS
18+
NAMES hwloc.h
19+
)
1520

16-
MESSAGE(STATUS "Looking for Hwloc using HWLOC_DIR = ${HWLOC_DIR}")
21+
find_library(HWLOC_LIBRARY
22+
NAMES libhwloc.so
23+
)
1724

18-
include(${HWLOC_DIR}/include)
25+
if(HWLOC_INCLUDE_DIRS AND HWLOC_LIBRARY)
26+
set(HWLOC_FOUND TRUE)
27+
message(STATUS "HWLOC library found using find_library()")
28+
message(STATUS " HWLOC_INCLUDE_DIRS = ${HWLOC_INCLUDE_DIRS}")
29+
message(STATUS " HWLOC_LIBRARY = ${HWLOC_LIBRARY}")
30+
endif()
31+
endif()
32+
33+
# If HWLOC is still not found, then download and build HWLOC from source
34+
if(NOT HWLOC_INCLUDE_DIRS AND HWLOC_LIBRARY)
35+
MESSAGE(STATUS "Downloading and building Hwloc from source")
1936

20-
set(HWLOC_FOUND TRUE)
21-
set(HWLOC_LIBRARY ${HWLOC_DIR}/lib/libhwloc.so)
22-
set(HWLOC_INCLUDES ${HWLOC_DIR}/include)
37+
### Necessary for ExternalProject_Add
38+
include(${CMAKE_ROOT}/Modules/ExternalProject.cmake)
39+
include(../SetupExternalProjects.cmake)
40+
message(STATUS "ExternalDownload Hwloc")
41+
message(STATUS " HWLOC_INCLUDE_DIRS = ${HWLOC_INCLUDE_DIRS}")
42+
message(STATUS " HWLOC_LIBRARY = ${HWLOC_LIBRARY}")
43+
set(HWLOC_FOUND TRUE)
44+
endif()
2345

24-
message(STATUS "FOUND Hwloc at ${HWLOC_DIR}")
25-
message(STATUS "HWLOC_INCLUDES = ${HWLOC_INCLUDES}")
46+
# Abort if all methods fail
47+
if(NOT HWLOC_FOUND)
48+
MESSAGE(FATAL_ERROR "Hwloc support needed")
49+
endif()

src/CMakeLists.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -41,4 +41,5 @@ install(TARGETS msr msr-static DESTINATION "${CMAKE_INSTALL_PREFIX}/lib" EXPORT
4141
#
4242
# Headers are in ../include
4343
#
44-
include_directories(${PROJECT_SOURCE_DIR}/include)
44+
include_directories(${PROJECT_SOURCE_DIR}/include
45+
${HWLOC_INCLUDE_DIRS})

0 commit comments

Comments
 (0)