@@ -170,30 +170,6 @@ qvi_hwsplit::cpuset(void) const
170
170
return m_hwpools[0 ]->cpuset ();
171
171
}
172
172
173
- std::vector<pid_t > &
174
- qvi_hwsplit::tids (void )
175
- {
176
- return m_group_tids;
177
- }
178
-
179
- std::vector<int > &
180
- qvi_hwsplit::colors (void )
181
- {
182
- return m_colors;
183
- }
184
-
185
- std::vector<qvi_hwpool *> &
186
- qvi_hwsplit::hwpools (void )
187
- {
188
- return m_hwpools;
189
- }
190
-
191
- qvi_hwloc_cpusets_t &
192
- qvi_hwsplit::affinities (void )
193
- {
194
- return m_affinities;
195
- }
196
-
197
173
int
198
174
qvi_hwsplit::split_cpuset (
199
175
qvi_hwloc_cpusets_t &result
@@ -218,6 +194,63 @@ qvi_hwsplit::split_cpuset(
218
194
return rc;
219
195
}
220
196
197
+ int
198
+ qvi_hwsplit::thread_split (
199
+ qv_scope_t *parent,
200
+ uint_t npieces,
201
+ int *kcolors,
202
+ uint_t k,
203
+ qv_hw_obj_type_t maybe_obj_type,
204
+ qvi_hwpool ***khwpools
205
+ ) {
206
+ const uint_t group_size = k;
207
+ // Construct the hardware split.
208
+ qvi_hwsplit hwsplit (parent, group_size, npieces, maybe_obj_type);
209
+ // Eagerly make room for the group member information.
210
+ hwsplit.reserve ();
211
+ // Since this is called by a single task, get its ID and associated
212
+ // hardware affinity here, and replicate them in the following loop
213
+ // that populates splitagg.
214
+ // No point in doing this in a loop.
215
+ const pid_t taskid = qvi_task::mytid ();
216
+ // Get the task's current affinity.
217
+ hwloc_cpuset_t task_affinity = nullptr ;
218
+ int rc = parent->group ()->task ()->bind_top (&task_affinity);
219
+ if (qvi_unlikely (rc != QV_SUCCESS)) return rc;
220
+ // Prepare the hwsplit with our parent's information.
221
+ for (uint_t i = 0 ; i < group_size; ++i) {
222
+ // Store requested colors in aggregate.
223
+ hwsplit.m_colors [i] = kcolors[i];
224
+ // Since the parent hardware pool is the resource we are splitting and
225
+ // agg_split_* calls expect |group_size| elements, replicate by dups.
226
+ rc = qvi_dup (*parent->hwpool (), &hwsplit.m_hwpools [i]);
227
+ if (qvi_unlikely (rc != QV_SUCCESS)) break ;
228
+ // Since this is called by a single task, replicate its task ID, too.
229
+ hwsplit.m_group_tids [i] = taskid;
230
+ // Same goes for the task's affinity.
231
+ hwsplit.m_affinities [i].set (task_affinity);
232
+ }
233
+ // Cleanup: we don't need task_affinity anymore.
234
+ qvi_hwloc_bitmap_delete (&task_affinity);
235
+ if (qvi_unlikely (rc != QV_SUCCESS)) return rc;
236
+ // Split the hardware resources based on the provided split parameters.
237
+ rc = hwsplit.split ();
238
+ if (qvi_unlikely (rc != QV_SUCCESS)) return rc;
239
+ // Now populate the hardware pools as the result.
240
+ qvi_hwpool **ikhwpools = new qvi_hwpool *[group_size];
241
+ for (uint_t i = 0 ; i < group_size; ++i) {
242
+ // Copy out, since the hardware pools in splitagg will get freed.
243
+ rc = qvi_dup (*hwsplit.m_hwpools [i], &ikhwpools[i]);
244
+ if (qvi_unlikely (rc != QV_SUCCESS)) break ;
245
+ }
246
+ if (qvi_unlikely (rc != QV_SUCCESS)) {
247
+ delete[] ikhwpools;
248
+ ikhwpools = nullptr ;
249
+ }
250
+ *khwpools = ikhwpools;
251
+ return rc;
252
+ }
253
+
221
254
int
222
255
qvi_hwsplit::osdev_cpusets (
223
256
qvi_hwloc_cpusets_t &result
@@ -272,7 +305,6 @@ qvi_hwsplit::affinity_preserving_policy(void) const
272
305
}
273
306
}
274
307
275
- /* * Releases all devices contained in the provided split aggregate. */
276
308
int
277
309
qvi_hwsplit::release_devices (void )
278
310
{
@@ -452,12 +484,12 @@ int
452
484
qvi_hwsplit::split_affinity_preserving_pass1 (void )
453
485
{
454
486
// cpusets used for first mapping pass.
455
- qvi_hwloc_cpusets_t cpusets{} ;
487
+ qvi_hwloc_cpusets_t cpusets;
456
488
// Get the primary cpusets used for the first pass of mapping.
457
489
int rc = primary_cpusets (cpusets);
458
490
if (rc != QV_SUCCESS) return rc;
459
491
// Maintains the mapping between task (consumer) IDs and resource IDs.
460
- qvi_map_t map{} ;
492
+ qvi_map_t map;
461
493
// Map tasks based on their affinity to resources encoded by the cpusets.
462
494
const auto policy = affinity_preserving_policy ();
463
495
rc = qvi_map_affinity_preserving (
@@ -735,24 +767,24 @@ qvi_hwsplit_coll::gather_hwpools(
735
767
int
736
768
qvi_hwsplit_coll::gather (void )
737
769
{
738
- int rc = gather_values (qvi_task::mytid (), m_hwsplit.tids () );
770
+ int rc = gather_values (qvi_task::mytid (), m_hwsplit.m_group_tids );
739
771
if (qvi_unlikely (rc != QV_SUCCESS)) return rc;
740
- rc = gather_values (m_color, m_hwsplit.colors () );
772
+ rc = gather_values (m_color, m_hwsplit.m_colors );
741
773
if (qvi_unlikely (rc != QV_SUCCESS)) return rc;
742
774
// Note that the result hwpools are copies, so we can modify them freely.
743
- rc = gather_hwpools (m_parent->hwpool (), m_hwsplit.hwpools () );
775
+ rc = gather_hwpools (m_parent->hwpool (), m_hwsplit.m_hwpools );
744
776
if (qvi_unlikely (rc != QV_SUCCESS)) return rc;
745
777
746
778
const int myrank = m_parent->group ()->rank ();
747
779
const uint_t group_size = m_parent->group ()->size ();
748
780
if (myrank == qvi_hwsplit_coll::rootid) {
749
- m_hwsplit.affinities () .resize (group_size);
781
+ m_hwsplit.m_affinities .resize (group_size);
750
782
for (uint_t tid = 0 ; tid < group_size; ++tid) {
751
783
hwloc_cpuset_t cpuset = nullptr ;
752
784
rc = m_parent->group ()->task ()->bind_top (&cpuset);
753
785
if (qvi_unlikely (rc != QV_SUCCESS)) break ;
754
786
//
755
- rc = m_hwsplit.affinities () [tid].set (cpuset);
787
+ rc = m_hwsplit.m_affinities [tid].set (cpuset);
756
788
// Clean up.
757
789
qvi_hwloc_bitmap_delete (&cpuset);
758
790
if (qvi_unlikely (rc != QV_SUCCESS)) break ;
@@ -806,9 +838,9 @@ qvi_hwsplit_coll::scatter(
806
838
int *colorp,
807
839
qvi_hwpool **result
808
840
) {
809
- const int rc = scatter_values (m_hwsplit.colors () , colorp);
841
+ const int rc = scatter_values (m_hwsplit.m_colors , colorp);
810
842
if (qvi_unlikely (rc != QV_SUCCESS)) return rc;
811
- return scatter_hwpools (m_hwsplit.hwpools () , result);
843
+ return scatter_hwpools (m_hwsplit.m_hwpools , result);
812
844
}
813
845
814
846
int
0 commit comments