MDX Testing

•4 min read

sample blog post to test the mdx compiler and custom components

bold bold text

italic italic text

strikethrough sttext

code inline code

#define UNROLLED_WARP_COPY(UNROLL_FACTOR, LANE_ID, N, DST, SRC, LD_FUNC, ST_FUNC)

blockquote

This is a blockquote

superscript H2O

subscript CO2

kbd Ctrl + C

Math

σ(QK⊤d)V\sigma\left(\frac{QK^{\top}}{\sqrt{d}}\right)V

Table:

Header 1Header 2Header 3
Row 1Cell 1Cell 2
Row 2Cell 3Cell 4

for this text footnote is below

text with another footnote

  1. list item 1
  2. list item 2
  3. list item 3
  • unordered list item 1
  • unordered list item 2
    • nested item 1
    • nested item 2
    1. nested ordered item 1
    2. nested ordered item 2

heading

subheading

Basic Code Block

Simple JavaScript without any special features:

__global__ void fma_kernel(float* result, float a, float b, float c) {
    float r;
    asm("fma.rn.f32 %0, %1, %2, %3;" : "=f"(r) : "f"(a), "f"(b), "f"(c));
    *result = r;
}
 
int main() {
    float *d_result, h_result;
    cudaMalloc(&d_result, sizeof(float));
    fma_kernel<<<1,1>>>(d_result, 2.0f, 3.0f, 4.0f);
    cudaMemcpy(&h_result, d_result, sizeof(float), cudaMemcpyDeviceToHost);
    printf("CUDA FMA Result: %f\n", h_result);
    cudaFree(d_result);
    return 0;
}

Line Numbers Test

Testing if line numbers appear:

#include <cstdio>
 
int main() {
    float a = 2.0f, b = 3.0f, c = 4.0f, result;
    asm volatile (
        "vfmadd213ss %[c], %[b], %[a]\n\t" // result = (a * b) + c
        : [a] "+x" (a)
        : [b] "x" (b), [c] "x" (c)
    );
    result = a;
    printf("x86 FMA Result: %f\n", result);
    return 0;
}

Line Numbers Starting at Custom Number

Should start at line 50:

__device__ __forceinline__ void st_na_relaxed(const int *ptr, int val) {
    asm volatile("st.relaxed.gpu.global.L1::no_allocate.b32 [%0], %1;" : : "l"(ptr), "r"(val));
}

Highlighting lines 2 and 4-6:

#define UNROLLED_WARP_COPY(UNROLL_FACTOR, LANE_ID, N, DST, SRC, LD_FUNC, ST_FUNC) \
{ \
    constexpr int kLoopStride = 32 * (UNROLL_FACTOR); \
    typename std::remove_reference<decltype(LD_FUNC((SRC) + 0))>::type unrolled_values[(UNROLL_FACTOR)]; \
    auto __src = (SRC); \
    auto __dst = (DST); \  // [!code highlight]
    for (int __i = (LANE_ID); __i < ((N) / kLoopStride) * kLoopStride; __i += kLoopStride) { \
        _Pragma("unroll") \
        for (int __j = 0; __j < (UNROLL_FACTOR); ++__j) \
            unrolled_values[__j] = LD_FUNC(__src + __i + __j * 32); \
        _Pragma("unroll") \
        for (int __j = 0; __j < (UNROLL_FACTOR); ++__j) \
            ST_FUNC(__dst + __i + __j * 32, unrolled_values[__j]); \
    } \
}

Different colored groups:

__device__  __forceinline__ float ld_volatile_global(const float *ptr) {
    float ret;
    asm volatile("ld.volatile.global.f32 %0, [%1];" : "=f"(ret) : "l"(ptr));
    return ret;
}
 
__device__  __forceinline__ int64_t ld_volatile_global(const int64_t *ptr) {
    int64_t ret;
    asm volatile("ld.volatile.global.s64 %0, [%1];" : "=l"(ret) : "l"(ptr));
    return ret;
}
 
__device__  __forceinline__ int64_t ld_volatile_global(const uint64_t *ptr) {
    int64_t ret;
    asm volatile("ld.volatile.global.u64 %0, [%1];" : "=l"(ret) : "l"(ptr));
    return ret;
}

Word/Character Highlighting

Highlighting specific words:

import time
import torch
import triton
import triton.language as tl
 
@triton.jit
def constant_add_kernel(
    x_ptr,
    constant,
    y_ptr,
    N0: tl.constexpr,
    BLOCK_SIZE: tl.constexpr
):
 
    pid = tl.program_id(0)
    offsets = pid * BLOCK_SIZE + tl.arange(0, BLOCK_SIZE)
    mask = offsets < N0
 
    x = tl.load(x_ptr + offsets, mask=mask)
    y = x + constant
    tl.store(y_ptr + offsets, y, mask=mask)

Different colored character groups:

const [data, setData] = useState(null);
const [loading, setLoading] = useState(true);
 
setData(newData);
setLoading(false);

title caption

utils/helpers.js
export function debounce(func, delay) {
  let timeoutId;
  return function (...args) {
    clearTimeout(timeoutId);
    timeoutId = setTimeout(() => func.apply(this, args), delay);
  };
}
SELECT
    u.name,
    COUNT(p.id) as post_count
FROM users u
LEFT JOIN posts p ON u.id = p.user_id
GROUP BY u.id, u.name
ORDER BY post_count DESC
LIMIT 10;
Query to get top users by post count

Diff Highlighting

Testing diff syntax:

const added = true; // [!code ++]
const removed = true; // [!code --]
const blank = true;

Inline Code Test

Here's some inline code: const name = "John" with syntax highlighting.

Testing token mapping: getUserById and className.

Footnotes

    Footnotes
  1. Github, "Basic Writing and Formatting Syntax" Github, 2024. [Accessed: 19-Sep-2024].
  2. This is a second footnote.