Skip to content

Commit

Permalink
Enable builds with system-level hwloc installation instead of interna…
Browse files Browse the repository at this point in the history
…l hwloc
  • Loading branch information
TomTheBear committed Dec 17, 2020
1 parent ee1c5cd commit e667773
Show file tree
Hide file tree
Showing 8 changed files with 116 additions and 83 deletions.
15 changes: 10 additions & 5 deletions Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ include $(MAKE_DIR)/config_git.mk
include $(MAKE_DIR)/config_checks.mk
include $(MAKE_DIR)/config_defines.mk

INCLUDES += -I./src/includes -I$(LUA_INCLUDE_DIR) -I$(HWLOC_FOLDER)/include -I$(BUILD_DIR)
INCLUDES += -I./src/includes -I$(LUA_INCLUDE_DIR) -I$(HWLOC_INCLUDE_DIR) -I$(BUILD_DIR)
LIBS += -ldl

ifeq ($(LUA_INTERNAL),false)
Expand Down Expand Up @@ -262,10 +262,15 @@ $(TARGET_GOTCHA_LIB):
@echo "===> ENTER $(GOTCHA_FOLDER)"
$(Q)$(MAKE) --no-print-directory -C $(GOTCHA_FOLDER) $(MAKECMDGOALS)


ifeq ($(USE_HWLOC_INTERNAL),true)
$(TARGET_HWLOC_LIB):
@echo "===> ENTER $(HWLOC_FOLDER)"
$(Q)$(MAKE) --no-print-directory -C $(HWLOC_FOLDER) $(MAKECMDGOALS)
else
$(TARGET_HWLOC_LIB):
@echo "===> EXTERNAL HWLOC"
endif


