SMAUG
Simulating Machine Learning Applications on gem5-Aladdin
ref_eltwise_add_op.cpp
1 #include "smaug/core/backend.h"
3 #include "smaug/operators/eltwise_add_op.h"
4 
5 #ifdef __cplusplus
6 extern "C" {
7 #endif
8 
13 void ref_eltwise_add(float* input0,
14  float* input1,
15  float* results,
16  int input_size) {
17  dmaLoad(input0, input0, input_size * sizeof(float));
18  dmaLoad(input1, input1, input_size * sizeof(float));
19  eltwise_add_loop:
20  for (int i = 0; i < input_size; i++) {
21  results[i] = input0[i] + input1[i];
22  }
23  dmaStore(results, results, input_size * sizeof(float));
24 }
25 
26 #ifdef __cplusplus
27 }
28 #endif
29 
30 namespace smaug {
31 
32 template <>
33 void EltwiseAddOp<ReferenceBackend>::run() {
34  auto input0 = getInput(Input0);
35  auto input1 = getInput(Input1);
36  auto output = getOutput(Outputs);
37  const TensorShape& input0Shape = input0->getShape();
38  const TensorShape& input1Shape = input1->getShape();
39  const TensorShape& outputShape = output->getShape();
40  assert(input0Shape == input1Shape && input0Shape == outputShape);
41 
42  float* input0Data = input0->data<float>();
43  float* input1Data = input1->data<float>();
44  float* outputData = output->data<float>();
45  mapArrayToAccel(ref::kEltwiseOpHw, "input0", input0Data,
46  input0Shape.storageSize() * sizeof(float));
47  mapArrayToAccel(ref::kEltwiseOpHw, "input1", input1Data,
48  input1Shape.storageSize() * sizeof(float));
49  mapArrayToAccel(ref::kEltwiseOpHw, "results", outputData,
50  outputShape.storageSize() * sizeof(float));
51  invokeKernel(ref::kEltwiseOpHw, ref_eltwise_add, input0Data, input1Data,
52  outputData, input0Shape.size());
53 }
54 
55 } // namespace smaug
56 
smaug
The smaug namespace is the parent namespace of all C++ code in SMAUG.
Definition: backend.cpp:38
common.h
Utilities for writing and invoking Aladdin kernels from Operators.
ref_eltwise_add
void ref_eltwise_add(float *input0, float *input1, float *results, int input_size)
Definition: ref_eltwise_add_op.cpp:13
smaug::mapArrayToAccel
void mapArrayToAccel(unsigned reqCode, const char *arrayName, void *baseAddr, size_t size)
Maps an array of data to the accelerator.
Definition: common.cpp:12
smaug::invokeKernel
void invokeKernel(int accelIdx, unsigned reqCode, const Kernel &kernel, Args &&... args)
The generic blocking interface for all accelerator kernel functions.
Definition: common.h:72