hwloc 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +5 -5
- data/hwloc.gemspec +1 -2
- data/lib/hwloc/Bind.rb +46 -0
- data/lib/hwloc/Bitmap.rb +6 -2
- data/lib/hwloc/Export.rb +11 -0
- data/lib/hwloc/Hwloc.rb +5 -1
- data/lib/hwloc/Obj.rb +179 -110
- data/lib/hwloc/Topology.rb +116 -13
- metadata +3 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: da58c0475ef675dc9333d71319fa2224a40f60faef278163bbfa63b85827ab46
|
4
|
+
data.tar.gz: 1ab3eb8ec7c39586d3a60198995cce73027c056d1199db8e4175180362b85a9d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: ef53f35ef86622c63c20ff1f787d8f0dc71ca395009c226886185683afec6c616887ee2f5a4532cc90ea31fa26ae8be20085040f03d63c3d73934ca25efd7e5c
|
7
|
+
data.tar.gz: 3a91c268149748eeac76b9ff40787cb685e28e60dae668e61d3cd3d1f81b2a12cd4e82fe05efcf182dc10e15e64fc155193a67318176288f1e31c215c14a5974
|
data/hwloc.gemspec
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = 'hwloc'
|
3
|
-
s.version = "0.3.
|
3
|
+
s.version = "0.3.2"
|
4
4
|
s.author = "Brice Videau"
|
5
5
|
s.email = "brice.videau@imag.fr"
|
6
6
|
s.homepage = "https://github.com/Nanosim-LIG/hwloc-ruby"
|
7
7
|
s.summary = "hwloc ruby bindings"
|
8
8
|
s.description = "hwloc ruby bindings for versions 1.10 onward"
|
9
9
|
s.files = Dir['hwloc.gemspec', 'LICENSE', 'README.md', 'lib/**/*']
|
10
|
-
s.has_rdoc = false
|
11
10
|
s.license = 'BSD-2-Clause'
|
12
11
|
s.required_ruby_version = '>= 1.9.3'
|
13
12
|
s.add_dependency 'ffi', '~> 1.9', '>=1.9.3'
|
data/lib/hwloc/Bind.rb
CHANGED
@@ -147,6 +147,7 @@ module Hwloc
|
|
147
147
|
class Topology
|
148
148
|
|
149
149
|
if API_VERSION < API_VERSION_2_0 then
|
150
|
+
|
150
151
|
def set_membind_nodeset(nodeset, policy, *flags)
|
151
152
|
err = Hwloc.hwloc_set_membind_nodeset(@ptr, nodeset, policy, flags)
|
152
153
|
raise MembindError if err == -1
|
@@ -210,6 +211,51 @@ module Hwloc
|
|
210
211
|
end
|
211
212
|
end
|
212
213
|
|
214
|
+
else
|
215
|
+
|
216
|
+
def set_membind_nodeset(nodeset, policy, *flags)
|
217
|
+
flags.push :MEMBIND_BYNODESET
|
218
|
+
set_membind(nodeset, policy, *flags)
|
219
|
+
return self
|
220
|
+
end
|
221
|
+
|
222
|
+
def get_membind_nodeset(*flags)
|
223
|
+
flags.push :MEMBIND_BYNODESET
|
224
|
+
get_membind(*flags)
|
225
|
+
end
|
226
|
+
|
227
|
+
def set_proc_membind_nodeset(pid, nodeset, policy, *flags)
|
228
|
+
flags.push :MEMBIND_BYNODESET
|
229
|
+
set_proc_membind(pid, nodeset, policy, flags)
|
230
|
+
return self
|
231
|
+
end
|
232
|
+
|
233
|
+
def get_proc_membind_nodeset(pid, *flags)
|
234
|
+
flags.push :MEMBIND_BYNODESET
|
235
|
+
get_proc_membind(pid, *flags)
|
236
|
+
end
|
237
|
+
|
238
|
+
def set_area_membind_nodeset(pointer, nodeset, policy, *flags)
|
239
|
+
flags.push :MEMBIND_BYNODESET
|
240
|
+
set_area_membind(pointer, nodeset, policy, *flags)
|
241
|
+
return self
|
242
|
+
end
|
243
|
+
|
244
|
+
def get_area_membind_nodeset(pointer, *flags)
|
245
|
+
flags.push :MEMBIND_BYNODESET
|
246
|
+
get_area_membind(pointer, *flags)
|
247
|
+
end
|
248
|
+
|
249
|
+
def alloc_membind_nodeset(size, nodeset, policy, *flags)
|
250
|
+
flags.push :MEMBIND_BYNODESET
|
251
|
+
alloc_membind(size, nodeset, policy, *flags)
|
252
|
+
end
|
253
|
+
|
254
|
+
def alloc_membind_policy_nodeset(size, nodeset, policy, *flags)
|
255
|
+
flags.push :MEMBIND_BYNODESET
|
256
|
+
alloc_membind_policy_nodeset(size, nodeset, policy, *flags)
|
257
|
+
end
|
258
|
+
|
213
259
|
end
|
214
260
|
|
215
261
|
def set_membind(set, policy, *flags)
|
data/lib/hwloc/Bitmap.rb
CHANGED
@@ -113,11 +113,15 @@ module Hwloc
|
|
113
113
|
s_ptr.read_string
|
114
114
|
end
|
115
115
|
|
116
|
-
def
|
116
|
+
def list_to_s
|
117
117
|
size = Hwloc.hwloc_bitmap_list_snprintf(nil, 0, @ptr)
|
118
118
|
s_ptr = FFI::MemoryPointer::new(size+1)
|
119
119
|
Hwloc.hwloc_bitmap_list_snprintf(s_ptr, size+1, @ptr)
|
120
|
-
|
120
|
+
s_ptr.read_string
|
121
|
+
end
|
122
|
+
|
123
|
+
def to_a
|
124
|
+
str = list_to_s
|
121
125
|
str.split(",").collect { |e|
|
122
126
|
if e.match("-") then
|
123
127
|
rgs = e.split("-")
|
data/lib/hwloc/Export.rb
CHANGED
@@ -1,3 +1,5 @@
|
|
1
|
+
require 'stringio'
|
2
|
+
|
1
3
|
module Hwloc
|
2
4
|
|
3
5
|
if API_VERSION < API_VERSION_2_0 then
|
@@ -66,6 +68,15 @@ module Hwloc
|
|
66
68
|
end
|
67
69
|
end
|
68
70
|
|
71
|
+
def to_xml(flags = 0)
|
72
|
+
a = if API_VERSION >= API_VERSION_2_0
|
73
|
+
export_xmlbuffer(flags)
|
74
|
+
else
|
75
|
+
export_xmlbuffer
|
76
|
+
end
|
77
|
+
a.read_string
|
78
|
+
end
|
79
|
+
|
69
80
|
def free_xmlbuffer(pointer)
|
70
81
|
Hwloc.hwloc_free_xmlbuffer(@self, pointer)
|
71
82
|
end
|
data/lib/hwloc/Hwloc.rb
CHANGED
@@ -3,8 +3,12 @@ require 'ffi/bitmask'
|
|
3
3
|
|
4
4
|
module Hwloc
|
5
5
|
extend FFI::Library
|
6
|
-
ffi_lib 'hwloc'
|
7
6
|
|
7
|
+
if ENV['HWLOC_LIBRARY_PATH']
|
8
|
+
ffi_lib ENV['HWLOC_LIBRARY_PATH']
|
9
|
+
else
|
10
|
+
ffi_lib 'hwloc'
|
11
|
+
end
|
8
12
|
attach_function :hwloc_get_api_version, [], :uint
|
9
13
|
|
10
14
|
API_VERSION = Hwloc.hwloc_get_api_version
|
data/lib/hwloc/Obj.rb
CHANGED
@@ -3,42 +3,32 @@ module Hwloc
|
|
3
3
|
class ObjError < Error
|
4
4
|
end
|
5
5
|
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
:
|
15
|
-
|
16
|
-
]
|
17
|
-
if API_VERSION >= API_VERSION_2_0 then
|
18
|
-
obj_types += [
|
19
|
-
:OBJ_L1CACHE,
|
20
|
-
:OBJ_L2CACHE,
|
21
|
-
:OBJ_L3CACHE,
|
22
|
-
:OBJ_L4CACHE,
|
23
|
-
:OBJ_L5CACHE,
|
24
|
-
:OBJ_L1ICACHE,
|
25
|
-
:OBJ_L2ICACHE,
|
26
|
-
:OBJ_L3ICACHE
|
27
|
-
]
|
6
|
+
attach_function :hwloc_obj_type_string, [:int], :string
|
7
|
+
|
8
|
+
obj_types = []
|
9
|
+
|
10
|
+
i = 0
|
11
|
+
loop do
|
12
|
+
str = Hwloc.hwloc_obj_type_string(i)
|
13
|
+
break if str == "Unknown"
|
14
|
+
obj_types.push :"OBJ_#{str.upcase.gsub("PCIDEV", "PCI_DEVICE").gsub("OSDEV", "OS_DEVICE")}"
|
15
|
+
i += 1
|
28
16
|
end
|
29
|
-
obj_types += [
|
30
|
-
:OBJ_GROUP,
|
31
|
-
:OBJ_MISC,
|
32
|
-
:OBJ_BRIDGE,
|
33
|
-
:OBJ_PCI_DEVICE,
|
34
|
-
:OBJ_OS_DEVICE,
|
35
|
-
:OBJ_TYPE_MAX
|
36
|
-
]
|
37
17
|
|
38
18
|
ObjType = enum( :obj_type, obj_types )
|
39
19
|
|
20
|
+
attach_function :hwloc_obj_type_string, [:obj_type], :string
|
40
21
|
attach_function :hwloc_compare_types, [:obj_type, :obj_type], :int
|
41
22
|
|
23
|
+
if API_VERSION >= API_VERSION_2_0 then
|
24
|
+
attach_function :hwloc_obj_type_is_normal, [:obj_type], :int
|
25
|
+
attach_function :hwloc_obj_type_is_io, [:obj_type], :int
|
26
|
+
attach_function :hwloc_obj_type_is_memory, [:obj_type], :int
|
27
|
+
attach_function :hwloc_obj_type_is_cache, [:obj_type], :int
|
28
|
+
attach_function :hwloc_obj_type_is_dcache, [:obj_type], :int
|
29
|
+
attach_function :hwloc_obj_type_is_icache, [:obj_type], :int
|
30
|
+
end
|
31
|
+
|
42
32
|
def self.compare_types(type1, type2)
|
43
33
|
return Hwloc.hwloc_compare_types(type1, type2)
|
44
34
|
end
|
@@ -144,9 +134,9 @@ module Hwloc
|
|
144
134
|
:DISTANCES_KIND_MEANS_BANDWIDTH
|
145
135
|
])
|
146
136
|
|
147
|
-
|
148
|
-
:
|
149
|
-
:
|
137
|
+
DistancesAddFlag = bitmask(FFI::find_type(:ulong), :distances_add_flag, [
|
138
|
+
:DISTANCES_ADD_FLAG_GROUP,
|
139
|
+
:DISTANCES_ADD_FLAG_GROUP_INACCURATE
|
150
140
|
])
|
151
141
|
|
152
142
|
class Distances < Struct
|
@@ -157,26 +147,42 @@ module Hwloc
|
|
157
147
|
|
158
148
|
def objs
|
159
149
|
arity = self[:nbobjs]
|
160
|
-
if arity == 0
|
161
|
-
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
150
|
+
return [] if arity == 0
|
151
|
+
return self[:objs].read_array_of_pointer(arity).collect { |p|
|
152
|
+
c = Obj::new(p)
|
153
|
+
c.instance_variable_set(:@topology, @topology)
|
154
|
+
c
|
155
|
+
}
|
156
|
+
end
|
157
|
+
|
158
|
+
def kind
|
159
|
+
self[:kind]
|
169
160
|
end
|
170
161
|
|
171
162
|
def values
|
172
163
|
arity = self[:nbobjs]
|
173
|
-
arity
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
164
|
+
return [] if arity == 0
|
165
|
+
return self[:values].read_array_of_uint64(arity*arity).each_slice(arity).to_a
|
166
|
+
end
|
167
|
+
|
168
|
+
def self.release(ptr)
|
169
|
+
Hwloc.hwloc_distances_release(@topology.ptr, ptr)
|
179
170
|
end
|
171
|
+
|
172
|
+
def obj_index(obj)
|
173
|
+
arity = self[:nbobjs]
|
174
|
+
return nil if arity == 0
|
175
|
+
self[:objs].read_array_of_pointer(arity).index(obj.to_ptr)
|
176
|
+
end
|
177
|
+
|
178
|
+
def obj_pair_values(obj1, obj2)
|
179
|
+
i1 = obj_index(obj1)
|
180
|
+
i2 = obj_index(obj2)
|
181
|
+
return nil unless i1 && i2
|
182
|
+
v = values
|
183
|
+
return [v[i1][i2], v[i2][i1]]
|
184
|
+
end
|
185
|
+
|
180
186
|
end
|
181
187
|
end
|
182
188
|
|
@@ -213,6 +219,20 @@ module Hwloc
|
|
213
219
|
end
|
214
220
|
end
|
215
221
|
|
222
|
+
class NumanodeAttr < Struct
|
223
|
+
layout :local_memory, :uint64,
|
224
|
+
:page_types_len, :uint,
|
225
|
+
:page_types, :pointer
|
226
|
+
def page_types
|
227
|
+
page_types_ptr = self[:page_types]
|
228
|
+
return page_types_len.times.collect { |i|
|
229
|
+
pt = ObjMemoryPageType::new(page_types_ptr+i*ObjMemoryPageType.size)
|
230
|
+
pt.instance_variable_set(:@topology, @topology)
|
231
|
+
pt
|
232
|
+
}
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
216
236
|
class CacheAttr < Struct
|
217
237
|
layout :size, :uint64,
|
218
238
|
:depth, :uint,
|
@@ -276,23 +296,28 @@ module Hwloc
|
|
276
296
|
end
|
277
297
|
|
278
298
|
class ObjAttr < Union
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
299
|
+
if API_VERSION < API_VERSION_2_0 then
|
300
|
+
layout :cache, CacheAttr,
|
301
|
+
:group, GroupAttr,
|
302
|
+
:pcidev, PcidevAttr,
|
303
|
+
:bridge, BridgeAttr,
|
304
|
+
:osdev, OsdevAttr
|
305
|
+
else
|
306
|
+
layout :numanode, NumanodeAttr,
|
307
|
+
:cache, CacheAttr,
|
308
|
+
:group, GroupAttr,
|
309
|
+
:pcidev, PcidevAttr,
|
310
|
+
:bridge, BridgeAttr,
|
311
|
+
:osdev, OsdevAttr
|
312
|
+
end
|
284
313
|
end
|
285
314
|
|
286
315
|
class Obj < Struct
|
287
316
|
end
|
288
317
|
|
289
|
-
if API_VERSION < API_VERSION_2_0 then
|
290
|
-
attach_function :hwloc_obj_type_string, [:obj_type], :string
|
291
|
-
else
|
292
|
-
attach_function :hwloc_type_name, [:obj_type], :string
|
293
|
-
end
|
294
318
|
attach_function :hwloc_obj_type_snprintf, [:pointer, :size_t, Obj.ptr, :int], :int
|
295
319
|
attach_function :hwloc_obj_attr_snprintf, [:pointer, :size_t, Obj.ptr, :string, :int], :int
|
320
|
+
attach_function :hwloc_obj_add_info, [Obj.ptr, :string, :string], :int
|
296
321
|
|
297
322
|
class Obj
|
298
323
|
if API_VERSION < API_VERSION_2_0 then
|
@@ -331,39 +356,39 @@ module Hwloc
|
|
331
356
|
]
|
332
357
|
else
|
333
358
|
layout_array = [
|
334
|
-
:type,
|
335
|
-
:subtype,
|
336
|
-
:os_index,
|
337
|
-
:name,
|
338
|
-
:
|
339
|
-
:attr,
|
340
|
-
:depth,
|
341
|
-
:logical_index,
|
342
|
-
:next_cousin,
|
343
|
-
:prev_cousin,
|
344
|
-
:parent,
|
345
|
-
:sibling_rank,
|
346
|
-
:next_sibling,
|
347
|
-
:prev_sibling,
|
348
|
-
:arity,
|
349
|
-
:children,
|
350
|
-
:first_child,
|
351
|
-
:last_child,
|
352
|
-
:symmetric_subtree
|
353
|
-
:
|
354
|
-
:
|
355
|
-
:
|
356
|
-
:
|
357
|
-
:
|
358
|
-
:
|
359
|
-
:
|
360
|
-
:
|
361
|
-
:
|
362
|
-
:
|
363
|
-
:infos,
|
364
|
-
:infos_count,
|
365
|
-
:user_data,
|
366
|
-
:gp_index,
|
359
|
+
:type, :obj_type,
|
360
|
+
:subtype, :string,
|
361
|
+
:os_index, :uint,
|
362
|
+
:name, :string,
|
363
|
+
:total_memory, :uint64,
|
364
|
+
:attr, ObjAttr.ptr,
|
365
|
+
:depth, :uint,
|
366
|
+
:logical_index, :uint,
|
367
|
+
:next_cousin, Obj.ptr,
|
368
|
+
:prev_cousin, Obj.ptr,
|
369
|
+
:parent, Obj.ptr,
|
370
|
+
:sibling_rank, :uint,
|
371
|
+
:next_sibling, Obj.ptr,
|
372
|
+
:prev_sibling, Obj.ptr,
|
373
|
+
:arity, :uint,
|
374
|
+
:children, :pointer,
|
375
|
+
:first_child, Obj.ptr,
|
376
|
+
:last_child, Obj.ptr,
|
377
|
+
:symmetric_subtree, :int,
|
378
|
+
:memory_arity, :uint,
|
379
|
+
:memory_first_child,Obj.ptr,
|
380
|
+
:io_arity, :uint,
|
381
|
+
:io_first_child, Obj.ptr,
|
382
|
+
:misc_arity, :uint,
|
383
|
+
:misc_first_child, Obj.ptr,
|
384
|
+
:cpuset, :cpuset,
|
385
|
+
:complete_cpuset, :cpuset,
|
386
|
+
:nodeset, :nodeset,
|
387
|
+
:complete_nodeset, :nodeset,
|
388
|
+
:infos, :pointer,
|
389
|
+
:infos_count, :uint,
|
390
|
+
:user_data, :pointer,
|
391
|
+
:gp_index, :uint64
|
367
392
|
]
|
368
393
|
end
|
369
394
|
|
@@ -380,16 +405,10 @@ module Hwloc
|
|
380
405
|
return str_ptr.read_string
|
381
406
|
end
|
382
407
|
|
383
|
-
|
384
|
-
|
385
|
-
return Hwloc.hwloc_obj_type_string(type)
|
386
|
-
end
|
387
|
-
alias type_name type_string
|
388
|
-
else
|
389
|
-
def type_name
|
390
|
-
return Hwloc.hwloc_type_name(type)
|
391
|
-
end
|
408
|
+
def type_string
|
409
|
+
return Hwloc.hwloc_obj_type_string(type)
|
392
410
|
end
|
411
|
+
alias type_name type_string
|
393
412
|
|
394
413
|
def attr_snprintf(verbose=0, separator=",")
|
395
414
|
sz = Hwloc.hwloc_obj_attr_snprintf(nil, 0, self, separator, verbose) + 1
|
@@ -477,6 +496,20 @@ module Hwloc
|
|
477
496
|
|
478
497
|
else
|
479
498
|
|
499
|
+
def memory_children
|
500
|
+
return [] if memory_arity == 0
|
501
|
+
c = []
|
502
|
+
c.push( memory_first_child )
|
503
|
+
(memory_arity-1).times {
|
504
|
+
c.push( c[-1].next_sibling )
|
505
|
+
}
|
506
|
+
return c
|
507
|
+
end
|
508
|
+
|
509
|
+
def each_memory_child(*args, &block)
|
510
|
+
return memory_children.each(*args, &block)
|
511
|
+
end
|
512
|
+
|
480
513
|
def io_children
|
481
514
|
return [] if io_arity == 0
|
482
515
|
c = []
|
@@ -571,22 +604,27 @@ module Hwloc
|
|
571
604
|
|
572
605
|
def infos
|
573
606
|
infos_count = self[:infos_count]
|
574
|
-
if infos_count == 0
|
575
|
-
|
576
|
-
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
inf_array.each { |e| inf_h[e[:name].to_sym] = e[:value] }
|
582
|
-
return inf_h
|
583
|
-
end
|
607
|
+
return {} if infos_count == 0
|
608
|
+
inf_array = infos_count.times.collect { |i|
|
609
|
+
o = ObjInfo::new(self[:infos] + i*ObjInfo.size)
|
610
|
+
}
|
611
|
+
inf_h = {}
|
612
|
+
inf_array.each { |e| inf_h[e[:name].to_sym] = e[:value] if e[:name] }
|
613
|
+
return inf_h
|
584
614
|
end
|
585
615
|
|
586
616
|
def each_info(*args, &block)
|
587
617
|
return infos.each(*args, &block)
|
588
618
|
end
|
589
619
|
|
620
|
+
def add_infos(**dict)
|
621
|
+
dict.each { |k, v|
|
622
|
+
err = Hwloc.hwloc_obj_add_info(self, k.to_s, v.to_s)
|
623
|
+
raise EditionError if err == -1
|
624
|
+
}
|
625
|
+
self
|
626
|
+
end
|
627
|
+
|
590
628
|
def attr
|
591
629
|
at = self[:attr]
|
592
630
|
return nil if at.to_ptr.null?
|
@@ -601,6 +639,9 @@ module Hwloc
|
|
601
639
|
when :OBJ_OS_DEVICE
|
602
640
|
return at[:osdev]
|
603
641
|
else
|
642
|
+
if API_VERSION >= API_VERSION_2_0 then
|
643
|
+
return at[:numanode] if t == :OBJ_NUMANODE
|
644
|
+
end
|
604
645
|
return at[:cache] if self.is_a_cache?
|
605
646
|
end
|
606
647
|
return nil
|
@@ -618,6 +659,34 @@ module Hwloc
|
|
618
659
|
def is_a_cache?
|
619
660
|
(Hwloc::OBJ_L1CACHE..Hwloc::OBJ_L3ICACHE).include?(ObjType[type])
|
620
661
|
end
|
662
|
+
|
663
|
+
def is_normal?
|
664
|
+
Hwloc::hwloc_obj_type_is_normal(ObjType[type]) == 1
|
665
|
+
end
|
666
|
+
|
667
|
+
def is_io?
|
668
|
+
Hwloc::hwloc_obj_type_is_io(ObjType[type]) == 1
|
669
|
+
end
|
670
|
+
|
671
|
+
def is_memory?
|
672
|
+
Hwloc::hwloc_obj_type_is_memory(ObjType[type]) == 1
|
673
|
+
end
|
674
|
+
|
675
|
+
def is_cache?
|
676
|
+
Hwloc::hwloc_obj_type_is_cache(ObjType[type]) == 1
|
677
|
+
end
|
678
|
+
|
679
|
+
def is_icache?
|
680
|
+
Hwloc::hwloc_obj_type_is_icache(ObjType[type]) == 1
|
681
|
+
end
|
682
|
+
|
683
|
+
def is_dcache?
|
684
|
+
Hwloc::hwloc_obj_type_is_dcache(ObjType[type]) == 1
|
685
|
+
end
|
686
|
+
|
687
|
+
def is_misc?
|
688
|
+
ObjType[type] == Hwloc::OBJ_MISC
|
689
|
+
end
|
621
690
|
end
|
622
691
|
|
623
692
|
end
|
data/lib/hwloc/Topology.rb
CHANGED
@@ -101,10 +101,10 @@ module Hwloc
|
|
101
101
|
attach_function :hwloc_topology_set_custom, [:topology], :int
|
102
102
|
attach_function :hwloc_topology_set_distance_matrix, [:topology, :obj_type, :uint, :pointer, :pointer], :int
|
103
103
|
else
|
104
|
-
attach_function :hwloc_distances_get, [:topology, :pointer, :pointer, :
|
105
|
-
attach_function :hwloc_distances_get_by_depth, [:topology, :uint, :pointer, :pointer, :
|
104
|
+
attach_function :hwloc_distances_get, [:topology, :pointer, :pointer, :distances_kind, :ulong], :int
|
105
|
+
attach_function :hwloc_distances_get_by_depth, [:topology, :uint, :pointer, :pointer, :distances_kind, :ulong], :int
|
106
106
|
attach_function :hwloc_distances_release, [:topology, Distances.ptr], :void
|
107
|
-
attach_function :hwloc_distances_add, [:topology, :uint, :pointer, :pointer, :
|
107
|
+
attach_function :hwloc_distances_add, [:topology, :uint, :pointer, :pointer, :distances_kind, :distances_add_flag], :int
|
108
108
|
attach_function :hwloc_distances_remove, [:topology], :int
|
109
109
|
attach_function :hwloc_distances_remove_by_depth, [:topology, :uint], :int
|
110
110
|
end
|
@@ -182,6 +182,13 @@ module Hwloc
|
|
182
182
|
err = Hwloc.hwloc_topology_dup(ptr, arg.ptr)
|
183
183
|
raise TopologyError if err == -1
|
184
184
|
@ptr = FFI::AutoPointer::new( ptr.read_pointer, Hwloc.method(:hwloc_topology_destroy) )
|
185
|
+
elsif arg.kind_of?( String ) then
|
186
|
+
ptr = FFI::MemoryPointer::new( :pointer )
|
187
|
+
err = Hwloc.hwloc_topology_init(ptr)
|
188
|
+
raise TopologyError if err == -1
|
189
|
+
@ptr = FFI::AutoPointer::new( ptr.read_pointer, Hwloc.method(:hwloc_topology_destroy) )
|
190
|
+
@xml_buffer = FFI::MemoryPointer::from_string(arg)
|
191
|
+
set_xmlbuffer(@xml_buffer)
|
185
192
|
else
|
186
193
|
raise TopologyError, "Invalid argument"
|
187
194
|
end
|
@@ -193,6 +200,7 @@ module Hwloc
|
|
193
200
|
def load
|
194
201
|
err = Hwloc.hwloc_topology_load(@ptr)
|
195
202
|
raise TopologyError if err == -1
|
203
|
+
@xml_buffer = nil if @xml_buffer
|
196
204
|
return self
|
197
205
|
end
|
198
206
|
|
@@ -446,20 +454,22 @@ module Hwloc
|
|
446
454
|
end
|
447
455
|
return self
|
448
456
|
else
|
449
|
-
|
450
|
-
idx = 0
|
451
|
-
while o = get_obj_by_depth(depth, idx) do
|
452
|
-
yielder << o
|
453
|
-
idx += 1
|
454
|
-
end
|
455
|
-
end
|
457
|
+
to_enum(:each_by_depth, depth)
|
456
458
|
end
|
457
459
|
end
|
458
460
|
|
459
461
|
def each_by_type(type, &block)
|
460
|
-
|
461
|
-
|
462
|
-
|
462
|
+
if block_given? then
|
463
|
+
depth = get_type_depth(type)
|
464
|
+
if depth == Hwloc::TYPE_DEPTH_MULTIPLE
|
465
|
+
each_obj.select{ |e| e.type == type }.each(&block)
|
466
|
+
return self
|
467
|
+
else
|
468
|
+
return each_by_depth(depth, &block)
|
469
|
+
end
|
470
|
+
else
|
471
|
+
to_enum(:each_by_type, type)
|
472
|
+
end
|
463
473
|
end
|
464
474
|
|
465
475
|
ObjType.symbols[0..-1].each { |sym|
|
@@ -487,6 +497,99 @@ module Hwloc
|
|
487
497
|
alias traverse each_obj
|
488
498
|
alias each each_obj
|
489
499
|
|
500
|
+
if API_VERSION >= API_VERSION_2_0 then
|
501
|
+
|
502
|
+
def distances_number(*kind)
|
503
|
+
res = nil
|
504
|
+
nr = FFI::MemoryPointer::new(:uint)
|
505
|
+
nr.write_uint 0
|
506
|
+
err = Hwloc.hwloc_distances_get(@ptr, nr, nil, kind, 0);
|
507
|
+
raise TopologyError if err == -1
|
508
|
+
res = nr.read_uint
|
509
|
+
res
|
510
|
+
end
|
511
|
+
|
512
|
+
def distances(*kind)
|
513
|
+
num_d = distances_number(*kind)
|
514
|
+
return [] if num_d == 0
|
515
|
+
nr = FFI::MemoryPointer::new(:uint)
|
516
|
+
nr.write_uint num_d
|
517
|
+
dis = FFI::MemoryPointer::new(:pointer, num_d)
|
518
|
+
err = Hwloc.hwloc_distances_get(@ptr, nr, dis, kind, 0);
|
519
|
+
raise TopologyError if err == -1
|
520
|
+
return dis.read_array_of_pointer(nr.read_uint).collect { |p|
|
521
|
+
d = Distances::new(p)
|
522
|
+
d.instance_variable_set(:@topology, self)
|
523
|
+
d
|
524
|
+
}
|
525
|
+
end
|
526
|
+
|
527
|
+
def distances_by_depth(depth, *kind)
|
528
|
+
nr = FFI::MemoryPointer::new(:uint)
|
529
|
+
nr.write_uint 0
|
530
|
+
err = Hwloc.hwloc_distances_get_by_depth(@ptr, depth, nr, nil, kind, 0);
|
531
|
+
raise TopologyError if err == -1
|
532
|
+
num_d = nr.read_uint
|
533
|
+
return [] if num_d == 0
|
534
|
+
dis = FFI::MemoryPointer::new(:pointer, num_d)
|
535
|
+
err = Hwloc.hwloc_distances_get_by_depth(@ptr, depth, nr, dis, kind, 0);
|
536
|
+
return dis.read_array_of_pointer(nr.read_uint).collect { |p|
|
537
|
+
d = Distances::new(p)
|
538
|
+
d.instance_variable_set(:@topology, self)
|
539
|
+
d
|
540
|
+
}
|
541
|
+
end
|
542
|
+
|
543
|
+
def distances_by_type(type, *kind)
|
544
|
+
depth = get_type_depth(type)
|
545
|
+
return [] if depth == Hwloc::TYPE_DEPTH_UNKNOWN
|
546
|
+
if depth == Hwloc::TYPE_DEPTH_MULTIPLE then
|
547
|
+
depth_list = each_obj.select{ |e| e.type == type }.collect{ |e| e.depth }.uniq
|
548
|
+
res = depth_list.collect { |d| distances_by_depth(d, *kind) }.reduce(:+)
|
549
|
+
return [] unless res
|
550
|
+
return res
|
551
|
+
end
|
552
|
+
return distances_by_depth(depth, *kind)
|
553
|
+
end
|
554
|
+
|
555
|
+
def distances_add(objs, values, *kind, flags: [])
|
556
|
+
nbobjs = objs.size
|
557
|
+
vals = values.flatten
|
558
|
+
raise TopologyError if vals.length != nbobjs * nbobjs
|
559
|
+
vals_p = FFI::MemoryPointer::new(:uint64, vals.length)
|
560
|
+
vals_p.write_array_of_uint64(vals)
|
561
|
+
objs_p = FFI::MemoryPointer::new(:pointer, objs.length)
|
562
|
+
objs_p.write_array_of_pointer(objs.collect(&:to_ptr))
|
563
|
+
err = Hwloc.hwloc_distances_add(@ptr, nbobjs, objs_p, vals_p, kind, flags)
|
564
|
+
raise TopologyError if err == -1
|
565
|
+
self
|
566
|
+
end
|
567
|
+
|
568
|
+
def distances_remove
|
569
|
+
err = Hwloc.hwloc_distances_remove(@ptr)
|
570
|
+
raise TopologyError if err == -1
|
571
|
+
self
|
572
|
+
end
|
573
|
+
|
574
|
+
def distances_remove_by_depth(depth)
|
575
|
+
err = Hwloc.hwloc_distances_remove_by_depth(@ptr, depth)
|
576
|
+
raise TopologyError if err == -1
|
577
|
+
self
|
578
|
+
end
|
579
|
+
|
580
|
+
def distances_remove_by_type(type)
|
581
|
+
depth = get_type_depth(type)
|
582
|
+
return self if depth == Hwloc::TYPE_DEPTH_UNKNOWN
|
583
|
+
if depth == Hwloc::TYPE_DEPTH_MULTIPLE then
|
584
|
+
depth_list = each_obj.select{ |e| e.type == type }.collect{ |e| e.depth }.uniq
|
585
|
+
depth_list.each { |d| distances_remove_by_depth(d) }
|
586
|
+
return self
|
587
|
+
end
|
588
|
+
return distances_remove_by_depth(depth)
|
589
|
+
end
|
590
|
+
|
591
|
+
end
|
592
|
+
|
490
593
|
end
|
491
594
|
|
492
595
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: hwloc
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.3.
|
4
|
+
version: 0.3.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brice Videau
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2020-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: ffi
|
@@ -86,8 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
86
86
|
- !ruby/object:Gem::Version
|
87
87
|
version: '0'
|
88
88
|
requirements: []
|
89
|
-
|
90
|
-
rubygems_version: 2.5.2
|
89
|
+
rubygems_version: 3.1.2
|
91
90
|
signing_key:
|
92
91
|
specification_version: 4
|
93
92
|
summary: hwloc ruby bindings
|