[Paper Review] Design and Implementation of ShenWei Universal C/C++
ShenWei Universal C/C++ (SWUC) is a language extension for C/C++ that unifies programming across Management Processing Elements (MPEs) and Compute Processing Elements (CPEs) in ShenWei many-core processors. By introducing new attributes like host, slave, infer, and kernel, along with compiler directives, SWUC enables single-file, portable code that simplifies heterogeneous programming and accelerates migration of existing C++ applications.
The ShenWei many-core series processors powering multiple cutting-edge supercomputers are equipped with their unique on-chip heterogeneous architecture. They have long required programmers to write separate codes for the control part on Management Processing Element (MPE) and accelerated part on Compute Processing Element (CPE), which is similar to open standards like OpenCL. Such a programming model results in shattered code and bad maintainability, and also make it hard to migrate existing projects targeting commodity processors. Borrowing the experience from CUDA and DPC++ and leveraging the unique unified main memory on ShenWei many-core architecture, we propose ShenWei Universal C/C++ (SWUC), a language extension to C/C++ that enables fluent programming acrossing the boundary of MPE and CPE. Through the use of several new attributes and compiler directives, users are able to write codes running on MPE and CPE in a single file. In case of C++, SWUC further support lambda expressions on CPEs, making it possible to have the code flow better matching the logical design. SWUC also manages to make the Athread library interfaces available, easing the learning curve for original ShenWei users. These powerful features together ensures SWUC to simplify the programming on ShenWei many-core processors and migration of existing C/C++ applications.
Motivation & Objective
- Address the fragmented development model in ShenWei many-core systems, where MPE and CPE code must be written and maintained in separate files.
- Reduce the complexity of migrating existing C/C++ applications—especially those with templates and member functions—onto ShenWei processors.
- Improve programmer productivity by enabling a single-source programming model that supports both host and device execution in one file.
- Simplify template usage across MPE and CPE boundaries through intelligent inference and attribute-based code filtering.
- Provide a drop-in replacement for standard C++ compilers with minimal engineering overhead, leveraging existing compiler infrastructure.
Proposed method
- Introduce four new language attributes: host (executes on MPE), slave (executes on CPE), infer (automatically determines target based on called functions), and kernel (marks entry points for CPE kernel launches).
- Use compiler directives #pragma swuc push and #pragma swuc pop to set default target architecture for code blocks, enabling selective application of attributes.
- Implement SWUC as a plugin to the Sunway C/C++ compiler, operating at the middle-end to analyze and filter code based on target architecture before code generation.
- Perform two-pass compilation: one for MPE (generating control code and kernel launch wrappers) and one for CPE (generating kernel launchers and device code), then link the outputs.
- Enable C++ lambda expressions with the slave attribute to allow device-side execution and improve code modularity and logical flow.
- Support template instantiation across MPE and CPE by using the infer attribute to propagate target architecture through call graphs, avoiding manual template specialization.
Experimental results
Research questions
- RQ1How can a unified C++ programming model be designed to simplify heterogeneous programming on ShenWei many-core processors without altering the underlying hardware abstraction?
- RQ2What mechanisms can enable seamless template and function pointer usage across MPE and CPE while preserving type safety and performance?
- RQ3Can a compiler plugin approach effectively unify MPE and CPE code generation with minimal modification to existing toolchains?
- RQ4How can the use of lambda expressions and function templates be supported across the MPE-CPE boundary in a way that reduces code duplication and improves maintainability?
- RQ5To what extent can the SWUC model reduce the effort required to port existing C++ applications to ShenWei architectures?
Key findings
- SWUC enables writing MPE and CPE code in a single source file using attributes like host, slave, and kernel, significantly reducing code fragmentation.
- The infer attribute allows automatic determination of function availability across MPE and CPE by analyzing call graphs, reducing manual annotation and duplication.
- C++ lambda expressions with the slave attribute are natively supported, enabling cleaner, more modular code that matches logical program structure.
- Template functions can be automatically instantiated for both MPE and CPE targets via the infer attribute, eliminating the need for manual template specialization across devices.
- The two-pass compilation model with middle-end interception ensures correct filtering of code not intended for the current target, preserving correctness and performance.
- SWUC is implemented as a plugin to the existing Sunway compiler, enabling drop-in replacement with minimal integration effort and full backward compatibility with standard C++.
Better researchstarts right now
From reading papers to final review, dramatically reduce your research time.
No credit card · Free plan available
This review was created by AI and reviewed by human editors.