}
void AclCppOpGenerator::visit(ops::ConstantOp& op) {
- // TODO: NIY
- assert(false);
+ Shape out_shape = op.getOutputShape(0);
+ TensorVariant data = op.getValue();
+
+ Shape transposed_shape;
+ // FIXME This is temporary solution,
+ // need to move this shape transposes into genTensor function and
+ // implement transpose operation to support ranks greater than 2
+ switch (out_shape.rank()) {
+ case 2:
+ transposed_shape = transposeShape<1, 0>(out_shape);
+ break;
+ case 1:
+ transposed_shape = out_shape;
+ break;
+ default:
+ throw AclCppException("Unsupported number of dimensions: " + to_string(out_shape.rank()));
+ }
+
+ shared_ptr<ArtifactId> out = genTensor(op, transposed_shape);
+
+ allocate(out);
+ // Serialize the weights tensor and generate the function to deserialize it in the artifact.
+ serializeTensor(out, data);
}
void AclCppOpGenerator::visit(ops::ReluOp& op) {
#include "core/modelIR/operations/ReluOp.h"
#include "core/modelIR/operations/ReduceFOp.h"
#include "core/modelIR/operations/CappedReluOp.h"
+#include "core/modelIR/operations/ConstantOp.h"
#include "core/modelIR/operations/ReshapeOp.h"
#include "core/modelIR/operations/ConcatOp.h"
#include "core/modelIR/operations/BiasAddOp.h"
TensorVariant createTensorVariant(const Shape& shape) {
size_t data_size = shape.numElements();
- shared_ptr<float> data(new float[data_size], default_delete<float[]>());
- return TensorVariant(shape, data, DTYPE::FLOAT32);
+ float* data = new float[data_size];
+ for (int32_t i = 0; i < shape.numElements(); ++i)
+ data[i] = i;
+
+ shared_ptr<float> ptr(data, default_delete<float[]>());
+ return TensorVariant(shape, ptr, DTYPE::FLOAT32);
}
}
+#include <fstream>
+
// Actual tests
+TEST(acl_backend_mir_to_dom, constant) {
+ Shape shape{3, 4};
+ TensorVariant constant_data = createTensorVariant(shape);
+
+ Graph g;
+ OpConstructor op_generator = [&constant_data](Graph& g, const vector<IODescriptor>& inputs) {
+ return g.create<mir::ops::ConstantOp>("data", constant_data);
+ };
+
+ fillGraph(g, op_generator, {});
+
+ stringstream params_out;
+ AclCppOpGenerator dom_gen(artifactName, params_out);
+
+ const ArtifactModule& m = dom_gen.generate(&g);
+
+ checkDomStructure(m, {}, {});
+}
+
TEST(acl_backend_mir_to_dom, bias) {
const int32_t channels = 2;
TensorVariant w = createTensorVariant({channels});