harvard-acc / ALADDIN

A pre-RTL, power-performance model for fixed-function accelerators
Other
170 stars 55 forks source link

About Aladdin's Input #30

Closed lhanzhang123 closed 4 years ago

lhanzhang123 commented 4 years ago

Sorry , i got a question about Aladdin's input . Can C++ use as a input ? or only C ? Because paper indicate that Aladdin can use C only , but i try a simple C++ file as a input , Aladdin can also execute .

xyzsam commented 4 years ago

When you write a program for Aladdin, there are two parts: the kernel that Aladdin converts into an accelerator model, and all the surrounding code (e.g. main, reading from input files, etc). The kernel must be C, but the surrounding code can be C++. Example:

extern "C" {
void my_kernel(int* array, size) {
  // This is the function that gets traced by LLVM-Tracer.
  // this MUST be C
}
}
int main() {
  // Surrounding code can use C++.
  std::vector<int> data{1,2,3,4};
  my_kernel(data.data(), data.size());
}

Note the extern "C" block - that ensures C-style linkage, so you don't need to worry about C++ name mangling.

lhanzhang123 commented 4 years ago

it's clear to me ! thank you !