Explain C++ and GPU Tradeoffs
Company: Qualcomm
Role: Software Engineer
Category: Software Engineering Fundamentals
Difficulty: medium
Interview Round: Technical Screen
The interview included several short-answer questions, all discussed in C++:
1. Explain how to reason about the output of a C++ program that uses both `enum` and `struct`. Your explanation should cover default enum values, scoped versus unscoped enums, aggregate initialization, omitted initializers, implicit conversions during printing, and the difference between member values and memory layout or padding.
2. Compare a preprocessor macro with a C++ function or `inline` function. Discuss preprocessing versus compilation, type safety, side effects, argument evaluation, debuggability, and performance.
3. For GPU-based matrix addition, compare two kernel implementations and explain their trade-offs. For example, compare a simple kernel where each thread reads two elements from global memory and writes one output element, versus a more optimized variant that uses better memory access patterns such as coalesced or vectorized loads, or shared-memory staging. Which version is usually better, and why?
4. Suppose every thread in a GPU kernel performs the same uniform operation or repeatedly reads the same read-only value. How would you improve performance and power efficiency?
Quick Answer: This question evaluates understanding of C++ language semantics (enum varieties, default values, aggregate initialization, implicit conversions, struct memory layout and padding), differences between preprocessing and compiled functions (macros versus inline/type-safe functions), and GPU performance trade-offs such as memory access patterns, coalescing, vectorized loads, and shared-memory staging. It is commonly asked to probe low-level reasoning about compilation versus preprocessing, type- and runtime-level trade-offs, and performance and power-efficiency in parallel kernels; it falls under Software Engineering Fundamentals and tests both conceptual understanding and practical application.