fpga: choosing c++ to program fpga
I keep hearing mostly from electrical engineers that C is used for fpga work.
What about C++? Are there any disadvantages to u开发者_运维知识库sing C++? I would think that the parallelism desired when programming for hardware would be better served by C++ more than C, no?
Also what do I use after that to make compatible c++ with the hardware?
I'm pretty sure that FPGAs are programmed either in VHDL or Verilog.
http://en.wikipedia.org/wiki/Vhdl
http://en.wikipedia.org/wiki/Verilog
I know that Altera also offers some C to HDL translators. I doubt that they are usable for anything but tiny designs though.
By far and away the easiest way to program an FPGA is via LabView's FPGA module. However this also ties you into their hardware and software. Not a cheap solution, but certainly the fastest way to get your program in hardware without having to learn anything but LabVIEW.
You can use C or C++ to program FPGAs but it requires some very expensive Highlevel Synthesis software. CatapultC is a product from Mentor Graphics which allows you to write your algorithm in untimed C++. It then synthesizes that C++ into RTL VHDL or Verilog. But CatapultC sells for well over $100,000 so it's definitely not for hobbyists. There's another product called ImpulseC which allows you to write C code which then gets synthesized into RTL, but I'm pretty sure that it only handles C not C++. ImpulseC is about $2000.
For hobbyists, you're probably best off sticking with VHDL or Verilog to describe your design and then using the free tools from Xilinx or Altera to synthesize that code and program the FPGA.
There is a big difference between compiling for CPUs and compiling for FPGAs. "Normal" compilers generate binary program code. The special FPGA compilers generate "hardware". There are compilers out there that turn some C-like code into "hardware". But it's not exactly C. It may be a C derivative extented with integer types of arbitrary bit lengths and is probably restricted to iteration and non-recursive function calls.
I am a big fan of C++ but even I see that many parts of it are just not appropriate for FPGAs: virtual functions, RTTI, exceptions. At least that's my impression. I didn't test those C-like FPGA compilers myself but a buddy of mine worked with them and it's supposedly a PITA.
They're probably using C to interface with the FPGA. When working with one in a design class, we used Verilog to program the FPGA and C in the attached Linux board. In that case, they're likely using C as it's easier to bang out a small program in C than in C++.
You're probably talking about SystemC, which is a set of C++ classes and macros used mainly for (transaction-level) modeling, not for synthesis. The high-level model can then be used as a golden reference to verifiy the register transfer level (RTL) description, which is typically coded in VHDL or Verilog.
as some of you I'm a fan of C++. I think it would be great to use SystemC to work with fpga's. So looking for that I found the next page. Maybe it could interest some of you.
http://www.es.ele.tue.nl/~ljozwiak/education/5JJ70p/blocks/4/sc2fpgaflow.html
What you are referring to is "behavioral synthesis", a compilation technique that allows to take sequential code as input (C, SystemC, C++) and generate automatically a FSM+Datapath pair in VHDL or Verilog, that can then be synthesized using regular Xilinx or Altera synthesizers.
To date, there are many "behavioral synthesizers" :
- CatapultC from Mentor Graphics allows you to use a big subset of C and also C++
- Cynthesizer from Forte Design System (systemC based) [edit 2015: now Cadence]
- for FPGA, ImpulseC seems quite mature
- [edit 2015] for Xilinx FPGA : Vivado-HLS
Hope this helps
Two that I can think of off the top of my head: C++ is much more complicated to write compilers (in this case HDL translators) for and has too many features that just would not be useful in such low level programming as fpga programming calls for.
Like others have said most FPGA's are designed using VHDL or Verilog. I have also seen PALASM used several years ago for small designs. The design is a logic description that is converted to settings that configure the FPGA. Verilog is based on c so knowing c will help with learning verilog however FPGAs are by nature parallel so even though the syntax might look similar not much else translates.
They might be talking about a programming language like Handel-C, which is some kind of C dialect, targeted for hardware programming. Handel-C can be directly or indirectly compiled to HDL, which in turn creates an FPGA configuration (i.e., the "program" on an FPGA).
Although VHDL and Verilog are much harder to learn, I suggest you start right away. When you're doing FPGA-related stuff, you're usually interested in efficiency. Handel-C will most likely make less efficient code than the code that you can write by hand (in VHDL or Verilog).
Edit: There's no C++ variant of Handel-C or related compilers I have ever head of.
- You could use a soft processor running on the FPGA and code in C from there (NIOS from Altera, Microblaze from Xilinx etc).
- SOC FPGA using OpenCL to interface with the FPGA from the ARM processor.
You can use C/C++ to program FPGAs. Xilinx has SDSoC, an eclipse based tool to program your FPGAs using C/C++. This basically builds hardware accelerator for part of code flagged to be synthesized. This assumes ARM+FPGA based zynq devices, host code is running on ARM
There is another flow SDAccel for PC based solution. With host code on X86 & accelerator on FPGA connected to your PCIe slot.
FPGA code describes hardware. What that means is you design a digital system and then use code to "describe" the hardware to the compiler. This is mainly done in VHDL or Verilog.
Modern compilers provide inerfaces between software and hardware platforms to let you write C code that can be run on FPGAs. Its not really code that will be uploaded to the FPGA but merely lets the compiler make code for the FPGA based on your C code. For an optimal system, there will need to be a Hardware Engineer who can make changes to the compiler generated code. Here's a nice article on the issue: https://www.eetimes.com/c-language-techniques-for-fpga-acceleration-of-embedded-software/#
There are some programs like Intel Monitor Program which let you run C code on FPGAs but what it does is create a 'Computer' using the Microprocessor already on Chip to let you see how the code works. Its more of a learning tool.
Not sure if this has been said yet (I didn't read all the responses) but it is a possibility that what you are hearing is a running software in a soft core... For instance Altera has Nios II which can run a linux kernel (uCLinux) which will allow some pre-loaded C programs to run on that soft core which in turn communicates with the FPGA. So an FPGA will still be programmed with VHDL/Verilog for the hardware side, then whatever data it holds could be accessible to a small app running on the OS in the soft core. I'm sure C++ would be allowed so long as uCLinux/whatever kernel is running supports the language.
~doddy
You usually get a larger standard library with C++ and with C, and C is closer to the way that the hardware operates, i.e. easier for electrical engineers.
精彩评论