🧭 Mentorship plan
Written from the value chain only: the original document was not available.
This mentorship plan guides a small team through building core components of Tenspiler, an automated system for translating general-purpose code into high-performance tensor operations. Learners will deepen their understanding of compiler design, formal verification, and AI/ML optimization by actively engaging with program synthesis, SMT solvers, and hardware-aware code generation. Each step combines theoretical inquiry with practical implementation to ensure robust skill development.
Pace rule: Each step starts with a question. The learner answers it in their own words, then does the task. A step's typical days are the time given. A learner who has not answered by then is not chased: the mentor moves on to learners who are moving, and the door stays open for when they return.
Who this is for
Final-year computer science or software engineering students with a basic understanding of programming languages, data structures, and algorithms, interested in compilers, AI/ML, and high-performance computing.Starting point
The team must be proficient in Python and C++, understand basic compiler concepts (lexing, parsing), and have familiarity with fundamental linear algebra operations. They should be comfortable with using a Linux environment and command-line tools.Components
- Component name
- Source Code Lifting & Synthesis
- Skill areas
- AI
- Platform engineering
- Why it matters
- This component is the crucial front-end of Tenspiler, responsible for taking the user's general-purpose C/C++ or Python code and accurately translating it into the Tensir intermediate representation. This translation, performed via Syntax-Guided Synthesis, is foundational for all subsequent verification and optimization steps, directly enabling the system's ability to automate code migration and achieve performance gains.
- Ladder
Step Question Where to look Student task Mentor checks Typical days 1 What is an Abstract Syntax Tree (AST) and how is it used in compiler front-ends? Aho, Lam, Sethi, Ullman, 'Compilers: Principles, Techniques, and Tools' (The Dragon Book), Chapter 2 Parse a simple C function, `int add(int a, int b) { return a + b; }`, and generate its AST. Present the AST visually (e.g., using a graph drawing tool or a nested text format). Learner's explanation of AST structure and purpose in their own words. A clear, correctly structured AST representation for the given C function. Pass if structure accurately reflects the C code's syntax. 2 2 How does Syntax-Guided Synthesis (SyGuS) fundamentally differ from traditional parsing and semantic analysis in compilation? Rosette documentation, specifically sections on program synthesis or SyGuS examples. Using a library like Rosette or Z3's SyGuS capabilities, implement a basic synthesis problem to find a function `f(x)` that satisfies `f(1)=2` and `f(2)=4`. The grammar should allow for simple arithmetic operations. Learner's explanation of SyGuS's search-based approach versus traditional compiler analysis. A working Python/Rosette script that correctly synthesizes `f(x) = 2*x` or equivalent. Pass if script runs and synthesizes correctly. 3 3 What is Tensir's role as an Intermediate Representation, and how is its functional grammar defined for synthesis? Tenspiler's internal Tensir grammar specification (assumed document, e.g., in EBNF or similar notation). Define a simplified Tensir grammar subset, using EBNF or a similar context-free grammar notation, capable of representing basic tensor-scalar addition (e.g., `tensir_add_scalar(tensor, scalar)` and tensor-tensor addition (e.g., `tensir_add_tensor(tensor_A, tensor_B)`). Learner's explanation of Tensir as a unified IR for tensor operations. A syntactically correct EBNF snippet that adequately defines the specified Tensir operations. Pass if grammar covers required operations clearly. 3 4 How can loop invariants be formulated and leveraged to synthesize iterative constructs in Tensir? Research papers on loop invariant generation/synthesis for program verification or synthesis, e.g., from PLDI, CAV, or POPL conferences. For the C loop `int sum = 0; for (int i = 0; i < N; ++i) { sum += arr[i]; }`, formulate a suitable loop invariant. Then, describe how this invariant would be incorporated into a SyGuS problem to synthesize the Tensir equivalent of the loop's body and accumulation. Learner's correct formulation of the loop invariant (e.g., `sum == SUM(arr[0...i-1])`). A clear description of the SyGuS problem's components (grammar, constraints, examples) that would leverage this invariant for synthesis. Pass if invariant is correct and its SyGuS integration is logically sound. 4 5 Why is bounded search, commonly used in SyGuS, a significant performance concern for synthesizing complex, real-world programs? Academic papers or reports discussing the scalability limits and complexity of Syntax-Guided Synthesis. Consider a C/C++ function for a 3x3 matrix multiplication. Estimate the growth in search space for synthesizing its Tensir equivalent as the 'bound' (maximum depth of the synthesized program) increases. Explain how this relates to scalability issues in practice. Learner's explanation of how bounded search limits exploration depth and its exponential impact on search space. A reasonable estimation of search space growth for the matrix multiplication example (e.g., relating to grammar size and bound). Pass if explanation is clear and estimation highlights scalability challenge. 3 6 For an industrial-grade Tenspiler, which trade-off would you prioritize between synthesis time and the completeness of the synthesized Tensir program, and why? No specific document; this requires critical thinking based on the previous steps and product goals. Propose a hybrid strategy for Tenspiler's synthesis phase that combines SyGuS with another technique (e.g., pattern matching for known idioms, or AI-guided search). Justify how this strategy balances the need for timely synthesis with ensuring a comprehensive and correct Tensir output. A well-reasoned argument for a chosen trade-off, citing the implications of each. A clearly articulated hybrid strategy with a logical justification for its components and how they address the trade-off. Pass if argument is sound and strategy is plausible. 4 - Common mistakes
- Confusing traditional parsing with the more complex search process of program synthesis.
- Creating overly broad or too restrictive grammars for Tensir, hindering effective synthesis.
- Underestimating the computational cost and time required for SyGuS on even moderately complex programs.
- Failing to adequately consider loop invariants when dealing with iterative constructs.
- Providing superficial answers to 'why' questions without deeper technical justification.
- Component name
- Functional Equivalence Verification
- Skill areas
- AI
- Platform engineering
- Why it matters
- This component is paramount for Tenspiler's core promise: ensuring that the synthesized Tensir program behaves identically to the original source code. Utilizing SMT solvers for formal verification, it guarantees the correctness of the translation, which is critical for trust and reliability in high-performance and safety-critical AI/ML applications.
- Ladder
Step Question Where to look Student task Mentor checks Typical days 1 What is a Satisfiability Modulo Theories (SMT) solver, and what types of logical problems is it designed to solve? CVC5 or Z3 SMT solver documentation (e.g., their introductory guides or tutorials). Write a simple SMT-LIB 2.0 script to determine if there exists an integer `x` such that `(x > 5 AND x < 10 AND (x % 2 == 0 OR x % 3 == 0))`. Run the script using CVC5 or Z3 and report the output. Learner's explanation of SMT solvers and their role in verifying logical formulas over various theories (e.g., integers, arrays). A correctly formatted SMT-LIB 2.0 script. A report showing the SMT solver output (e.g., `sat` with a model for `x`). Pass if script is correct and output is as expected. 2 2 How can functional equivalence between two program expressions be encoded as an SMT problem? A formal methods textbook or online course material explaining Hoare logic or weakest preconditions, focusing on how program states are modeled. Consider two simple Tensir-like expressions: `(expr1 a b) = a + b` and `(expr2 a b) = b + a`. Encode the assertion `(expr1 x y) == (expr2 x y)` for arbitrary integers `x` and `y` into an SMT-LIB 2.0 query. Use CVC5 or Z3 to verify this equivalence. Learner's explanation of encoding program states and function calls into SMT logic. A correct SMT-LIB 2.0 script asserting the equivalence. The solver output should be `unsat` (meaning the negation of the equivalence is unsatisfiable, thus the equivalence holds). Pass if encoding is correct and solver proves equivalence. 3 3 Why are explicit loop invariants crucial for verifying programs containing loops using SMT solvers for unbounded domains? Academic papers or comprehensive tutorials on SMT-based program verification, particularly those discussing loop treatment. Attempt to verify the equivalence of `sum = 0; for i=0 to N: sum = sum + i` and `sum = N * (N + 1) / 2` using an SMT solver without explicitly providing a loop invariant for the first expression, assuming `N` can be any non-negative integer. Explain why this approach fails for arbitrary `N`. Learner's explanation that SMT solvers struggle with universal quantification over unbounded loop iterations without abstraction. A description of how a naive encoding without an invariant will not produce a definitive `unsat` for all `N`. Pass if explanation highlights the need for invariants for unbounded loops. 4 4 What are the primary performance bottlenecks encountered when using SMT solvers for verifying real-world, large-scale program properties? Reports from SMT-COMP (SMT competition) or academic publications discussing SMT solver performance and scalability challenges. Research and summarize the main factors that cause SMT solvers to be slow or time-out on complex problems (e.g., quantifier handling, theory combinations, large clause sets, memory consumption). Give quantitative examples of typical runtime for hard problems, if available. Learner's identification and explanation of key bottlenecks (e.g., complexity of theories, number of variables/assertions, quantifier instantiation). A summary of performance limiting factors, possibly referencing specific SMT-COMP results or academic findings. Pass if bottlenecks are correctly identified and explained. 3 5 In the context of verifying a critical AI/ML kernel in Tenspiler, what trade-off would you choose between the rigor of formal verification and the time it takes to complete the verification, and why? No specific document; this requires critical thinking based on the application domain and engineering realities. Consider a matrix multiplication kernel used in a medical AI diagnosis system. Propose a verification strategy that balances the need for absolute correctness with practical time constraints. Discuss if a full SMT-based proof is always necessary or if other techniques (e.g., bounded model checking for a large bound, statistical checking) could be employed in conjunction. A well-reasoned argument for a chosen trade-off, considering the criticality of the application. A proposed strategy that combines (or prioritizes) different verification techniques, with a clear justification for why each is chosen and where it applies. Pass if argument is sound and strategy is robust. 4 - Common mistakes
- Incorrectly formulating logical assertions in SMT-LIB, leading to wrong results (e.g., `sat` instead of `unsat`).
- Expecting SMT solvers to automatically reason about program loops without explicit invariants or bounded unrolling.
- Underestimating the exponential complexity and memory requirements of SMT solving for complex program paths.
- Failing to understand the 'satisfiability' vs. 'validity' concepts in SMT queries.
- Component name
- Target DSL Code Generation
- Skill areas
- AI
- Platform engineering
- Why it matters
- This component is the final and critical step in Tenspiler's value chain, transforming the verified Tensir IR into executable code for diverse target DSLs and hardware accelerators. Its efficiency and accuracy directly determine the realized performance gains and broad applicability of Tenspiler across various AI/ML ecosystems, delivering on the promise of optimized tensor operations.
- Ladder
Step Question Where to look Student task Mentor checks Typical days 1 What is a Domain-Specific Language (DSL), and how do DSLs like NumPy and PyTorch facilitate tensor operations in AI/ML? Online documentation for NumPy and PyTorch (e.g., their 'getting started' or 'overview' sections). Write a Python script that performs element-wise addition of two 3x3 matrices using NumPy. Then, write another Python script that performs the same operation using PyTorch. Compare the syntax. Learner's explanation of DSLs and their benefits in specific domains. Two correct Python scripts demonstrating matrix addition, one using NumPy and one using PyTorch. Pass if both scripts are correct and syntax comparison is accurate. 2 2 How does pattern-matching facilitate the translation of an Intermediate Representation (IR) like Tensir into target-specific DSL code? Compiler design textbooks (e.g., 'Advanced Compiler Design and Implementation' by Steven Muchnick, chapters on code generation) or documentation for IR-to-code generation frameworks (e.g., LLVM's TableGen concept). For a simplified Tensir expression representing element-wise tensor addition, e.g., `Tensir.Add(tensorA, tensorB)`, propose a pattern-matching rule (using a pseudocode or simple declarative language) to translate this into a PyTorch API call like `torch.add(tensorA, tensorB)`. Describe the 'pattern' and 'action' parts of your rule. Learner's explanation of pattern matching (e.g., matching a subtree/pattern in the IR and replacing it with target code). A clear, well-structured pseudocode or declarative rule defining the Tensir-to-PyTorch translation. Pass if rule is logically sound and correctly translates the operation. 3 3 What specific techniques make code generation 'hardware-aware' to leverage the unique features of specialized AI/ML accelerators (e.g., GPUs, TPUs)? Research papers or articles on high-performance computing, GPU programming, or AI hardware architectures (e.g., 'CUDA C++ Programming Guide', 'Google TPU Architecture' overview). Describe how a common tensor operation like matrix multiplication (GEMM) can be optimized for a GPU. Focus on techniques such as tiling/blocking, shared memory usage, and vectorization, explaining how these directly exploit GPU hardware features. Learner's explanation of hardware-aware techniques (e.g., tiling, vectorization, memory hierarchy exploitation). A detailed description of at least two GPU optimization techniques for GEMM and how they map to hardware. Pass if description is accurate and detailed. 3 4 Why is it challenging to maintain both semantic preservation and performance optimality when generating code from a single IR (Tensir) for highly diverse hardware targets? Compiler optimization textbooks or papers discussing challenges in portable performance, heterogeneous computing, or compiler backends. Consider the Tensir representation of a convolution operation. Explain how generating code for a standard CPU (e.g., using OpenMP) versus a specialized AI accelerator (e.g., using custom intrinsics or a different memory model) might lead to different performance characteristics and potential semantic preservation challenges if the translation rules are not precise enough. Learner's explanation of challenges (e.g., differing instruction sets, memory models, synchronization primitives, data layouts). A concrete example demonstrating how distinct optimization strategies for CPU vs. accelerator could lead to performance disparities and potential semantic pitfalls if not carefully managed. Pass if challenges are clearly articulated with examples. 4 5 What trade-off would you choose between keeping Tensir simple and abstract, versus extending it with hardware-specific details to achieve peak performance on diverse targets, and why? No specific document; this requires critical thinking based on IR design principles and Tenspiler's goals. Propose an architectural approach for Tenspiler's code generation that balances Tensir's desired simplicity as a unified IR with the need for fine-grained hardware control for maximal performance. This could involve, for example, a multi-stage lowering process or an annotation system. A well-reasoned argument for a chosen balance between IR abstraction and hardware specificity. A clear proposal (e.g., a multi-stage lowering, an IR annotation system, or a target-specific optimization pass structure) that justifies how it achieves the desired trade-off. Pass if argument is sound and architectural proposal is logical. 4 - Common mistakes
- Generating generic code that doesn't leverage target-specific optimizations (e.g., vectorization, tiling).
- Not accounting for different memory models or data representations across hardware targets.
- Assuming that a direct translation of IR always yields optimal or even correct code.
- Overlooking the performance implications of specific DSL constructs or library calls.
- Failing to validate the generated code's semantic equivalence and performance against the original or expected behavior.
Mentor guidance
- Encourage learners to use AI tools (e.g., ChatGPT, Bard) to *find* answers to questions, but emphasize the importance of explaining in their own words and critically evaluating the AI's output.
- Ensure that each task builds directly on the answer to the preceding question. If the answer is vague, the task will likely be performed poorly.
- Stress that 'pass marks' are not just about completing the task, but about demonstrating understanding of the underlying principles.
- Remind learners that they are building a *verified* transpiler; correctness and semantic preservation are paramount.
- Do not extend deadlines for steps. The time estimates are generous for learning and doing.
- Emphasize the 'why' behind every technical choice, as Tenspiler is an innovation, not just an implementation.
Assumptions
- The source document for the value chain is not available to the mentor or the learner; all information is derived from the provided JSON.
- The mentor has access to Tenspiler's internal documentation, including the Tensir grammar specification and implementation details for its Rosette and CVC5 integrations.
- Learners have access to necessary development environments (Python, C++ compilers, SMT solvers like CVC5/Z3, and the Rosette framework or similar program synthesis libraries).
Prepared by InnoQuest's AI from the uploaded document. Check every number before relying on it; assumptions are listed above.