$(BENCH_TARGET):
@echo "===> ENTER $(BENCH_FOLDER)"
Expand Down Expand Up @@ -327,9 +332,9 @@ distclean: $(TARGET_LUA_LIB) $(TARGET_HWLOC_LIB) $(TARGET_GOTCHA_LIB) $(BENCH_TA
@rm -f $(FORTRAN_IF_NAME)
@rm -f $(FREQ_TARGET) $(DAEMON_TARGET) $(APPDAEMON_TARGET)
@rm -rf $(BUILD_DIR)
@rm -rf $(TARGET_LUA_LIB).* $(shell basename $(TARGET_LUA_LIB)).*
@rm -rf $(TARGET_HWLOC_LIB).* $(shell basename $(TARGET_HWLOC_LIB)).*
@rm -rf $(TARGET_GOTCHA_LIB).* $(shell basename $(TARGET_GOTCHA_LIB)).*
@if [ "$(LUA_INTERNAL)" = "true" ]; then rm -f $(TARGET_LUA_LIB).* $(shell basename $(TARGET_LUA_LIB)).*; fi
@if [ "$(USE_INTERNAL_HWLOC)" = "true" ]; then rm -f $(TARGET_HWLOC_LIB).* $(shell basename $(TARGET_HWLOC_LIB)).*; fi
@rm -f $(TARGET_GOTCHA_LIB).* $(shell basename $(TARGET_GOTCHA_LIB)).*
@rm -f $(GENGROUPLOCK)
@rm -f likwid-config.cmake
@rm -rf doc/html
Expand Down
4 changes: 2 additions & 2 deletions bench/Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -72,8 +72,8 @@ endif



SHARED_TARGET_LIB := -L.. -L../ext/hwloc/ -L$(LUA_LIB_DIR) -llikwid -llikwid-hwloc -l$(LUA_LIB_NAME)
STATIC_TARGET_LIB := ../liblikwid.a ../ext/hwloc/liblikwid-hwloc.a $(LUA_LIB_DIR)/lib$(LUA_LIB_NAME).a
SHARED_TARGET_LIB := -L.. -L$(HWLOC_LIB_DIR) -L$(LUA_LIB_DIR) -llikwid -l$(HWLOC_LIB_NAME) -l$(LUA_LIB_NAME)
STATIC_TARGET_LIB := ../liblikwid.a $(HWLOC_LIB_DIR)/lib$(HWLOC_LIB_NAME).a $(LUA_LIB_DIR)/lib$(LUA_LIB_NAME).a
TARGET_LIB = $(SHARED_TARGET_LIB)

BENCH_LIBS :=
Expand Down
6 changes: 6 additions & 0 deletions config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,12 @@ INSTALL_CHOWN = -g root -o root#NO SPACE
#LUA_LIB_NAME = lua5.2#NO SPACE, executable is assumed to have the same name
#LUA_BIN = /usr/bin#NO SPACE

# uncomment to optionally use system hwloc (tested with hwloc 2.x):
# default is to use internal hwloc
#HWLOC_INCLUDE_DIR = /usr/include#NO SPACE
#HWLOC_LIB_DIR = /usr/lib#NO SPACE
#HWLOC_LIB_NAME = hwloc#NO SPACE, used later as -l$HWLOC_LIB_NAME

# Change to true to a build shared library instead of a static one
# It is NOT recommended to switch to static libraries as some features don't
# work when compiled statically
Expand Down
14 changes: 12 additions & 2 deletions make/config_defines.mk
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,20 @@ LUA_INTERNAL := true#NO SPACE
endif
SHARED_LIBLUA := lib$(LUA_LIB_NAME).so
STATIC_LIBLUA := lib$(LUA_LIB_NAME).a

# HWLOC:
ifdef HWLOC_INCLUDE_DIR
USE_INTERNAL_HWLOC := false#NO SPACE
HWLOC_FOLDER := $(HWLOC_LIB_DIR)
else
HWLOC_FOLDER := $(PWD)/ext/hwloc
STATIC_LIBHWLOC := liblikwid-hwloc.a
SHARED_LIBHWLOC := liblikwid-hwloc.so
HWLOC_INCLUDE_DIR := $(HWLOC_FOLDER)/include
HWLOC_LIB_DIR := $(HWLOC_FOLDER)
HWLOC_LIB_NAME := likwid-hwloc
USE_INTERNAL_HWLOC := true#NO SPACE
endif
STATIC_LIBHWLOC := lib$(HWLOC_LIB_NAME).a
SHARED_LIBHWLOC := lib$(HWLOC_LIB_NAME).so

GOTCHA_FOLDER := $(PWD)/ext/GOTCHA
STATIC_LIBGOTCHA := liblikwid-gotcha.a
Expand Down
9 changes: 9 additions & 0 deletions src/includes/topology_hwloc.h
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@
#include <hwloc.h>
#include <sched.h>

#ifdef USE_INTERNAL_HWLOC
#define HWLOC_PREFIX likwid_
#else
#define HWLOC_PREFIX
#endif
#define LIKWID_HWLOC_MUNGE_NAME(a, b) LIKWID_HWLOC_MUNGE_NAME2(a, b)
#define LIKWID_HWLOC_MUNGE_NAME2(a, b) a ## b
#define LIKWID_HWLOC_NAME(name) LIKWID_HWLOC_MUNGE_NAME(HWLOC_PREFIX, hwloc_ ## name)

extern hwloc_topology_t hwloc_topology;

int likwid_hwloc_record_objs_of_type_below_obj(hwloc_topology_t t, hwloc_obj_t obj, hwloc_obj_type_t type, int* index, uint32_t **list);
Expand Down
58 changes: 29 additions & 29 deletions src/numa_hwloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -135,11 +135,11 @@ likwid_hwloc_findProcessor(int nodeID, int cpuID)
{
hwloc_obj_t obj;
int i;
int pu_count = likwid_hwloc_get_nbobjs_by_type(hwloc_topology, HWLOC_OBJ_PU);
int pu_count = LIKWID_HWLOC_NAME(get_nbobjs_by_type)(hwloc_topology, HWLOC_OBJ_PU);

for (i=0; i<pu_count; i++)
{
obj = likwid_hwloc_get_obj_by_type(hwloc_topology, HWLOC_OBJ_PU, i);
obj = LIKWID_HWLOC_NAME(get_obj_by_type)(hwloc_topology, HWLOC_OBJ_PU, i);
if (!obj)
{
continue;
Expand Down Expand Up @@ -180,21 +180,21 @@ hwloc_numa_init(void)

if (!hwloc_topology)
{
likwid_hwloc_topology_init(&hwloc_topology);
LIKWID_HWLOC_NAME(topology_init)(&hwloc_topology);
#if HWLOC_API_VERSION > 0x00020000
likwid_hwloc_topology_set_flags(hwloc_topology, HWLOC_TOPOLOGY_FLAG_WHOLE_SYSTEM );
LIKWID_HWLOC_NAME(topology_set_flags)(hwloc_topology, HWLOC_TOPOLOGY_FLAG_WHOLE_SYSTEM );
#else
likwid_hwloc_topology_set_flags(hwloc_topology, HWLOC_TOPOLOGY_FLAG_WHOLE_SYSTEM|HWLOC_TOPOLOGY_FLAG_WHOLE_IO );
LIKWID_HWLOC_NAME(topology_set_flags)(hwloc_topology, HWLOC_TOPOLOGY_FLAG_WHOLE_SYSTEM|HWLOC_TOPOLOGY_FLAG_WHOLE_IO );
#endif
likwid_hwloc_topology_load(hwloc_topology);
LIKWID_HWLOC_NAME(topology_load)(hwloc_topology);
}
#if defined(__x86_64) || defined(__i386__)
numa_info.numberOfNodes = likwid_hwloc_get_nbobjs_by_type(hwloc_topology, hwloc_type);
numa_info.numberOfNodes = LIKWID_HWLOC_NAME(get_nbobjs_by_type)(hwloc_topology, hwloc_type);
#endif
#if defined(__ARM_ARCH_7A__) || defined(__ARM_ARCH_8A__)
numa_info.numberOfNodes = 0;
#endif
numPUs = likwid_hwloc_get_nbobjs_by_type(hwloc_topology, HWLOC_OBJ_PU);
numPUs = LIKWID_HWLOC_NAME(get_nbobjs_by_type)(hwloc_topology, HWLOC_OBJ_PU);
/* If the amount of NUMA nodes == 0, there is actually no NUMA node, hence
aggregate all sockets in the system into the single virtually created NUMA node */
if (numa_info.numberOfNodes == 0)
Expand All @@ -210,15 +210,15 @@ hwloc_numa_init(void)
numa_info.numberOfNodes * sizeof(NumaNode));
return -1;
}
depth = likwid_hwloc_get_type_depth(hwloc_topology, hwloc_type);
depth = LIKWID_HWLOC_NAME(get_type_depth)(hwloc_topology, hwloc_type);
#if HWLOC_API_VERSION > 0x00020000
errno = likwid_hwloc_distances_get_by_type(hwloc_topology, hwloc_type, &dist_count, &dists, HWLOC_DISTANCES_KIND_FROM_OS, 0);
errno = LIKWID_HWLOC_NAME(distances_get_by_type)(hwloc_topology, hwloc_type, &dist_count, &dists, HWLOC_DISTANCES_KIND_FROM_OS, 0);
#else
distances = likwid_hwloc_get_whole_distance_matrix_by_type(hwloc_topology, hwloc_type);
distances = LIKWID_HWLOC_NAME(get_whole_distance_matrix_by_type)(hwloc_topology, hwloc_type);
#endif
for (i=0; i<numa_info.numberOfNodes; i++)
{
obj = likwid_hwloc_get_obj_by_depth(hwloc_topology, depth, i);
obj = LIKWID_HWLOC_NAME(get_obj_by_depth)(hwloc_topology, depth, i);

numa_info.nodes[i].id = obj->os_index;
#if HWLOC_API_VERSION > 0x00020000
Expand Down Expand Up @@ -267,14 +267,14 @@ hwloc_numa_init(void)
for (d = 0; d < cpuid_topology.numHWThreads; d++)
{
HWThread *t = &cpuid_topology.threadPool[d];
if (likwid_hwloc_bitmap_isset(obj->cpuset, t->apicId) && t->threadId == 0)
if (LIKWID_HWLOC_NAME(bitmap_isset)(obj->cpuset, t->apicId) && t->threadId == 0)
{
numa_info.nodes[i].processors[j] = t->apicId;
j++;
for (int k = 0; k < cpuid_topology.numHWThreads; k++)
{
HWThread *x = &cpuid_topology.threadPool[k];
if (t->coreId == x->coreId && t->threadId != x->threadId && likwid_hwloc_bitmap_isset(obj->cpuset, x->apicId))
if (t->coreId == x->coreId && t->threadId != x->threadId && LIKWID_HWLOC_NAME(bitmap_isset)(obj->cpuset, x->apicId))
{
numa_info.nodes[i].processors[j] = x->apicId;
j++;
Expand All @@ -297,11 +297,11 @@ hwloc_numa_init(void)
#if HWLOC_API_VERSION > 0x00020000
if (dists)
{
int base = hwloc_distances_obj_index(dists, obj);
int base = LIKWID_HWLOC_NAME(distances_obj_index)(dists, obj);
for (d = 0; d < dists->nbobjs; d++)
{
hwloc_obj_t dobj = dists->objs[d];
int idx = hwloc_distances_obj_index(dists, dobj);
int idx = LIKWID_HWLOC_NAME(distances_obj_index)(dists, dobj);
numa_info.nodes[i].distances[idx] = dists->values[(base*dists->nbobjs)+idx];
}
numa_info.nodes[i].numberOfDistances = numa_info.numberOfNodes;
Expand All @@ -328,7 +328,7 @@ hwloc_numa_init(void)
#if HWLOC_API_VERSION > 0x00020000
if (dists)
{
hwloc_distances_release_remove(hwloc_topology, dists);
LIKWID_HWLOC_NAME(distances_release_remove)(hwloc_topology, dists);
}
#endif
}
Expand All @@ -351,15 +351,15 @@ hwloc_numa_membind(void* ptr, size_t size, int domainId)
if (!ptr || size == 0 || domainId < 0 || domainId >= numa_info.numberOfNodes)
return;
hwloc_membind_flags_t flags = HWLOC_MEMBIND_STRICT|HWLOC_MEMBIND_PROCESS|HWLOC_MEMBIND_BYNODESET;
hwloc_nodeset_t nodeset = likwid_hwloc_bitmap_alloc();
likwid_hwloc_bitmap_zero(nodeset);
likwid_hwloc_bitmap_set(nodeset, domainId);
hwloc_nodeset_t nodeset = LIKWID_HWLOC_NAME(bitmap_alloc)();
LIKWID_HWLOC_NAME(bitmap_zero)(nodeset);
LIKWID_HWLOC_NAME(bitmap_set)(nodeset, domainId);
#if HWLOC_API_VERSION > 0x00020000
ret = likwid_hwloc_set_area_membind(hwloc_topology, ptr, size, nodeset, HWLOC_MEMBIND_BIND, flags);
ret = LIKWID_HWLOC_NAME(set_area_membind)(hwloc_topology, ptr, size, nodeset, HWLOC_MEMBIND_BIND, flags);
#else
ret = likwid_hwloc_set_area_membind_nodeset(hwloc_topology, ptr, size, nodeset, HWLOC_MEMBIND_BIND, flags);
ret = LIKWID_HWLOC_NAME(set_area_membind_nodeset)(hwloc_topology, ptr, size, nodeset, HWLOC_MEMBIND_BIND, flags);
#endif
likwid_hwloc_bitmap_free(nodeset);
LIKWID_HWLOC_NAME(bitmap_free)(nodeset);

if (ret < 0)
{
Expand All @@ -372,21 +372,21 @@ hwloc_numa_setInterleaved(int* processorList, int numberOfProcessors)
{
int i,j;
int ret = 0;
likwid_hwloc_cpuset_t cpuset = hwloc_bitmap_alloc();
likwid_hwloc_membind_flags_t flags = HWLOC_MEMBIND_STRICT|HWLOC_MEMBIND_PROCESS;
likwid_hwloc_bitmap_zero(cpuset);
LIKWID_HWLOC_NAME(cpuset_t) cpuset = LIKWID_HWLOC_NAME(bitmap_alloc)();
LIKWID_HWLOC_NAME(membind_flags_t) flags = HWLOC_MEMBIND_STRICT|HWLOC_MEMBIND_PROCESS;
LIKWID_HWLOC_NAME(bitmap_zero)(cpuset);
for (i=0; i<numa_info.numberOfNodes; i++)
{
for (j=0; j<numberOfProcessors; j++)
{
if (likwid_hwloc_findProcessor(i,processorList[j]))
{
likwid_hwloc_bitmap_set(cpuset, i);
LIKWID_HWLOC_NAME(bitmap_set)(cpuset, i);
}
}
}
ret = likwid_hwloc_set_membind(hwloc_topology, cpuset, HWLOC_MEMBIND_INTERLEAVE, flags);
likwid_hwloc_bitmap_free(cpuset);
ret = LIKWID_HWLOC_NAME(set_membind)(hwloc_topology, cpuset, HWLOC_MEMBIND_INTERLEAVE, flags);
LIKWID_HWLOC_NAME(bitmap_free)(cpuset);
if (ret < 0)
{
ERROR;
Expand Down
12 changes: 6 additions & 6 deletions src/pci_hwloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -59,18 +59,18 @@ hwloc_pci_init(uint16_t testDevice, char** socket_bus, int* nrSockets)

if (!hwloc_topology)
{
likwid_hwloc_topology_init(&hwloc_topology);
LIKWID_HWLOC_NAME(topology_init)(&hwloc_topology);
#if HWLOC_API_VERSION > 0x00020000
likwid_hwloc_topology_set_flags(hwloc_topology, HWLOC_TOPOLOGY_FLAG_WHOLE_SYSTEM );
LIKWID_HWLOC_NAME(topology_set_flags)(hwloc_topology, HWLOC_TOPOLOGY_FLAG_WHOLE_SYSTEM );
#else
likwid_hwloc_topology_set_flags(hwloc_topology, HWLOC_TOPOLOGY_FLAG_WHOLE_SYSTEM|HWLOC_TOPOLOGY_FLAG_WHOLE_IO );
LIKWID_HWLOC_NAME(topology_set_flags)(hwloc_topology, HWLOC_TOPOLOGY_FLAG_WHOLE_SYSTEM|HWLOC_TOPOLOGY_FLAG_WHOLE_IO );
#endif
likwid_hwloc_topology_load(hwloc_topology);
LIKWID_HWLOC_NAME(topology_load)(hwloc_topology);
}

for(i = 0; i < likwid_hwloc_get_nbobjs_by_type(hwloc_topology, HWLOC_OBJ_PCI_DEVICE); i++)
for(i = 0; i < LIKWID_HWLOC_NAME(get_nbobjs_by_type)(hwloc_topology, HWLOC_OBJ_PCI_DEVICE); i++)
{
obj = likwid_hwloc_get_obj_by_type(hwloc_topology, HWLOC_OBJ_PCI_DEVICE, i);
obj = LIKWID_HWLOC_NAME(get_obj_by_type)(hwloc_topology, HWLOC_OBJ_PCI_DEVICE, i);
if (obj->attr->pcidev.vendor_id != testVendor)
{
continue;
Expand Down
Loading

0 comments on commit e667773

Please sign in to comment.