@@ -77,9 +77,11 @@ llvm::Error Partitioner::finalize(const DAGListTy &partitions,
77
77
78
78
// Validate the functions after partitioning.
79
79
for (Function *subF : module_->getFunctions ()) {
80
- RETURN_ERR_IF_NOT (subF->verify (),
81
- strFormat (" Conversion led to invalid function: %s" ,
82
- subF->getName ().str ().data ()));
80
+ if (!subF->verify ()) {
81
+ return MAKE_ERR (GlowErr::ErrorCode::PARTITIONER_ERROR,
82
+ " Conversion led to invalid function " +
83
+ subF->getName ().str ());
84
+ }
83
85
}
84
86
85
87
if (logPartition) {
@@ -94,8 +96,10 @@ llvm::Error Partitioner::finalize(const DAGListTy &partitions,
94
96
if (dumpPartition) {
95
97
for (const auto &node : partitions[0 ].nodes ) {
96
98
Function *subF = module_->getFunction (node->name );
97
- RETURN_ERR_IF_NOT (
98
- subF, strFormat (" Invalid function name %s." , node->name .data ()));
99
+ if (!subF) {
100
+ return MAKE_ERR (GlowErr::ErrorCode::PARTITIONER_ERROR,
101
+ " Invalid function name " + node->name );
102
+ }
99
103
subF->dumpDAG (" partitionLogicalID" +
100
104
std::to_string (node->logicalDevices [0 ]) + " __" +
101
105
subF->getName ().str () + " __" + node->backendName + " .dot" );
@@ -284,8 +288,10 @@ llvm::Expected<DAGListTy> Partitioner::backendBasedPartition(
284
288
break ;
285
289
}
286
290
}
287
- RETURN_ERR_IF_NOT (nodeToBackendName.find (&N) != nodeToBackendName.end (),
291
+ if (nodeToBackendName.find (&N) == nodeToBackendName.end ()) {
292
+ return MAKE_ERR (GlowErr::ErrorCode::PARTITIONER_ERROR,
288
293
" Node is not supported by any of the provided backends" );
294
+ }
289
295
}
290
296
291
297
BFSLevel bfs = getBFSLevel (F);
@@ -427,11 +433,13 @@ llvm::Expected<DAGListTy> Partitioner::createDAGWithoutPartition(
427
433
llvm::Expected<DAGListTy>
428
434
Partitioner::loadBalancedPartition (CompilationContext &cctx,
429
435
size_t numDevices) {
430
- RETURN_ERR_IF_NOT (
431
- module_->getFunctions ().size () == 1 ,
432
- strFormat (" Invalid : %lu functions in a module. Now in load-balanced "
433
- " partition flow, the module can only contain 1 function" ,
434
- module_->getFunctions ().size ()));
436
+ if (module_->getFunctions ().size () != 1 ) {
437
+ return MAKE_ERR (
438
+ GlowErr::ErrorCode::PARTITIONER_ERROR,
439
+ strFormat (" Invalid : %lu functions in a module. Now in load-balanced "
440
+ " partition flow, the module can only contain 1 function" ,
441
+ module_->getFunctions ().size ()));
442
+ }
435
443
436
444
if (multiBackendNames_) {
437
445
VLOG (1 ) << " For multi backend types, load-balanced partition can't be "
@@ -570,8 +578,10 @@ Partitioner::loadBalancedPartition(CompilationContext &cctx,
570
578
}
571
579
572
580
// Throw error if we were not able to put this node into any partition
573
- RETURN_ERR_IF_NOT (curPartition < numDevices,
581
+ if (curPartition >= numDevices) {
582
+ return MAKE_ERR (GlowErr::ErrorCode::PARTITIONER_ERROR,
574
583
" Load balance partition error" );
584
+ }
575
585
}
576
586
}
577
587
for (size_t i = 0 ; i < numDevices; i++) {
@@ -601,12 +611,14 @@ llvm::Expected<DAGListTy>
601
611
Partitioner::quantizationProfilingPartition (CompilationContext &cctx) {
602
612
// For quantization profiling flow, currently we assume there is only 1
603
613
// function in a module.
604
- RETURN_ERR_IF_NOT (
605
- module_->getFunctions ().size () == 1 ,
606
- strFormat (
607
- " Invalid : %lu functions in a module. In quantization profiling "
608
- " partition flow, the module can only contain 1 function" ,
609
- module_->getFunctions ().size ()));
614
+ if (module_->getFunctions ().size () != 1 ) {
615
+ return MAKE_ERR (
616
+ GlowErr::ErrorCode::PARTITIONER_ERROR,
617
+ strFormat (
618
+ " Invalid : %lu functions in a module. In quantization profiling "
619
+ " partition flow, the module can only contain 1 function" ,
620
+ module_->getFunctions ().size ()));
621
+ }
610
622
611
623
// Quantization profiling flow is run under CPU backend, so we don't really
612
624
// need the concrete partition. The backendBasedPartition is necessary since
@@ -668,19 +680,24 @@ Partitioner::heterogeneousPartition(CompilationContext &cctx) {
668
680
}
669
681
// NOTE: the following error detection will be removed once multi-functions
670
682
// in a module is supported.
671
- RETURN_ERR_IF_NOT (
672
- module_->getFunctions ().size () == 1 ,
673
- strFormat (" Invalid : %lu functions in a module. Now in heterogeneous "
674
- " partition flow, the module can only contain 1 function" ,
675
- module_->getFunctions ().size ()));
683
+ if (module_->getFunctions ().size () != 1 ) {
684
+ return MAKE_ERR (
685
+ GlowErr::ErrorCode::PARTITIONER_ERROR,
686
+ strFormat (" Invalid : %lu functions in a module. Now in heterogeneous "
687
+ " partition flow, the module can only contain 1 function" ,
688
+ module_->getFunctions ().size ()));
689
+ }
676
690
} else {
677
691
// NOTE: the following error detection will be removed once multi-functions
678
692
// in a module is supported.
679
- RETURN_ERR_IF_NOT (
680
- module_->getFunctions ().size () == 1 ,
681
- strFormat (" Invalid : %lu functions in a module. Now in heterogeneous "
682
- " partition flow, the module can only contain 1 function" ,
683
- module_->getFunctions ().size ()));
693
+ if (module_->getFunctions ().size () != 1 ) {
694
+ return MAKE_ERR (
695
+ GlowErr::ErrorCode::PARTITIONER_ERROR,
696
+ strFormat (
697
+ " Invalid : %lu functions in a module. Now in heterogeneous partition\
698
+ flow, the module can only contain 1 function" ,
699
+ module_->getFunctions ().size ()));
700
+ }
684
701
ASSIGN_VALUE_OR_RETURN_ERR (
685
702
partitions, backendBasedPartition (funcToBackend, F_, backends, cctx));
686
703
module_->eraseFunction (F_);
@@ -750,8 +767,11 @@ Partitioner::partitionFromConfig(const PartitionConfig &partitionConfig) {
750
767
std::vector<Backend *> backends;
751
768
genBackendMap (backendMap_, backendHolder, backends);
752
769
Function *F = module_->getFunction (partitionConfig.funcName );
753
- RETURN_ERR_IF_NOT (F, strFormat (" Can't find function %s in current module." ,
754
- F->getName ().str ().data ()));
770
+ if (!F) {
771
+ return MAKE_ERR (GlowErr::ErrorCode::PARTITIONER_ERROR,
772
+ strFormat (" Can't find function %s in current module." ,
773
+ F->getName ().str ().data ()));
774
+ }
755
775
756
776
DCHECK (
757
777
partitionConfig.numOfPartitions == partitionConfig.backendNames .size () &&
0 commit comments