int main(void) { #define N 10 hwloc_bitmap_t sets[N]; unsigned i,j; unsigned stats[5]; memset(stats, 0, sizeof(stats)); sets[0] = hwloc_bitmap_alloc(); sets[1] = hwloc_bitmap_alloc_full(); sets[2] = hwloc_bitmap_alloc_full(); hwloc_bitmap_clr_range(sets[2], 56, 129); sets[3] = hwloc_bitmap_alloc_full(); hwloc_bitmap_clr_range(sets[3], 0, 33); hwloc_bitmap_clr_range(sets[3], 50, 135); sets[4] = hwloc_bitmap_alloc(); hwloc_bitmap_set_range(sets[4], 0, 24); sets[5] = hwloc_bitmap_alloc(); hwloc_bitmap_set_range(sets[5], 0, 178); sets[6] = hwloc_bitmap_alloc(); hwloc_bitmap_set_range(sets[6], 0, 191); hwloc_bitmap_set_range(sets[6], 1031, 2035); sets[7] = hwloc_bitmap_alloc(); hwloc_bitmap_set_range(sets[7], 324, 456); sets[8] = hwloc_bitmap_alloc(); hwloc_bitmap_set_range(sets[8], 323, 455); hwloc_bitmap_set_range(sets[8], 136, 177); sets[9] = hwloc_bitmap_alloc(); hwloc_bitmap_set_range(sets[9], 3, 6); for(i=0; i<N; i++) { for(j=0; j<N; j++) { int res = check_compare(sets[i], sets[j]); stats[res]++; } } for(i=0; i<N; i++) hwloc_bitmap_free(sets[i]); printf("got %u EQUAL\n", stats[0]); printf("got %u INCLUDED\n", stats[1]); printf("got %u CONTAINS\n", stats[2]); printf("got %u INTERSECTS\n", stats[3]); printf("got %u DIFFERENT\n", stats[4]); return 0; }
int hwloc_look_hardwired_fujitsu_fx10(struct hwloc_topology *topology) { /* FIXME: what if a broken core is disabled? */ unsigned i; hwloc_obj_t obj; hwloc_bitmap_t set; for(i=0; i<16; i++) { set = hwloc_bitmap_alloc(); hwloc_bitmap_set(set, i); obj = hwloc_alloc_setup_object(HWLOC_OBJ_CACHE, -1); obj->cpuset = hwloc_bitmap_dup(set); obj->attr->cache.type = HWLOC_OBJ_CACHE_INSTRUCTION; obj->attr->cache.depth = 1; obj->attr->cache.size = 32*1024; obj->attr->cache.linesize = 128; obj->attr->cache.associativity = 2; hwloc_insert_object_by_cpuset(topology, obj); obj = hwloc_alloc_setup_object(HWLOC_OBJ_CACHE, -1); obj->cpuset = hwloc_bitmap_dup(set); obj->attr->cache.type = HWLOC_OBJ_CACHE_DATA; obj->attr->cache.depth = 1; obj->attr->cache.size = 32*1024; obj->attr->cache.linesize = 128; obj->attr->cache.associativity = 2; hwloc_insert_object_by_cpuset(topology, obj); obj = hwloc_alloc_setup_object(HWLOC_OBJ_CORE, i); obj->cpuset = set; hwloc_insert_object_by_cpuset(topology, obj); } set = hwloc_bitmap_alloc(); hwloc_bitmap_set_range(set, 0, 15); obj = hwloc_alloc_setup_object(HWLOC_OBJ_CACHE, -1); obj->cpuset = hwloc_bitmap_dup(set); obj->attr->cache.type = HWLOC_OBJ_CACHE_UNIFIED; obj->attr->cache.depth = 2; obj->attr->cache.size = 12*1024*1024; obj->attr->cache.linesize = 128; obj->attr->cache.associativity = 24; hwloc_insert_object_by_cpuset(topology, obj); obj = hwloc_alloc_setup_object(HWLOC_OBJ_PACKAGE, 0); obj->cpuset = set; hwloc_obj_add_info(obj, "CPUVendor", "Fujitsu"); hwloc_obj_add_info(obj, "CPUModel", "SPARC64 IXfx"); hwloc_insert_object_by_cpuset(topology, obj); hwloc_setup_pu_level(topology, 16); return 0; }
int main(void) { hwloc_bitmap_t set; /* check an empty bitmap */ set = hwloc_bitmap_alloc(); assert(hwloc_bitmap_to_ulong(set) == 0UL); assert(hwloc_bitmap_to_ith_ulong(set, 0) == 0UL); assert(hwloc_bitmap_to_ith_ulong(set, 1) == 0UL); assert(hwloc_bitmap_to_ith_ulong(set, 23) == 0UL); /* check a non-empty bitmap */ hwloc_bitmap_from_ith_ulong(set, 4, 0xff); assert(hwloc_bitmap_to_ith_ulong(set, 4) == 0xff); assert(hwloc_bitmap_to_ulong(set) == 0UL); assert(hwloc_bitmap_to_ith_ulong(set, 0) == 0UL); assert(hwloc_bitmap_to_ith_ulong(set, 1) == 0UL); assert(hwloc_bitmap_to_ith_ulong(set, 23) == 0UL); /* check a zeroed bitmap */ hwloc_bitmap_zero(set); assert(hwloc_bitmap_to_ulong(set) == 0UL); assert(hwloc_bitmap_to_ith_ulong(set, 0) == 0UL); assert(hwloc_bitmap_to_ith_ulong(set, 1) == 0UL); assert(hwloc_bitmap_to_ith_ulong(set, 4) == 0UL); assert(hwloc_bitmap_to_ith_ulong(set, 23) == 0UL); hwloc_bitmap_free(set); /* check a full bitmap */ set = hwloc_bitmap_alloc_full(); assert(hwloc_bitmap_to_ulong(set) == ~0UL); assert(hwloc_bitmap_to_ith_ulong(set, 0) == ~0UL); assert(hwloc_bitmap_to_ith_ulong(set, 1) == ~0UL); assert(hwloc_bitmap_to_ith_ulong(set, 23) == ~0UL); /* check a almost full bitmap */ hwloc_bitmap_set_ith_ulong(set, 4, 0xff); assert(hwloc_bitmap_to_ith_ulong(set, 4) == 0xff); assert(hwloc_bitmap_to_ulong(set) == ~0UL); assert(hwloc_bitmap_to_ith_ulong(set, 0) == ~0UL); assert(hwloc_bitmap_to_ith_ulong(set, 1) == ~0UL); assert(hwloc_bitmap_to_ith_ulong(set, 23) == ~0UL); /* check a almost empty bitmap */ hwloc_bitmap_from_ith_ulong(set, 4, 0xff); assert(hwloc_bitmap_to_ith_ulong(set, 4) == 0xff); assert(hwloc_bitmap_to_ulong(set) == 0UL); assert(hwloc_bitmap_to_ith_ulong(set, 0) == 0UL); assert(hwloc_bitmap_to_ith_ulong(set, 1) == 0UL); assert(hwloc_bitmap_to_ith_ulong(set, 23) == 0UL); hwloc_bitmap_free(set); /* check ranges */ set = hwloc_bitmap_alloc(); assert(hwloc_bitmap_weight(set) == 0); /* 23-45 */ hwloc_bitmap_set_range(set, 23, 45); assert(hwloc_bitmap_weight(set) == 23); /* 23-45,78- */ hwloc_bitmap_set_range(set, 78, -1); assert(hwloc_bitmap_weight(set) == -1); /* 23- */ hwloc_bitmap_set_range(set, 44, 79); assert(hwloc_bitmap_weight(set) == -1); assert(hwloc_bitmap_first(set) == 23); assert(!hwloc_bitmap_isfull(set)); /* 0- */ hwloc_bitmap_set_range(set, 0, 22); assert(hwloc_bitmap_weight(set) == -1); assert(hwloc_bitmap_isfull(set)); /* 0-34,57- */ hwloc_bitmap_clr_range(set, 35, 56); assert(hwloc_bitmap_weight(set) == -1); assert(!hwloc_bitmap_isfull(set)); /* 0-34,57 */ hwloc_bitmap_clr_range(set, 58, -1); assert(hwloc_bitmap_weight(set) == 36); assert(hwloc_bitmap_last(set) == 57); assert(hwloc_bitmap_next(set, 34) == 57); /* 0-34 */ hwloc_bitmap_clr(set, 57); assert(hwloc_bitmap_weight(set) == 35); assert(hwloc_bitmap_last(set) == 34); /* empty */ hwloc_bitmap_clr_range(set, 0, 34); assert(hwloc_bitmap_weight(set) == 0); assert(hwloc_bitmap_first(set) == -1); hwloc_bitmap_free(set); return 0; }
int main(void) { hwloc_bitmap_t set; int i, cpu, expected_cpu = 0; /* empty set */ set = hwloc_bitmap_alloc(); assert(hwloc_bitmap_first(set) == -1); assert(hwloc_bitmap_last(set) == -1); assert(hwloc_bitmap_next(set, 0) == -1); assert(hwloc_bitmap_next(set, -1) == -1); assert(hwloc_bitmap_weight(set) == 0); /* full set */ hwloc_bitmap_fill(set); assert(hwloc_bitmap_first(set) == 0); assert(hwloc_bitmap_last(set) == -1); assert(hwloc_bitmap_next(set, -1) == 0); assert(hwloc_bitmap_next(set, 0) == 1); assert(hwloc_bitmap_next(set, 1) == 2); assert(hwloc_bitmap_next(set, 2) == 3); assert(hwloc_bitmap_next(set, 30) == 31); assert(hwloc_bitmap_next(set, 31) == 32); assert(hwloc_bitmap_next(set, 32) == 33); assert(hwloc_bitmap_next(set, 62) == 63); assert(hwloc_bitmap_next(set, 63) == 64); assert(hwloc_bitmap_next(set, 64) == 65); assert(hwloc_bitmap_next(set, 12345) == 12346); assert(hwloc_bitmap_weight(set) == -1); /* custom sets */ hwloc_bitmap_zero(set); hwloc_bitmap_set_range(set, 36, 59); assert(hwloc_bitmap_first(set) == 36); assert(hwloc_bitmap_last(set) == 59); assert(hwloc_bitmap_next(set, -1) == 36); assert(hwloc_bitmap_next(set, 0) == 36); assert(hwloc_bitmap_next(set, 36) == 37); assert(hwloc_bitmap_next(set, 59) == -1); assert(hwloc_bitmap_weight(set) == 24); hwloc_bitmap_set_range(set, 136, 259); assert(hwloc_bitmap_first(set) == 36); assert(hwloc_bitmap_last(set) == 259); assert(hwloc_bitmap_next(set, 59) == 136); assert(hwloc_bitmap_next(set, 259) == -1); assert(hwloc_bitmap_weight(set) == 148); hwloc_bitmap_clr(set, 199); assert(hwloc_bitmap_first(set) == 36); assert(hwloc_bitmap_last(set) == 259); assert(hwloc_bitmap_next(set, 198) == 200); assert(hwloc_bitmap_next(set, 199) == 200); assert(hwloc_bitmap_weight(set) == 147); i = 0; hwloc_bitmap_foreach_begin(cpu, set) { if (0 <= i && i < 24) expected_cpu = i + 36; else if (24 <= i && i < 87) expected_cpu = i + 112; else if (87 <= i && i < 147) expected_cpu = i + 113; assert(expected_cpu == cpu); i++; } hwloc_bitmap_foreach_end(); hwloc_bitmap_free(set); return 0; }
int hwloc_look_hardwired_fujitsu_fx10(struct hwloc_topology *topology) { /* If a broken core gets disabled, its bit disappears and other core bits are NOT shifted towards 0. * Node is not given to user job, not need to handle that case properly. */ unsigned i; hwloc_obj_t obj; hwloc_bitmap_t set; for(i=0; i<16; i++) { set = hwloc_bitmap_alloc(); hwloc_bitmap_set(set, i); if (hwloc_filter_check_keep_object_type(topology, HWLOC_OBJ_L1ICACHE)) { obj = hwloc_alloc_setup_object(topology, HWLOC_OBJ_L1ICACHE, -1); obj->cpuset = hwloc_bitmap_dup(set); obj->attr->cache.type = HWLOC_OBJ_CACHE_INSTRUCTION; obj->attr->cache.depth = 1; obj->attr->cache.size = 32*1024; obj->attr->cache.linesize = 128; obj->attr->cache.associativity = 2; hwloc_insert_object_by_cpuset(topology, obj); } if (hwloc_filter_check_keep_object_type(topology, HWLOC_OBJ_L1CACHE)) { obj = hwloc_alloc_setup_object(topology, HWLOC_OBJ_L1CACHE, -1); obj->cpuset = hwloc_bitmap_dup(set); obj->attr->cache.type = HWLOC_OBJ_CACHE_DATA; obj->attr->cache.depth = 1; obj->attr->cache.size = 32*1024; obj->attr->cache.linesize = 128; obj->attr->cache.associativity = 2; hwloc_insert_object_by_cpuset(topology, obj); } if (hwloc_filter_check_keep_object_type(topology, HWLOC_OBJ_CORE)) { obj = hwloc_alloc_setup_object(topology, HWLOC_OBJ_CORE, i); obj->cpuset = set; hwloc_insert_object_by_cpuset(topology, obj); } else hwloc_bitmap_free(set); } set = hwloc_bitmap_alloc(); hwloc_bitmap_set_range(set, 0, 15); if (hwloc_filter_check_keep_object_type(topology, HWLOC_OBJ_L2CACHE)) { obj = hwloc_alloc_setup_object(topology, HWLOC_OBJ_L2CACHE, -1); obj->cpuset = hwloc_bitmap_dup(set); obj->attr->cache.type = HWLOC_OBJ_CACHE_UNIFIED; obj->attr->cache.depth = 2; obj->attr->cache.size = 12*1024*1024; obj->attr->cache.linesize = 128; obj->attr->cache.associativity = 24; hwloc_insert_object_by_cpuset(topology, obj); } if (hwloc_filter_check_keep_object_type(topology, HWLOC_OBJ_PACKAGE)) { obj = hwloc_alloc_setup_object(topology, HWLOC_OBJ_PACKAGE, 0); obj->cpuset = set; hwloc_obj_add_info(obj, "CPUVendor", "Fujitsu"); hwloc_obj_add_info(obj, "CPUModel", "SPARC64 IXfx"); hwloc_insert_object_by_cpuset(topology, obj); } else hwloc_bitmap_free(set); hwloc_setup_pu_level(topology, 16); return 0; }
int hwloc_look_hardwired_fujitsu_fx100(struct hwloc_topology *topology) { /* FIXME: what if a broken core is disabled? */ unsigned i; hwloc_obj_t obj; hwloc_bitmap_t set; for(i=0; i<34; i++) { set = hwloc_bitmap_alloc(); hwloc_bitmap_set(set, i); if (hwloc_filter_check_keep_object_type(topology, HWLOC_OBJ_L1ICACHE)) { obj = hwloc_alloc_setup_object(HWLOC_OBJ_L1ICACHE, -1); obj->cpuset = hwloc_bitmap_dup(set); obj->attr->cache.type = HWLOC_OBJ_CACHE_INSTRUCTION; obj->attr->cache.depth = 1; obj->attr->cache.size = 64*1024; obj->attr->cache.linesize = 256; obj->attr->cache.associativity = 4; hwloc_insert_object_by_cpuset(topology, obj); } if (hwloc_filter_check_keep_object_type(topology, HWLOC_OBJ_L1CACHE)) { obj = hwloc_alloc_setup_object(HWLOC_OBJ_L1CACHE, -1); obj->cpuset = hwloc_bitmap_dup(set); obj->attr->cache.type = HWLOC_OBJ_CACHE_DATA; obj->attr->cache.depth = 1; obj->attr->cache.size = 64*1024; obj->attr->cache.linesize = 256; obj->attr->cache.associativity = 4; hwloc_insert_object_by_cpuset(topology, obj); } if (hwloc_filter_check_keep_object_type(topology, HWLOC_OBJ_CORE)) { obj = hwloc_alloc_setup_object(HWLOC_OBJ_CORE, i); obj->cpuset = set; hwloc_insert_object_by_cpuset(topology, obj); } else hwloc_bitmap_free(set); } if (hwloc_filter_check_keep_object_type(topology, HWLOC_OBJ_L2CACHE)) { obj = hwloc_alloc_setup_object(HWLOC_OBJ_L2CACHE, -1); obj->cpuset = hwloc_bitmap_alloc(); hwloc_bitmap_set_range(obj->cpuset, 0, 15); hwloc_bitmap_set(obj->cpuset, 32); obj->attr->cache.type = HWLOC_OBJ_CACHE_UNIFIED; obj->attr->cache.depth = 2; obj->attr->cache.size = 12*1024*1024; obj->attr->cache.linesize = 256; obj->attr->cache.associativity = 24; hwloc_insert_object_by_cpuset(topology, obj); obj = hwloc_alloc_setup_object(HWLOC_OBJ_L2CACHE, -1); obj->cpuset = hwloc_bitmap_alloc(); hwloc_bitmap_set_range(obj->cpuset, 16, 31); hwloc_bitmap_set(obj->cpuset, 33); obj->attr->cache.type = HWLOC_OBJ_CACHE_UNIFIED; obj->attr->cache.depth = 2; obj->attr->cache.size = 12*1024*1024; obj->attr->cache.linesize = 256; obj->attr->cache.associativity = 24; hwloc_insert_object_by_cpuset(topology, obj); } if (hwloc_filter_check_keep_object_type(topology, HWLOC_OBJ_PACKAGE)) { obj = hwloc_alloc_setup_object(HWLOC_OBJ_PACKAGE, 0); obj->cpuset = hwloc_bitmap_alloc(); hwloc_bitmap_set_range(obj->cpuset, 0, 33); hwloc_obj_add_info(obj, "CPUVendor", "Fujitsu"); hwloc_obj_add_info(obj, "CPUModel", "SPARC64 XIfx"); hwloc_insert_object_by_cpuset(topology, obj); } hwloc_setup_pu_level(topology, 34); return 0; }
int main(void) { hwloc_bitmap_t cpuset = hwloc_bitmap_alloc(); unsigned node_indexes[3], core_indexes[6]; float node_distances[9], core_distances[36]; unsigned i,j; int err; for(i=0; i<3; i++) { node_indexes[i] = i; for(j=0; j<3; j++) node_distances[i*3+j] = (i == j ? 10.f : 20.f); } for(i=0; i<6; i++) { core_indexes[i] = i; for(j=0; j<6; j++) core_distances[i*6+j] = (i == j ? 4.f : 8.f); } hwloc_topology_init(&topology); hwloc_topology_set_synthetic(topology, "node:3 core:2 pu:4"); hwloc_topology_set_distance_matrix(topology, HWLOC_OBJ_NODE, 3, node_indexes, node_distances); hwloc_topology_set_distance_matrix(topology, HWLOC_OBJ_CORE, 6, core_indexes, core_distances); hwloc_topology_load(topology); /* entire topology */ printf("starting from full topology\n"); check(3, 6, 24); check_distances(3, 6); /* restrict to nothing, impossible */ printf("restricting to nothing, must fail\n"); hwloc_bitmap_zero(cpuset); err = hwloc_topology_restrict(topology, cpuset, HWLOC_RESTRICT_FLAG_ADAPT_DISTANCES); assert(err < 0 && errno == EINVAL); check(3, 6, 24); check_distances(3, 6); /* restrict to everything, will do nothing */ printf("restricting to nothing, does nothing\n"); hwloc_bitmap_fill(cpuset); err = hwloc_topology_restrict(topology, cpuset, HWLOC_RESTRICT_FLAG_ADAPT_DISTANCES); assert(!err); check(3, 6, 24); check_distances(3, 6); /* remove a single pu (second PU of second core of second node) */ printf("removing one PU\n"); hwloc_bitmap_fill(cpuset); hwloc_bitmap_clr(cpuset, 13); err = hwloc_topology_restrict(topology, cpuset, HWLOC_RESTRICT_FLAG_ADAPT_DISTANCES); assert(!err); check(3, 6, 23); check_distances(3, 6); /* remove the entire second core of first node */ printf("removing one core\n"); hwloc_bitmap_fill(cpuset); hwloc_bitmap_clr_range(cpuset, 4, 7); err = hwloc_topology_restrict(topology, cpuset, HWLOC_RESTRICT_FLAG_ADAPT_DISTANCES); assert(!err); check(3, 5, 19); check_distances(3, 5); /* remove the entire third node */ printf("removing one node\n"); hwloc_bitmap_fill(cpuset); hwloc_bitmap_clr_range(cpuset, 16, 23); err = hwloc_topology_restrict(topology, cpuset, HWLOC_RESTRICT_FLAG_ADAPT_DISTANCES); assert(!err); check(2, 3, 11); check_distances(2, 3); /* restrict to the third node, impossible */ printf("restricting to only some already removed node, must fail\n"); hwloc_bitmap_zero(cpuset); hwloc_bitmap_set_range(cpuset, 16, 23); err = hwloc_topology_restrict(topology, cpuset, HWLOC_RESTRICT_FLAG_ADAPT_DISTANCES); assert(err == -1 && errno == EINVAL); check(2, 3, 11); check_distances(2, 3); /* only keep three PUs (first and last of first core, and last of last core of second node) */ printf("restricting to 3 PUs\n"); hwloc_bitmap_zero(cpuset); hwloc_bitmap_set(cpuset, 0); hwloc_bitmap_set(cpuset, 3); hwloc_bitmap_set(cpuset, 15); err = hwloc_topology_restrict(topology, cpuset, 0); assert(!err); check(2, 2, 3); check_distances(0, 0); /* only keep one PU (last of last core of second node) */ printf("restricting to a single PU\n"); hwloc_bitmap_zero(cpuset); hwloc_bitmap_set(cpuset, 15); err = hwloc_topology_restrict(topology, cpuset, 0); assert(!err); check(1, 1, 1); check_distances(0, 0); hwloc_topology_destroy(topology); /* check that restricting exactly on a Misc object keeps things coherent */ printf("restricting to a Misc covering only the of the PU level\n"); hwloc_topology_init(&topology); hwloc_topology_set_synthetic(topology, "pu:4"); hwloc_topology_load(topology); hwloc_bitmap_zero(cpuset); hwloc_bitmap_set_range(cpuset, 1, 2); hwloc_topology_insert_misc_object_by_cpuset(topology, cpuset, "toto"); hwloc_topology_restrict(topology, cpuset, 0); hwloc_topology_check(topology); hwloc_topology_destroy(topology); hwloc_bitmap_free(cpuset); return 0; }