Skip to content

Commit c2ff76b

Browse files
Removed warnings
removed alloc of static arrays with dynamic sizes on stack, and return of stack array values Signed-off-by: Alexandre Eichenberger <[email protected]>
1 parent 8f4d85f commit c2ff76b

File tree

3 files changed

+11
-7
lines changed

3 files changed

+11
-7
lines changed

src/Accelerators/NNPA/Support/Stickify/Stickify.cpp

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -969,7 +969,9 @@ zdnn_status transform_ztensor(const void *in_buf, zdnn_ztensor *ztensor) {
969969
fields_to_convert = ztensor->transformed_desc->dim2;
970970

971971
// convert_data_format() will dump the converted entries here
972-
uint16_t temp_buff[fields_to_convert];
972+
uint16_t *temp_buff =
973+
(uint16_t *)malloc(fields_to_convert * sizeof(uint16_t));
974+
assert(temp_buff && "failed to allocate temp buff");
973975

974976
// number of bytes to jump from the beginning of the last C-stick to the
975977
// next page-boundary
@@ -1057,7 +1059,8 @@ zdnn_status transform_ztensor(const void *in_buf, zdnn_ztensor *ztensor) {
10571059
// done with all the C/H/W, go to the next n
10581060
output_offset = out_offset_n + bytes_per_n;
10591061
}
1060-
}
1062+
free(temp_buff);
1063+
} // End of if NCHW
10611064
} else if (ztensor->transformed_desc->layout == ZDNN_HWCK) {
10621065

10631066
uint64_t bytes_per_h =
@@ -1420,7 +1423,8 @@ zdnn_status stickify(zdnn_ztensor *ztensor, ...) {
14201423

14211424
// Save the gate data for slicing later.
14221425
// (e.g., LSTM) va_arg order: F (FWD,BWD), I (FWD,BWD), C...etc.
1423-
void *gate_data[num_gates];
1426+
void **gate_data = (void **)malloc(num_gates * sizeof(void *));
1427+
assert(gate_data && "failed to allocate data");
14241428
for (uint8_t i = 0; i < num_gates; i++) {
14251429
gate_data[i] = va_arg(argptr, void *);
14261430
}
@@ -1508,7 +1512,7 @@ zdnn_status stickify(zdnn_ztensor *ztensor, ...) {
15081512
// Set that the output ztensor has completed transformation.
15091513
ztensor->is_transformed = true;
15101514
}
1511-
1515+
free(gate_data);
15121516
} while (false);
15131517

15141518
} else {

src/Dialect/ONNX/DialectBuilder.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -555,7 +555,7 @@ TensorType OnnxBuilder::toTensor(Type input) const {
555555
return RankedTensorType::get(aTy.getShape(), elementTy);
556556
}
557557

558-
TypeRange OnnxBuilder::toTensors(TypeRange inputs) const {
558+
SmallVector<Type, 4> OnnxBuilder::toTensors(TypeRange inputs) const {
559559
if (llvm::all_of(inputs, [](Type t) { return (mlir::isa<TensorType>(t)); }))
560560
return inputs;
561561
assert(llvm::all_of(inputs, [](Type t) {
@@ -570,7 +570,7 @@ TypeRange OnnxBuilder::toTensors(TypeRange inputs) const {
570570
}
571571
resultTypes.emplace_back(RankedTensorType::get(aTy.getShape(), elementTy));
572572
}
573-
return TypeRange(resultTypes);
573+
return resultTypes;
574574
}
575575

576576
Value OnnxBuilder::toMemref(Value input) const {

src/Dialect/ONNX/DialectBuilder.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -232,7 +232,7 @@ struct OnnxBuilder : DialectBuilder {
232232
// Convert a Type to TensorType if it is of MemRefType.
233233
mlir::TensorType toTensor(mlir::Type input) const;
234234
// Convert Type to TypeRange of TensorType if it is of MemRefType.
235-
mlir::TypeRange toTensors(mlir::TypeRange inputs) const;
235+
mlir::SmallVector<mlir::Type, 4> toTensors(mlir::TypeRange inputs) const;
236236
// Convert a Value to MemrefType if it is of TensorType.
237237
mlir::Value toMemref(mlir::Value input) const;
238238

0 commit comments

Comments
 (0)