Guides using RAPTOR (LLVM-based tool) to profile and alter floating-point precision in C, C++, and Fortran scientific code. Covers compiler shims, manual flags, LTO, and the precision truncation API.
Ships in RAPTOR. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
None: SKILL.md is the whole skill.
RAPTOR (from RIKEN-RCCS) is an LLVM-based tool that transparently replaces high-precision floating-point operations with lower-precision alternatives in C, C++, and Fortran code. It enables scientists to profile numerical requirements and identify precision-sensitive code regions without manual refactoring.
Repository: https://github.com/RIKEN-RCCS/RAPTOR
RAPTOR provides drop-in compiler wrappers that automatically inject the required flags:
| Wrapper | Replaces |
|---|---|
raptor-clang | clang |
raptor-clang++ | clang++ |
raptor-flang | flang |
Simply replace your compiler invocation, e.g.:
raptor-clang++ -O2 -o myapp myapp.cpp
Compilation (requires at least -O1):
clang++ -O2 -fpass-plugin=$RAPTOR_INSTALL_DIR/lib/LLVMRaptor-$LLVM_VER.so -c myapp.cpp
Linking:
clang++ -o myapp myapp.o -lRaptor-RT-$LLVM_VER -lmpfr -lstdc++
Verbose remarks (see what RAPTOR transforms):
clang++ -O2 -Rpass=raptor -fpass-plugin=... -c myapp.cpp
For deeper cross-module analysis, enable LTO:
Compilation:
clang++ -O2 -flto=full -fpass-plugin=$RAPTOR_INSTALL_DIR/lib/LLVMRaptor-$LLVM_VER.so -c myapp.cpp
Linking (via clang/flang):
clang++ -fuse-ld=lld -Wl,--load-pass-plugin=$RAPTOR_INSTALL_DIR/lib/LLDRaptor-$LLVM_VER.so -o myapp myapp.o -lRaptor-RT-$LLVM_VER -lmpfr -lstdc++
Linking (via lld directly):
ld.lld --load-pass-plugin=$RAPTOR_INSTALL_DIR/lib/LLDRaptor-$LLVM_VER.so ...
RAPTOR provides an API to explicitly request precision truncation on specific functions.
Declare the truncation helper:
template <typename fty>
fty *__raptor_truncate_op_func(fty *, int from_type, int to_type, int to_exponent, int to_mantissa);
template <typename fty>
fty *__raptor_truncate_op_func(fty *, int from_type, int to_type, int to_width);
Parameters:
fty * — pointer to the function to truncatefrom_type — source precision in bits (e.g., 32, 64)to_type — target type: 1 = MPFR (custom precision), 0 = IEEE builtinto_exponent — exponent bits (MPFR mode)to_mantissa — mantissa bits (MPFR mode)to_width — target IEEE width in bits (IEEE mode)Example — truncate to custom MPFR precision (5-bit exponent, 8-bit mantissa):
auto f = __raptor_truncate_op_func(
foo, // function pointer
32, // from: 32-bit float
1, // to: MPFR custom
5, // exponent bits
8); // mantissa bits
f(a, b);
Example — truncate from 64-bit to 32-bit IEEE:
auto f = __raptor_truncate_op_func(foo, 64, 0, 32);
f(a, b);
interface
function f__raptor_truncate_op_func(tfunc, from_ieee, to_type, &
to_exponent, to_significand) result(fty) bind(c)
use iso_c_binding
implicit none
integer(c_int), intent(in), value :: from_ieee, to_type, &
to_exponent, to_significand
type(c_funptr), intent(in), value :: tfunc
type(c_funptr) :: fty
end function f__raptor_truncate_op_func
end interface
Example:
cfty = c_funloc(simple_sum)
cfty = f__raptor_truncate_op_func(cfty, 64, 1, 10, 4)
call c_f_procpointer(cfty, ffty)
c = ffty(a, b)
See test/Integration/Truncate/Fortran/simple.f90 in the repo for a complete working example.
All arguments to __raptor_truncate_op_func must be integer literals, not variables. RAPTOR resolves them at compile time via the LLVM pass. Passing a runtime variable causes a compiler crash:
Assertion `isa<To>(Val) && "cast<Ty>() argument of incompatible type!"' failed.
Running pass "RaptorNewPM" on module ...
To sweep multiple precisions, use a macro to stamp out separate calls per constant:
#define RUN_TRUNC(MBITS) do { \
auto fn = __raptor_truncate_op_func(my_func, 64, 1, 11, MBITS); \
/* ... use fn ... */ \
} while(0)
RUN_TRUNC(8);
RUN_TRUNC(16);
RUN_TRUNC(23);
RUN_TRUNC(52);
#undef RUN_TRUNC
The RAPTOR runtime is typically installed as a static archive (libRaptor-RT-<VER>.a), not a .so. The -lRaptor-RT-<VER> flag may not resolve. Link explicitly by path instead:
# Instead of: -lRaptor-RT-$(LLVM_VER)
RLIBS = -L$(RAPTOR_INSTALL_DIR)/lib $(RAPTOR_INSTALL_DIR)/lib/libRaptor-RT-$(LLVM_VER).a -lmpfr -lstdc++
The __raptor_truncate_op_func symbol is only available when linking against the RAPTOR runtime. A plain build (without RAPTOR flags) will fail to link. Use a preprocessor guard so the same source file compiles both ways:
#ifdef USE_RAPTOR
template <typename fty>
fty *__raptor_truncate_op_func(fty *, int from_type, int to_type, int to_exponent, int to_mantissa);
template <typename fty>
fty *__raptor_truncate_op_func(fty *, int from_type, int to_type, int to_width);
#endif
// ...
#ifdef USE_RAPTOR
auto f = __raptor_truncate_op_func(my_func, 64, 0, 32);
// reduced precision experiment ...
#endif
In the Makefile, pass -DUSE_RAPTOR only for the instrumented target:
solver: solver.cpp
$(CXX) $(CXXFLAGS) -o $@ $<
solver_raptor: solver.cpp
$(CXX) $(CXXFLAGS) $(RFLAGS) -DUSE_RAPTOR -o $@ $< $(RLIBS)
The truncation API wraps a specific function. To use it, your calling code must accept a function pointer rather than calling the target directly:
// Refactor callers to accept a function pointer
double rk4_step(double t, double y, double h,
double (*deriv_fn)(double, double)) { ... }
// Then swap in the truncated version
auto deriv_f32 = __raptor_truncate_op_func(deriv, 64, 0, 32);
rk4_step(t, y, h, deriv_f32);
IEEE and MPFR-equivalent mantissa bit counts for common formats (exponent bits in parentheses):
| Format | Exponent bits | Mantissa bits |
|---|---|---|
| double | 11 | 52 |
| float | 8 | 23 |
| half | 5 | 10 |
| bfloat16 | 8 | 7 |
When using MPFR mode to emulate a target format, match the exponent to the format above and vary the mantissa to find the minimum sufficient precision for your application.
What SKILL.md sets; muted values are Claude Code's defaults
Three short reads, in order
Other plugins' skills for the same job
/RAPTOR:raptorfrom RAPTOR
npx claudepluginhub riken-rccs/hpc-agentic-sdk --plugin RAPTOR