From 513008ed10a6df45864f663de577559fcf357f42 Mon Sep 17 00:00:00 2001 From: Paul-Edouard Sarlin Date: Fri, 2 Oct 2026 18:02:52 +0000 Subject: [PATCH] [Caspar] Scope subexpression elimination in Dabseg and CPSE to output parameter groups In Caspar kernels, factors write to multiple distinct output parameter groups (e.g., residual 'res', camera pose, camera calibration, and 3D point). Between these parameter groups, the kernel emits barrier synchronizations and shared memory reduction flushes (FlushSumShared). Previously, Common Subexpression Elimination (CSE) in make_dabseg and do_cpse operated globally across the entire factor DAG. When a subexpression (such as -(1 + k*r^2)) computed during the camera pose Jacobian was reused hundreds of lines later in the calibration Jacobian across 12 FlushSumShared barriers, the variable remained live throughout all intermediate reductions. Under __launch_bounds__(1024, 1) (which limits threads to 64 registers), this extreme register pressure caused registers to be spilled to local memory and corrupted in kernels with high occupancy. This change scopes subexpression elimination per output parameter group: 1. Accessor accepts an optional group: str | None parameter, and Factor.make_kernels explicitly tags output accessors with their parameter group ('res' or parameter name). 2. CallData includes group in its hash and equality, preventing Dabseg.data_to_id from deduplicating identical subexpressions across group boundaries. 3. make_dabseg resets its expression-to-value map across output group transitions. 4. do_cpse partitions calls by call.group so partial associative/commutative reductions do not cross group boundaries. 5. Function fixers preserve call.group across DAG transformations. This eliminates cross-barrier live ranges between parameter groups, preventing stack spilling and register corruption across reduction flushes. --- symforce/caspar/code_formulation/cpse.py | 30 ++- symforce/caspar/code_formulation/dabseg.py | 17 +- .../code_formulation/dabseg_from_accessors.py | 8 + .../code_formulation/function_fixers.py | 2 + symforce/caspar/code_generation/factor.py | 55 +++-- symforce/caspar/memory/accessors.py | 4 +- .../kernel_rosenbrock_res_jac.cu | 41 ++-- .../kernel_rosenbrock_res_jac_first.cu | 40 ++-- .../kernel_chain_a_link_res_jac.cu | 73 +++--- .../kernel_chain_a_link_res_jac_first.cu | 77 ++++--- .../kernel_chain_a_prior_res_jac.cu | 11 +- .../kernel_chain_a_prior_res_jac_first.cu | 17 +- .../kernel_chain_b_link_res_jac.cu | 205 +++++++++-------- .../kernel_chain_b_link_res_jac_first.cu | 211 ++++++++++-------- .../kernel_chain_b_prior_res_jac.cu | 32 +-- .../kernel_chain_b_prior_res_jac_first.cu | 42 ++-- .../kernel_chain_coupling_res_jac.cu | 108 +++++---- .../kernel_chain_coupling_res_jac_first.cu | 112 ++++++---- 18 files changed, 627 insertions(+), 458 deletions(-) diff --git a/symforce/caspar/code_formulation/cpse.py b/symforce/caspar/code_formulation/cpse.py index 5b5d85d7..de9d30a6 100644 --- a/symforce/caspar/code_formulation/cpse.py +++ b/symforce/caspar/code_formulation/cpse.py @@ -106,7 +106,7 @@ def _cpse_impl( def do_cpse(dabseg: Dabseg, ftype: T.Type[Func]) -> None: """ Perform Partial Common Subexpression Elimination on a Dabseg for a given - commutative and associative function type. + commutative and associative function type, scoped within each call group. Example: 1) r0=a+b+c, r1=a+c+d+e, r2=a+c+e (original sums) @@ -114,8 +114,20 @@ def do_cpse(dabseg: Dabseg, ftype: T.Type[Func]) -> None: 3) r0=r3+b, r1=r2+d, r2=r3+e, r3=a+c (eliminate r3+e) (done) """ - calls = [call for call in dabseg.call_iter() if call.is_a(ftype)] + calls_by_group: dict[str | None, list[Call]] = {} + for call in dabseg.call_iter(): + if call.is_a(ftype): + calls_by_group.setdefault(call.group, []).append(call) + for group, calls in calls_by_group.items(): + if len(calls) < 2: + continue + _do_cpse_group(dabseg, ftype, calls, group) + + +def _do_cpse_group( + dabseg: Dabseg, ftype: T.Type[Func], calls: list[Call], group: str | None +) -> None: def get_args(call: Call) -> T.Iterator[ValId]: for arg in call.args: if arg.call.is_a(ftype): @@ -131,17 +143,23 @@ def get_args(call: Call) -> T.Iterator[ValId]: def map_var(v: ValId) -> Val: return dabseg.val(tmp_map.get(v, v)) - unique = {argset[0]: func for argset, func in zip(argsets, calls) if len(argset) == 1} + unique = { + argset[0]: func for argset, func in zip(argsets, calls, strict=True) if len(argset) == 1 + } for i, tmp_varset in enumerate(tmp_varsets): tmp_id = ValId(i + OFFSET) if tmp_id in unique: func = unique[tmp_id] else: - func = dabseg.add_call(ftype(), tuple(map(map_var, tmp_varset)), fix_accumulator=False) + func = dabseg.add_call( + ftype(), tuple(map(map_var, tmp_varset)), fix_accumulator=False, group=group + ) tmp_map[tmp_id] = func[0].id - for func, argset in zip(calls, argsets): + for func, argset in zip(calls, argsets, strict=True): if len(argset) == 1: continue - func_new = dabseg.add_call(ftype(), tuple(map(map_var, argset)), fix_accumulator=False) + func_new = dabseg.add_call( + ftype(), tuple(map(map_var, argset)), fix_accumulator=False, group=group + ) dabseg.rebind(func_new, func) diff --git a/symforce/caspar/code_formulation/dabseg.py b/symforce/caspar/code_formulation/dabseg.py index 12c8909f..ca07d887 100644 --- a/symforce/caspar/code_formulation/dabseg.py +++ b/symforce/caspar/code_formulation/dabseg.py @@ -28,6 +28,7 @@ def __init__(self) -> None: self.call_rebinds: dict[CallId, CallId] = {} self.unique_used: set[ValId] = set() self.final_call_ids: SortedSet[CallId] = SortedSet() + self.current_group: str | None = None def call_data(self, call_id: CallId) -> CallData: return self._call_data[call_id] @@ -56,13 +57,17 @@ def add_call( *, depends: tuple[Call, ...] = (), fix_accumulator: bool = True, + group: str | None = None, ) -> Call: + if group is None: + group = self.current_group return self.add_call_data( CallData( func=func, arg_ids=tuple(a.id for a in args), depends=tuple(call.id for call in depends), relations={}, + group=group, ), fix_accumulator=fix_accumulator, ) @@ -189,6 +194,7 @@ def clean(self) -> Dabseg: arg_ids=tuple((vmap[v.id] for v in call.args)), depends=tuple(cmap[dep.id] for dep in call.depends), relations=self.call_data(call.id).relations, + group=call.group, ) ) vmap.update({v_old.id: v_new.id for v_old, v_new in zip(call.outs, new_func.outs)}) @@ -247,6 +253,7 @@ class CallData: relations: dict[str, CallId] out_ids: tuple[ValId, ...] id: CallId + group: str | None = None def __init__( self, @@ -254,12 +261,14 @@ def __init__( arg_ids: tuple[ValId, ...], depends: tuple[CallId, ...], relations: dict[str, CallId], + group: str | None = None, ) -> None: assert isinstance(func, Func) self.func = func self.arg_ids = arg_ids self.depends = depends self.relations = relations + self.group = group def finalize(self, outs: tuple[ValId, ...], fid: CallId) -> None: self.out_ids = outs @@ -275,18 +284,20 @@ def copy(self) -> CallData: arg_ids=self.arg_ids, depends=self.depends, relations=self.relations, + group=self.group, ) def __hash__(self) -> int: if self.is_unique: return hash((self.func, self.arg_ids, self.id)) - return hash((self.func, self.arg_ids)) + return hash((self.func, self.arg_ids, self.group)) def __eq__(self, value: object, /) -> bool: return ( isinstance(value, CallData) and self.func == value.func and self.arg_ids == value.arg_ids + and self.group == value.group ) @@ -418,6 +429,10 @@ def relations(self) -> dict[str, Call]: def func(self) -> Func: return self._fdata.func + @property + def group(self) -> str | None: + return self._fdata.group + def parents( self, include_depends: bool = True, diff --git a/symforce/caspar/code_formulation/dabseg_from_accessors.py b/symforce/caspar/code_formulation/dabseg_from_accessors.py index 221ca16d..b65322b1 100644 --- a/symforce/caspar/code_formulation/dabseg_from_accessors.py +++ b/symforce/caspar/code_formulation/dabseg_from_accessors.py @@ -91,7 +91,13 @@ def make_dabseg( var._str = storage[el].name # noqa: SLF001 leaves = [] + base_expr_map = dict(expr_map) + current_group: str | None = None for out in outputs: + if out.group != current_group: + expr_map = dict(base_expr_map) + current_group = out.group + dabseg.current_group = current_group if is_pair(out.storage): expr_lists = [Ops.to_storage(out.storage[0]), Ops.to_storage(out.storage[1])] for i, indices in enumerate(out.chunk_indices): @@ -122,8 +128,10 @@ def make_dabseg( leaves.append(call) dabseg.set_finalize(leaves) for call in dabseg.call_iter(): + dabseg.current_group = call.group call = function_fixers.fix_pow(dabseg, call) call = function_fixers.unpack_square(dabseg, call) + dabseg.current_group = None set_debug_graph(dabseg) do_cpse(dabseg, ftypes.Prod) do_cpse(dabseg, ftypes.Sum) diff --git a/symforce/caspar/code_formulation/function_fixers.py b/symforce/caspar/code_formulation/function_fixers.py index eee12445..29880264 100644 --- a/symforce/caspar/code_formulation/function_fixers.py +++ b/symforce/caspar/code_formulation/function_fixers.py @@ -136,6 +136,7 @@ def is_fma_prod(call: Call) -> bool: for call_id, relations in relations_map.items(): call = dabseg.call(call_id) + dabseg.current_group = call.group if (is_fma_prod(call) and call.n_args == 2) or not relations: continue @@ -199,3 +200,4 @@ def is_fma_prod(call: Call) -> bool: init.add_relation(finish, "finish") dabseg.rebind(finish, call) + dabseg.current_group = None diff --git a/symforce/caspar/code_generation/factor.py b/symforce/caspar/code_generation/factor.py index d24b120f..85482c38 100644 --- a/symforce/caspar/code_generation/factor.py +++ b/symforce/caspar/code_generation/factor.py @@ -207,47 +207,70 @@ def make_kernels(self) -> list[Kernel]: # noqa: PLR0915 diag1, tril1 = get_diagonal_and_lower_triangle(jac1.T * jac1) if not self.solved_by_preconditioner: jac_outs += ( - WriteSequential(f"out_{k}_jac_first", dyn_part(jac0), **accessor_kwargs), - WriteSequential(f"out_{k}_jac_second", dyn_part(jac1), **accessor_kwargs), + WriteSequential( + f"out_{k}_jac_first", dyn_part(jac0), group=k, **accessor_kwargs + ), + WriteSequential( + f"out_{k}_jac_second", dyn_part(jac1), group=k, **accessor_kwargs + ), ) jac_outs += ( - WriteSequential(f"out_{k}_tridig_U", dyn_part(tridig), **accessor_kwargs), + WriteSequential( + f"out_{k}_tridig_U", dyn_part(tridig), group=k, **accessor_kwargs + ), AddPair( f"out_{k}_njtr", Pair(-jac0.T * self.res, -jac1.T * self.res), + group=k, **accessor_kwargs, ), - AddPair(f"out_{k}_precond_diag", Pair(diag0, diag1), **accessor_kwargs), - AddPair(f"out_{k}_precond_tril", Pair(tril0, tril1), **accessor_kwargs), + AddPair( + f"out_{k}_precond_diag", Pair(diag0, diag1), group=k, **accessor_kwargs + ), + AddPair( + f"out_{k}_precond_tril", Pair(tril0, tril1), group=k, **accessor_kwargs + ), ) elif self.isnodeuniq[k]: jac = self.jacs[k] diag, tril = get_diagonal_and_lower_triangle(jac.T * jac) if not self.solved_by_preconditioner: jac_outs.append( - WriteSequential(f"out_{k}_jac", dyn_part(jac), **accessor_kwargs) + WriteSequential(f"out_{k}_jac", dyn_part(jac), group=k, **accessor_kwargs) ) jac_outs += ( - AddSum(f"out_{k}_njtr", -jac.T * self.res, **accessor_kwargs), - AddSum(f"out_{k}_precond_diag", diag, **accessor_kwargs), - AddSum(f"out_{k}_precond_tril", tril, **accessor_kwargs), + AddSum(f"out_{k}_njtr", -jac.T * self.res, group=k, **accessor_kwargs), + AddSum(f"out_{k}_precond_diag", diag, group=k, **accessor_kwargs), + AddSum(f"out_{k}_precond_tril", tril, group=k, **accessor_kwargs), ) else: jac = self.jacs[k] diag, tril = get_diagonal_and_lower_triangle(jac.T * jac) if not self.solved_by_preconditioner: jac_outs.append( - WriteSequential(f"out_{k}_jac", dyn_part(jac), **accessor_kwargs) + WriteSequential(f"out_{k}_jac", dyn_part(jac), group=k, **accessor_kwargs) ) jac_outs += ( AddSharedSum( - f"out_{k}_njtr", -jac.T * self.res, reuse_indices_from=k, **accessor_kwargs + f"out_{k}_njtr", + -jac.T * self.res, + reuse_indices_from=k, + group=k, + **accessor_kwargs, ), AddSharedSum( - f"out_{k}_precond_diag", diag, reuse_indices_from=k, **accessor_kwargs + f"out_{k}_precond_diag", + diag, + reuse_indices_from=k, + group=k, + **accessor_kwargs, ), AddSharedSum( - f"out_{k}_precond_tril", tril, reuse_indices_from=k, **accessor_kwargs + f"out_{k}_precond_tril", + tril, + reuse_indices_from=k, + group=k, + **accessor_kwargs, ), ) @@ -255,8 +278,8 @@ def make_kernels(self) -> list[Kernel]: # noqa: PLR0915 (self.name, "res_jac_first"), inputs, [ - WriteSequential("out_res", self.res, **accessor_kwargs), - AddSum("out_rTr", self.res.T * self.res, **accessor_kwargs), + WriteSequential("out_res", self.res, group="res", **accessor_kwargs), + AddSum("out_rTr", self.res.T * self.res, group="res", **accessor_kwargs), *jac_outs, ], ) @@ -264,7 +287,7 @@ def make_kernels(self) -> list[Kernel]: # noqa: PLR0915 (self.name, "res_jac"), inputs, [ - WriteSequential("out_res", self.res, **accessor_kwargs), + WriteSequential("out_res", self.res, group="res", **accessor_kwargs), *jac_outs, ], ) diff --git a/symforce/caspar/memory/accessors.py b/symforce/caspar/memory/accessors.py index 3c42e199..bd6dcbab 100644 --- a/symforce/caspar/memory/accessors.py +++ b/symforce/caspar/memory/accessors.py @@ -91,7 +91,7 @@ class Accessor: SKIP_IF_ALL_ZERO: T.ClassVar[bool] = False - def __init__( + def __init__( # noqa: PLR0913 self, name: str, storage: T.StorableOrType, @@ -104,6 +104,7 @@ def __init__( default: T.Any | None = None, after: str | None = None, block_size: int = 1024, + group: str | None = None, ): assert isinstance(self, _Pairwise) == is_pair(storage) assert isinstance(kernel_dtype, DType) @@ -114,6 +115,7 @@ def __init__( self.stride = stride self.default = default self.after = after + self.group = group self.idx_name = name if reuse_indices_from is None else reuse_indices_from self.kernel_t = kernel_dtype self.storage_t = dtype diff --git a/test/symforce_function_codegen_test_data/symengine/symforce_caspar_solver_test/kernel_rosenbrock_res_jac.cu b/test/symforce_function_codegen_test_data/symengine/symforce_caspar_solver_test/kernel_rosenbrock_res_jac.cu index 8c17c53f..4e202ccf 100644 --- a/test/symforce_function_codegen_test_data/symengine/symforce_caspar_solver_test/kernel_rosenbrock_res_jac.cu +++ b/test/symforce_function_codegen_test_data/symengine/symforce_caspar_solver_test/kernel_rosenbrock_res_jac.cu @@ -48,33 +48,38 @@ __global__ void __launch_bounds__(1024, 1) if (global_thread_idx < problem_size) { r3 = -1.00000000000000000e+00; r4 = r1 * r1; - r2 = fma(r3, r4, r2); - r0 = r0 * r2; - r5 = 1.00000000000000000e+00; - r3 = fma(r1, r3, r5); - WriteIdx2<1024, double, double, double2>(out_res, 0 * out_res_num_alloc, global_thread_idx, r0, + r4 = fma(r3, r4, r2); + r4 = r0 * r4; + r0 = 1.00000000000000000e+00; + r3 = fma(r1, r3, r0); + WriteIdx2<1024, double, double, double2>(out_res, 0 * out_res_num_alloc, global_thread_idx, r4, r3); - r0 = -1.00000000000000000e+02; - r0 = r2 * r0; - r6 = r1 * r2; - r7 = 2.00000000000000000e+02; - r6 = fma(r7, r6, r3); - WriteSum2((double*)inout_shared, r6, r0); + r3 = 1.00000000000000000e+00; + r4 = -1.00000000000000000e+00; + r0 = fma(r1, r4, r3); + r5 = 2.00000000000000000e+02; + r6 = r1 * r5; + r7 = r1 * r1; + r4 = fma(r4, r7, r2); + r0 = fma(r4, r6, r0); + r6 = -1.00000000000000000e+02; + r6 = r4 * r6; + WriteSum2((double*)inout_shared, r0, r6); }; FlushSumShared<2, double>(out_x_njtr, 0 * out_x_njtr_num_alloc, x_indices_loc, (double*)inout_shared); if (global_thread_idx < problem_size) { - r0 = 1.00000000000000000e+02; - r6 = 4.00000000000000000e+02; - r4 = fma(r6, r4, r5); - WriteSum2((double*)inout_shared, r4, r0); + r6 = 1.00000000000000000e+02; + r0 = 4.00000000000000000e+02; + r7 = fma(r0, r7, r3); + WriteSum2((double*)inout_shared, r7, r6); }; FlushSumShared<2, double>(out_x_precond_diag, 0 * out_x_precond_diag_num_alloc, x_indices_loc, (double*)inout_shared); if (global_thread_idx < problem_size) { - r0 = -2.00000000000000000e+02; - r0 = r1 * r0; - WriteSum1((double*)inout_shared, r0); + r6 = -2.00000000000000000e+02; + r6 = r1 * r6; + WriteSum1((double*)inout_shared, r6); }; FlushSumShared<1, double>(out_x_precond_tril, 0 * out_x_precond_tril_num_alloc, x_indices_loc, (double*)inout_shared); diff --git a/test/symforce_function_codegen_test_data/symengine/symforce_caspar_solver_test/kernel_rosenbrock_res_jac_first.cu b/test/symforce_function_codegen_test_data/symengine/symforce_caspar_solver_test/kernel_rosenbrock_res_jac_first.cu index 94cdbac1..94e5fca0 100644 --- a/test/symforce_function_codegen_test_data/symengine/symforce_caspar_solver_test/kernel_rosenbrock_res_jac_first.cu +++ b/test/symforce_function_codegen_test_data/symengine/symforce_caspar_solver_test/kernel_rosenbrock_res_jac_first.cu @@ -37,7 +37,7 @@ __global__ void __launch_bounds__(1024, 1) __shared__ double out_rTr_local[1]; - double r0 = 0, r1 = 0, r2 = 0, r3 = 0, r4 = 0, r5 = 0, r6 = 0, r7 = 0, r8 = 0; + double r0 = 0, r1 = 0, r2 = 0, r3 = 0, r4 = 0, r5 = 0, r6 = 0, r7 = 0; if (global_thread_idx < problem_size) { r0 = 1.00000000000000000e+01; @@ -50,38 +50,44 @@ __global__ void __launch_bounds__(1024, 1) if (global_thread_idx < problem_size) { r3 = -1.00000000000000000e+00; r4 = r1 * r1; - r2 = fma(r3, r4, r2); - r0 = r0 * r2; + r4 = fma(r3, r4, r2); + r0 = r0 * r4; r5 = 1.00000000000000000e+00; r3 = fma(r1, r3, r5); WriteIdx2<1024, double, double, double2>(out_res, 0 * out_res_num_alloc, global_thread_idx, r0, r3); r0 = 1.00000000000000000e+02; - r6 = r2 * r2; - r6 = fma(r0, r6, r3 * r3); + r4 = r4 * r4; + r4 = fma(r0, r4, r3 * r3); }; - SumStore(out_rTr_local, (double*)inout_shared, 0, global_thread_idx < problem_size, r6); + SumStore(out_rTr_local, (double*)inout_shared, 0, global_thread_idx < problem_size, r4); if (global_thread_idx < problem_size) { + r4 = 1.00000000000000000e+00; + r0 = -1.00000000000000000e+00; + r3 = fma(r1, r0, r4); + r5 = 2.00000000000000000e+02; + r6 = r1 * r5; + r7 = r1 * r1; + r0 = fma(r0, r7, r2); + r3 = fma(r0, r6, r3); r6 = -1.00000000000000000e+02; - r6 = r2 * r6; - r7 = r1 * r2; - r8 = 2.00000000000000000e+02; - r7 = fma(r8, r7, r3); - WriteSum2((double*)inout_shared, r7, r6); + r6 = r0 * r6; + WriteSum2((double*)inout_shared, r3, r6); }; FlushSumShared<2, double>(out_x_njtr, 0 * out_x_njtr_num_alloc, x_indices_loc, (double*)inout_shared); if (global_thread_idx < problem_size) { - r6 = 4.00000000000000000e+02; - r4 = fma(r6, r4, r5); - WriteSum2((double*)inout_shared, r4, r0); + r6 = 1.00000000000000000e+02; + r3 = 4.00000000000000000e+02; + r7 = fma(r3, r7, r4); + WriteSum2((double*)inout_shared, r7, r6); }; FlushSumShared<2, double>(out_x_precond_diag, 0 * out_x_precond_diag_num_alloc, x_indices_loc, (double*)inout_shared); if (global_thread_idx < problem_size) { - r0 = -2.00000000000000000e+02; - r0 = r1 * r0; - WriteSum1((double*)inout_shared, r0); + r6 = -2.00000000000000000e+02; + r6 = r1 * r6; + WriteSum1((double*)inout_shared, r6); }; FlushSumShared<1, double>(out_x_precond_tril, 0 * out_x_precond_tril_num_alloc, x_indices_loc, (double*)inout_shared); diff --git a/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_a_link_res_jac.cu b/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_a_link_res_jac.cu index 7495787b..016bf234 100644 --- a/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_a_link_res_jac.cu +++ b/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_a_link_res_jac.cu @@ -28,7 +28,7 @@ __global__ void __launch_bounds__(1024, 1) ChainALinkResJacKernel( extern __shared__ __align__(16) uint8_t inout_shared[]; double r0 = 0, r1 = 0, r2 = 0, r3 = 0, r4 = 0, r5 = 0, r6 = 0, r7 = 0, r8 = 0, r9 = 0, r10 = 0, - r11 = 0, r12 = 0, r13 = 0, r14 = 0; + r11 = 0, r12 = 0, r13 = 0, r14 = 0, r15 = 0, r16 = 0; if (global_thread_idx < problem_size) { ReadIdx2<1024, double, double, double2>(offset, 0 * offset_num_alloc, global_thread_idx, r0, @@ -41,48 +41,55 @@ __global__ void __launch_bounds__(1024, 1) ChainALinkResJacKernel( global_thread_idx, threadIdx.x == 1023, global_thread_idx <= problem_size, r5, r6, r7, r8); if (global_thread_idx < problem_size) { - r5 = fma(r5, r2, r7); - r0 = fma(r3, r5, r0 * r2); - ReadIdx2<1024, double, double, double2>(weight, 2 * weight_num_alloc, global_thread_idx, r7, - r9); - r6 = fma(r6, r2, r8); - r0 = fma(r7, r6, r0); - r5 = fma(r4, r5, r1 * r2); - r5 = fma(r9, r6, r5); - WriteIdx2<1024, double, double, double2>(out_res, 0 * out_res_num_alloc, global_thread_idx, r0, - r5); - r6 = r4 * r2; - r1 = r3 * r3; - r8 = fma(r2, r1, r4 * r6); - r10 = r3 * r7; - r10 = fma(r9, r6, r2 * r10); + r9 = fma(r5, r2, r7); + r10 = fma(r3, r9, r0 * r2); + ReadIdx2<1024, double, double, double2>(weight, 2 * weight_num_alloc, global_thread_idx, r11, + r12); + r13 = fma(r6, r2, r8); + r10 = fma(r11, r13, r10); + r9 = fma(r4, r9, r1 * r2); + r9 = fma(r12, r13, r9); + WriteIdx2<1024, double, double, double2>(out_res, 0 * out_res_num_alloc, global_thread_idx, r10, + r9); + r9 = -1.00000000000000000e+00; + r10 = r4 * r9; + r13 = r3 * r3; + r2 = fma(r9, r13, r4 * r10); + r14 = r3 * r11; + r14 = fma(r12, r10, r9 * r14); WriteIdx2<1024, double, double, double2>(out_a_tridig_U, 0 * out_a_tridig_U_num_alloc, - global_thread_idx, r8, r10); - r8 = r9 * r9; - r11 = r7 * r7; - r12 = fma(r2, r11, r2 * r8); + global_thread_idx, r2, r14); + r2 = r12 * r12; + r15 = r11 * r11; + r16 = fma(r9, r15, r9 * r2); WriteIdx2<1024, double, double, double2>(out_a_tridig_U, 2 * out_a_tridig_U_num_alloc, - global_thread_idx, r10, r12); - r12 = fma(r3, r0, r4 * r5); - r10 = fma(r7, r0, r9 * r5); - r13 = r9 * r2; - r14 = r7 * r2; - r14 = fma(r0, r14, r5 * r13); - r13 = r3 * r2; - r6 = fma(r5, r6, r0 * r13); + global_thread_idx, r14, r16); + r5 = fma(r5, r9, r7); + r1 = fma(r4, r5, r1 * r9); + r6 = fma(r6, r9, r8); + r1 = fma(r12, r6, r1); + r5 = fma(r3, r5, r0 * r9); + r5 = fma(r11, r6, r5); + r6 = fma(r3, r5, r4 * r1); + r0 = fma(r11, r5, r12 * r1); + r8 = r12 * r9; + r7 = r11 * r9; + r7 = fma(r5, r7, r1 * r8); + r8 = r3 * r9; + r10 = fma(r1, r10, r5 * r8); }; ShuffleAndWrite2((double*)inout_shared, out_a_njtr, 0 * out_a_njtr_num_alloc, global_thread_idx, - problem_size, r12, r10, r6, r14); + problem_size, r6, r0, r10, r7); if (global_thread_idx < problem_size) { - r1 = fma(r4, r4, r1); - r11 = r8 + r11; + r13 = fma(r4, r4, r13); + r15 = r2 + r15; }; ShuffleAndWrite2( (double*)inout_shared, out_a_precond_diag, 0 * out_a_precond_diag_num_alloc, - global_thread_idx, problem_size, r1, r11, r1, r11); + global_thread_idx, problem_size, r13, r15, r13, r15); if (global_thread_idx < problem_size) { - r4 = fma(r4, r9, r3 * r7); + r4 = fma(r4, r12, r3 * r11); }; ShuffleAndWrite1((double*)inout_shared, out_a_precond_tril, 0 * out_a_precond_tril_num_alloc, diff --git a/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_a_link_res_jac_first.cu b/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_a_link_res_jac_first.cu index df421ac3..3f229cf2 100644 --- a/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_a_link_res_jac_first.cu +++ b/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_a_link_res_jac_first.cu @@ -30,7 +30,7 @@ __global__ void __launch_bounds__(1024, 1) ChainALinkResJacFirstKernel( __shared__ double out_rTr_local[1]; double r0 = 0, r1 = 0, r2 = 0, r3 = 0, r4 = 0, r5 = 0, r6 = 0, r7 = 0, r8 = 0, r9 = 0, r10 = 0, - r11 = 0, r12 = 0, r13 = 0, r14 = 0; + r11 = 0, r12 = 0, r13 = 0, r14 = 0, r15 = 0, r16 = 0; if (global_thread_idx < problem_size) { ReadIdx2<1024, double, double, double2>(offset, 0 * offset_num_alloc, global_thread_idx, r0, @@ -43,52 +43,59 @@ __global__ void __launch_bounds__(1024, 1) ChainALinkResJacFirstKernel( global_thread_idx, threadIdx.x == 1023, global_thread_idx <= problem_size, r5, r6, r7, r8); if (global_thread_idx < problem_size) { - r5 = fma(r5, r2, r7); - r0 = fma(r3, r5, r0 * r2); - ReadIdx2<1024, double, double, double2>(weight, 2 * weight_num_alloc, global_thread_idx, r7, - r9); - r6 = fma(r6, r2, r8); - r0 = fma(r7, r6, r0); - r5 = fma(r4, r5, r1 * r2); - r5 = fma(r9, r6, r5); - WriteIdx2<1024, double, double, double2>(out_res, 0 * out_res_num_alloc, global_thread_idx, r0, - r5); - r6 = fma(r0, r0, r5 * r5); + r9 = fma(r5, r2, r7); + r10 = fma(r3, r9, r0 * r2); + ReadIdx2<1024, double, double, double2>(weight, 2 * weight_num_alloc, global_thread_idx, r11, + r12); + r13 = fma(r6, r2, r8); + r10 = fma(r11, r13, r10); + r9 = fma(r4, r9, r1 * r2); + r9 = fma(r12, r13, r9); + WriteIdx2<1024, double, double, double2>(out_res, 0 * out_res_num_alloc, global_thread_idx, r10, + r9); + r10 = fma(r10, r10, r9 * r9); }; - SumStore(out_rTr_local, (double*)inout_shared, 0, global_thread_idx < problem_size, r6); + SumStore(out_rTr_local, (double*)inout_shared, 0, global_thread_idx < problem_size, r10); if (global_thread_idx < problem_size) { - r6 = r4 * r2; - r1 = r3 * r3; - r8 = fma(r2, r1, r4 * r6); - r10 = r3 * r7; - r10 = fma(r9, r6, r2 * r10); + r10 = -1.00000000000000000e+00; + r9 = r4 * r10; + r13 = r3 * r3; + r2 = fma(r10, r13, r4 * r9); + r14 = r3 * r11; + r14 = fma(r12, r9, r10 * r14); WriteIdx2<1024, double, double, double2>(out_a_tridig_U, 0 * out_a_tridig_U_num_alloc, - global_thread_idx, r8, r10); - r8 = r9 * r9; - r11 = r7 * r7; - r12 = fma(r2, r11, r2 * r8); + global_thread_idx, r2, r14); + r2 = r12 * r12; + r15 = r11 * r11; + r16 = fma(r10, r15, r10 * r2); WriteIdx2<1024, double, double, double2>(out_a_tridig_U, 2 * out_a_tridig_U_num_alloc, - global_thread_idx, r10, r12); - r12 = fma(r3, r0, r4 * r5); - r10 = fma(r7, r0, r9 * r5); - r13 = r9 * r2; - r14 = r7 * r2; - r14 = fma(r0, r14, r5 * r13); - r13 = r3 * r2; - r6 = fma(r5, r6, r0 * r13); + global_thread_idx, r14, r16); + r5 = fma(r5, r10, r7); + r1 = fma(r4, r5, r1 * r10); + r6 = fma(r6, r10, r8); + r1 = fma(r12, r6, r1); + r5 = fma(r3, r5, r0 * r10); + r5 = fma(r11, r6, r5); + r6 = fma(r3, r5, r4 * r1); + r0 = fma(r11, r5, r12 * r1); + r8 = r12 * r10; + r7 = r11 * r10; + r7 = fma(r5, r7, r1 * r8); + r8 = r3 * r10; + r9 = fma(r1, r9, r5 * r8); }; ShuffleAndWrite2((double*)inout_shared, out_a_njtr, 0 * out_a_njtr_num_alloc, global_thread_idx, - problem_size, r12, r10, r6, r14); + problem_size, r6, r0, r9, r7); if (global_thread_idx < problem_size) { - r1 = fma(r4, r4, r1); - r11 = r8 + r11; + r13 = fma(r4, r4, r13); + r15 = r2 + r15; }; ShuffleAndWrite2( (double*)inout_shared, out_a_precond_diag, 0 * out_a_precond_diag_num_alloc, - global_thread_idx, problem_size, r1, r11, r1, r11); + global_thread_idx, problem_size, r13, r15, r13, r15); if (global_thread_idx < problem_size) { - r4 = fma(r4, r9, r3 * r7); + r4 = fma(r4, r12, r3 * r11); }; ShuffleAndWrite1((double*)inout_shared, out_a_precond_tril, 0 * out_a_precond_tril_num_alloc, diff --git a/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_a_prior_res_jac.cu b/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_a_prior_res_jac.cu index 7da8cd8d..b8982946 100644 --- a/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_a_prior_res_jac.cu +++ b/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_a_prior_res_jac.cu @@ -35,7 +35,7 @@ __global__ void __launch_bounds__(1024, 1) (global_thread_idx < problem_size ? a_indices[global_thread_idx] : SharedIndex{0xffffffff, 0xffff, 0xffff}); - double r0 = 0, r1 = 0, r2 = 0, r3 = 0, r4 = 0; + double r0 = 0, r1 = 0, r2 = 0, r3 = 0, r4 = 0, r5 = 0; LoadShared<2, double, double>(a, 0 * a_num_alloc, a_indices_loc, (double*)inout_shared); if (global_thread_idx < problem_size) { ReadShared2((double*)inout_shared, a_indices_loc[threadIdx.x].target, r0, r1); @@ -45,11 +45,14 @@ __global__ void __launch_bounds__(1024, 1) ReadIdx2<1024, double, double, double2>(target, 0 * target_num_alloc, global_thread_idx, r2, r3); r4 = -1.00000000000000000e+00; + r5 = fma(r2, r4, r0); + r4 = fma(r3, r4, r1); + WriteIdx2<1024, double, double, double2>(out_res, 0 * out_res_num_alloc, global_thread_idx, r5, + r4); + r4 = -1.00000000000000000e+00; r2 = fma(r2, r4, r0); - r3 = fma(r3, r4, r1); - WriteIdx2<1024, double, double, double2>(out_res, 0 * out_res_num_alloc, global_thread_idx, r2, - r3); r2 = r4 * r2; + r3 = fma(r3, r4, r1); r3 = r4 * r3; WriteSum2((double*)inout_shared, r2, r3); }; diff --git a/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_a_prior_res_jac_first.cu b/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_a_prior_res_jac_first.cu index ddbab613..0a8ccf89 100644 --- a/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_a_prior_res_jac_first.cu +++ b/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_a_prior_res_jac_first.cu @@ -38,7 +38,7 @@ __global__ void __launch_bounds__(1024, 1) __shared__ double out_rTr_local[1]; - double r0 = 0, r1 = 0, r2 = 0, r3 = 0, r4 = 0; + double r0 = 0, r1 = 0, r2 = 0, r3 = 0, r4 = 0, r5 = 0; LoadShared<2, double, double>(a, 0 * a_num_alloc, a_indices_loc, (double*)inout_shared); if (global_thread_idx < problem_size) { ReadShared2((double*)inout_shared, a_indices_loc[threadIdx.x].target, r0, r1); @@ -48,15 +48,18 @@ __global__ void __launch_bounds__(1024, 1) ReadIdx2<1024, double, double, double2>(target, 0 * target_num_alloc, global_thread_idx, r2, r3); r4 = -1.00000000000000000e+00; - r2 = fma(r2, r4, r0); - r3 = fma(r3, r4, r1); - WriteIdx2<1024, double, double, double2>(out_res, 0 * out_res_num_alloc, global_thread_idx, r2, - r3); - r1 = fma(r3, r3, r2 * r2); + r5 = fma(r2, r4, r0); + r4 = fma(r3, r4, r1); + WriteIdx2<1024, double, double, double2>(out_res, 0 * out_res_num_alloc, global_thread_idx, r5, + r4); + r4 = fma(r4, r4, r5 * r5); }; - SumStore(out_rTr_local, (double*)inout_shared, 0, global_thread_idx < problem_size, r1); + SumStore(out_rTr_local, (double*)inout_shared, 0, global_thread_idx < problem_size, r4); if (global_thread_idx < problem_size) { + r4 = -1.00000000000000000e+00; + r2 = fma(r2, r4, r0); r2 = r4 * r2; + r3 = fma(r3, r4, r1); r3 = r4 * r3; WriteSum2((double*)inout_shared, r2, r3); }; diff --git a/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_b_link_res_jac.cu b/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_b_link_res_jac.cu index 4642b781..f4c69fcd 100644 --- a/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_b_link_res_jac.cu +++ b/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_b_link_res_jac.cu @@ -29,7 +29,7 @@ __global__ void __launch_bounds__(1024, 1) ChainBLinkResJacKernel( double r0 = 0, r1 = 0, r2 = 0, r3 = 0, r4 = 0, r5 = 0, r6 = 0, r7 = 0, r8 = 0, r9 = 0, r10 = 0, r11 = 0, r12 = 0, r13 = 0, r14 = 0, r15 = 0, r16 = 0, r17 = 0, r18 = 0, r19 = 0, r20 = 0, - r21 = 0, r22 = 0, r23 = 0, r24 = 0, r25 = 0, r26 = 0; + r21 = 0, r22 = 0, r23 = 0, r24 = 0, r25 = 0, r26 = 0, r27 = 0, r28 = 0; if (global_thread_idx < problem_size) { ReadIdx2<1024, double, double, double2>(offset, 0 * offset_num_alloc, global_thread_idx, r0, @@ -42,133 +42,146 @@ __global__ void __launch_bounds__(1024, 1) ChainBLinkResJacKernel( global_thread_idx, threadIdx.x == 1023, global_thread_idx <= problem_size, r5, r6); if (global_thread_idx < problem_size) { - r5 = fma(r5, r2, r6); - r0 = fma(r3, r5, r0 * r2); - ReadIdx2<1024, double, double, double2>(weight, 0 * weight_num_alloc, global_thread_idx, r6, - r7); + r7 = fma(r5, r2, r6); + r8 = fma(r3, r7, r0 * r2); + ReadIdx2<1024, double, double, double2>(weight, 0 * weight_num_alloc, global_thread_idx, r9, + r10); }; ReadAndShuffle2<1024, double, double, double2>( (double*)inout_shared, b, 0 * b_num_alloc, global_thread_idx, threadIdx.x == 1023, - global_thread_idx <= problem_size, r8, r9, r10, r11); + global_thread_idx <= problem_size, r11, r12, r13, r14); if (global_thread_idx < problem_size) { - r8 = fma(r8, r2, r10); - ReadIdx2<1024, double, double, double2>(weight, 2 * weight_num_alloc, global_thread_idx, r10, - r12); - r9 = fma(r9, r2, r11); - r0 = fma(r6, r8, r0); - r0 = fma(r12, r9, r0); - r1 = fma(r4, r5, r1 * r2); - ReadIdx2<1024, double, double, double2>(weight, 4 * weight_num_alloc, global_thread_idx, r11, - r13); - r1 = fma(r7, r8, r1); - r1 = fma(r11, r9, r1); - WriteIdx2<1024, double, double, double2>(out_res, 0 * out_res_num_alloc, global_thread_idx, r0, - r1); - ReadIdx1<1024, double, double, double>(offset, 2 * offset_num_alloc, global_thread_idx, r14); - ReadIdx1<1024, double, double, double>(weight, 8 * weight_num_alloc, global_thread_idx, r15); - r5 = fma(r15, r5, r14 * r2); - r5 = fma(r10, r8, r5); - r5 = fma(r13, r9, r5); - WriteIdx1<1024, double, double, double>(out_res, 2 * out_res_num_alloc, global_thread_idx, r5); - r9 = r7 * r2; - r8 = r10 * r10; - r14 = fma(r2, r8, r7 * r9); - r16 = r6 * r6; - r14 = fma(r2, r16, r14); - r17 = r6 * r12; - r18 = r10 * r13; - r18 = fma(r2, r18, r2 * r17); - r18 = fma(r11, r9, r18); + r15 = fma(r11, r2, r13); + ReadIdx2<1024, double, double, double2>(weight, 2 * weight_num_alloc, global_thread_idx, r16, + r17); + r18 = fma(r12, r2, r14); + r8 = fma(r9, r15, r8); + r8 = fma(r17, r18, r8); + r19 = fma(r4, r7, r1 * r2); + ReadIdx2<1024, double, double, double2>(weight, 4 * weight_num_alloc, global_thread_idx, r20, + r21); + r19 = fma(r10, r15, r19); + r19 = fma(r20, r18, r19); + WriteIdx2<1024, double, double, double2>(out_res, 0 * out_res_num_alloc, global_thread_idx, r8, + r19); + ReadIdx1<1024, double, double, double>(offset, 2 * offset_num_alloc, global_thread_idx, r19); + ReadIdx1<1024, double, double, double>(weight, 8 * weight_num_alloc, global_thread_idx, r8); + r7 = fma(r8, r7, r19 * r2); + r7 = fma(r16, r15, r7); + r7 = fma(r21, r18, r7); + WriteIdx1<1024, double, double, double>(out_res, 2 * out_res_num_alloc, global_thread_idx, r7); + r7 = -1.00000000000000000e+00; + r18 = r10 * r7; + r15 = r16 * r16; + r2 = fma(r7, r15, r10 * r18); + r22 = r9 * r9; + r2 = fma(r7, r22, r2); + r23 = r9 * r17; + r24 = r16 * r21; + r24 = fma(r7, r24, r7 * r23); + r24 = fma(r20, r18, r24); WriteIdx2<1024, double, double, double2>(out_b_tridig_U, 0 * out_b_tridig_U_num_alloc, - global_thread_idx, r14, r18); - r14 = r6 * r3; - r17 = r10 * r15; - r17 = fma(r2, r17, r2 * r14); - r17 = fma(r4, r9, r17); + global_thread_idx, r2, r24); + r2 = r9 * r3; + r23 = r16 * r8; + r23 = fma(r7, r23, r7 * r2); + r23 = fma(r4, r18, r23); WriteIdx2<1024, double, double, double2>(out_b_tridig_U, 2 * out_b_tridig_U_num_alloc, - global_thread_idx, r17, r18); - r18 = r12 * r3; - r14 = r13 * r15; - r14 = fma(r2, r14, r2 * r18); - r18 = r11 * r4; - r14 = fma(r2, r18, r14); - r18 = r11 * r11; - r19 = r13 * r13; - r20 = fma(r2, r19, r2 * r18); - r21 = r12 * r12; - r20 = fma(r2, r21, r20); + global_thread_idx, r23, r24); + r24 = r17 * r3; + r2 = r21 * r8; + r2 = fma(r7, r2, r7 * r24); + r24 = r20 * r4; + r2 = fma(r7, r24, r2); + r24 = r20 * r20; + r25 = r21 * r21; + r26 = fma(r7, r25, r7 * r24); + r27 = r17 * r17; + r26 = fma(r7, r27, r26); WriteIdx2<1024, double, double, double2>(out_b_tridig_U, 4 * out_b_tridig_U_num_alloc, - global_thread_idx, r20, r14); + global_thread_idx, r26, r2); WriteIdx2<1024, double, double, double2>(out_b_tridig_U, 6 * out_b_tridig_U_num_alloc, - global_thread_idx, r17, r14); - r14 = r4 * r4; - r17 = r15 * r15; - r20 = fma(r2, r17, r2 * r14); - r22 = r3 * r3; - r20 = fma(r2, r22, r20); + global_thread_idx, r23, r2); + r2 = r4 * r4; + r23 = r8 * r8; + r26 = fma(r7, r23, r7 * r2); + r28 = r3 * r3; + r26 = fma(r7, r28, r26); WriteIdx1<1024, double, double, double>(out_b_tridig_U, 8 * out_b_tridig_U_num_alloc, - global_thread_idx, r20); - r20 = fma(r6, r0, r10 * r5); - r20 = fma(r7, r1, r20); - r23 = fma(r12, r0, r13 * r5); - r23 = fma(r11, r1, r23); - r24 = r13 * r2; - r25 = r12 * r2; - r25 = fma(r0, r25, r5 * r24); - r24 = r11 * r2; - r25 = fma(r1, r24, r25); - r24 = r10 * r2; - r26 = r6 * r2; - r26 = fma(r0, r26, r5 * r24); - r26 = fma(r1, r9, r26); + global_thread_idx, r26); + r5 = fma(r5, r7, r6); + r19 = fma(r8, r5, r19 * r7); + r11 = fma(r11, r7, r13); + r12 = fma(r12, r7, r14); + r19 = fma(r16, r11, r19); + r19 = fma(r21, r12, r19); + r0 = fma(r3, r5, r0 * r7); + r0 = fma(r9, r11, r0); + r0 = fma(r17, r12, r0); + r14 = fma(r9, r0, r16 * r19); + r5 = fma(r4, r5, r1 * r7); + r5 = fma(r10, r11, r5); + r5 = fma(r20, r12, r5); + r14 = fma(r10, r5, r14); + r12 = fma(r17, r0, r21 * r19); + r12 = fma(r20, r5, r12); + r11 = r21 * r7; + r1 = r17 * r7; + r1 = fma(r0, r1, r19 * r11); + r11 = r20 * r7; + r1 = fma(r5, r11, r1); + r11 = r16 * r7; + r13 = r9 * r7; + r13 = fma(r0, r13, r19 * r11); + r13 = fma(r5, r18, r13); }; ShuffleAndWrite2((double*)inout_shared, out_b_njtr, 0 * out_b_njtr_num_alloc, global_thread_idx, - problem_size, r20, r23, r26, r25); + problem_size, r14, r12, r13, r1); if (global_thread_idx < problem_size) { - r25 = fma(r3, r0, r15 * r5); - r25 = fma(r4, r1, r25); - r26 = r15 * r2; - r23 = r3 * r2; - r23 = fma(r0, r23, r5 * r26); - r26 = r4 * r2; - r23 = fma(r1, r26, r23); + r1 = fma(r3, r0, r8 * r19); + r1 = fma(r4, r5, r1); + r13 = r8 * r7; + r12 = r3 * r7; + r12 = fma(r0, r12, r19 * r13); + r13 = r4 * r7; + r12 = fma(r5, r13, r12); }; ShuffleAndWrite1((double*)inout_shared, out_b_njtr, 2 * out_b_njtr_num_alloc, global_thread_idx, - problem_size, r25, r23); + problem_size, r1, r12); if (global_thread_idx < problem_size) { - r8 = fma(r7, r7, r8); - r8 = r8 + r16; - r19 = r18 + r19; - r19 = r19 + r21; + r15 = fma(r10, r10, r15); + r15 = r15 + r22; + r25 = r24 + r25; + r25 = r25 + r27; }; ShuffleAndWrite2( (double*)inout_shared, out_b_precond_diag, 0 * out_b_precond_diag_num_alloc, - global_thread_idx, problem_size, r8, r19, r8, r19); + global_thread_idx, problem_size, r15, r25, r15, r25); if (global_thread_idx < problem_size) { - r17 = r14 + r17; - r17 = r17 + r22; + r23 = r2 + r23; + r23 = r23 + r28; }; ShuffleAndWrite1((double*)inout_shared, out_b_precond_diag, 2 * out_b_precond_diag_num_alloc, - global_thread_idx, problem_size, r17, r17); + global_thread_idx, problem_size, r23, r23); if (global_thread_idx < problem_size) { - r17 = fma(r10, r13, r6 * r12); - r17 = fma(r7, r11, r17); - r22 = fma(r10, r15, r6 * r3); - r22 = fma(r7, r4, r22); + r23 = fma(r16, r21, r9 * r17); + r23 = fma(r10, r20, r23); + r28 = fma(r16, r8, r9 * r3); + r28 = fma(r10, r4, r28); }; ShuffleAndWrite2( (double*)inout_shared, out_b_precond_tril, 0 * out_b_precond_tril_num_alloc, - global_thread_idx, problem_size, r17, r22, r17, r22); + global_thread_idx, problem_size, r23, r28, r23, r28); if (global_thread_idx < problem_size) { - r22 = fma(r13, r15, r12 * r3); - r22 = fma(r11, r4, r22); + r28 = fma(r21, r8, r17 * r3); + r28 = fma(r20, r4, r28); }; ShuffleAndWrite1((double*)inout_shared, out_b_precond_tril, 2 * out_b_precond_tril_num_alloc, - global_thread_idx, problem_size, r22, r22); + global_thread_idx, problem_size, r28, r28); } void ChainBLinkResJac(double* const b, unsigned int b_num_alloc, double* weight, diff --git a/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_b_link_res_jac_first.cu b/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_b_link_res_jac_first.cu index 22ff48f3..9db42278 100644 --- a/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_b_link_res_jac_first.cu +++ b/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_b_link_res_jac_first.cu @@ -31,7 +31,7 @@ __global__ void __launch_bounds__(1024, 1) ChainBLinkResJacFirstKernel( double r0 = 0, r1 = 0, r2 = 0, r3 = 0, r4 = 0, r5 = 0, r6 = 0, r7 = 0, r8 = 0, r9 = 0, r10 = 0, r11 = 0, r12 = 0, r13 = 0, r14 = 0, r15 = 0, r16 = 0, r17 = 0, r18 = 0, r19 = 0, r20 = 0, - r21 = 0, r22 = 0, r23 = 0, r24 = 0, r25 = 0, r26 = 0; + r21 = 0, r22 = 0, r23 = 0, r24 = 0, r25 = 0, r26 = 0, r27 = 0, r28 = 0; if (global_thread_idx < problem_size) { ReadIdx2<1024, double, double, double2>(offset, 0 * offset_num_alloc, global_thread_idx, r0, @@ -44,138 +44,151 @@ __global__ void __launch_bounds__(1024, 1) ChainBLinkResJacFirstKernel( global_thread_idx, threadIdx.x == 1023, global_thread_idx <= problem_size, r5, r6); if (global_thread_idx < problem_size) { - r5 = fma(r5, r2, r6); - r0 = fma(r3, r5, r0 * r2); - ReadIdx2<1024, double, double, double2>(weight, 0 * weight_num_alloc, global_thread_idx, r6, - r7); + r7 = fma(r5, r2, r6); + r8 = fma(r3, r7, r0 * r2); + ReadIdx2<1024, double, double, double2>(weight, 0 * weight_num_alloc, global_thread_idx, r9, + r10); }; ReadAndShuffle2<1024, double, double, double2>( (double*)inout_shared, b, 0 * b_num_alloc, global_thread_idx, threadIdx.x == 1023, - global_thread_idx <= problem_size, r8, r9, r10, r11); + global_thread_idx <= problem_size, r11, r12, r13, r14); if (global_thread_idx < problem_size) { - r8 = fma(r8, r2, r10); - ReadIdx2<1024, double, double, double2>(weight, 2 * weight_num_alloc, global_thread_idx, r10, - r12); - r9 = fma(r9, r2, r11); - r0 = fma(r6, r8, r0); - r0 = fma(r12, r9, r0); - r1 = fma(r4, r5, r1 * r2); - ReadIdx2<1024, double, double, double2>(weight, 4 * weight_num_alloc, global_thread_idx, r11, - r13); - r1 = fma(r7, r8, r1); - r1 = fma(r11, r9, r1); - WriteIdx2<1024, double, double, double2>(out_res, 0 * out_res_num_alloc, global_thread_idx, r0, - r1); - ReadIdx1<1024, double, double, double>(offset, 2 * offset_num_alloc, global_thread_idx, r14); - ReadIdx1<1024, double, double, double>(weight, 8 * weight_num_alloc, global_thread_idx, r15); - r5 = fma(r15, r5, r14 * r2); - r5 = fma(r10, r8, r5); - r5 = fma(r13, r9, r5); - WriteIdx1<1024, double, double, double>(out_res, 2 * out_res_num_alloc, global_thread_idx, r5); - r9 = fma(r0, r0, r5 * r5); - r9 = fma(r1, r1, r9); + r15 = fma(r11, r2, r13); + ReadIdx2<1024, double, double, double2>(weight, 2 * weight_num_alloc, global_thread_idx, r16, + r17); + r18 = fma(r12, r2, r14); + r8 = fma(r9, r15, r8); + r8 = fma(r17, r18, r8); + r19 = fma(r4, r7, r1 * r2); + ReadIdx2<1024, double, double, double2>(weight, 4 * weight_num_alloc, global_thread_idx, r20, + r21); + r19 = fma(r10, r15, r19); + r19 = fma(r20, r18, r19); + WriteIdx2<1024, double, double, double2>(out_res, 0 * out_res_num_alloc, global_thread_idx, r8, + r19); + ReadIdx1<1024, double, double, double>(offset, 2 * offset_num_alloc, global_thread_idx, r22); + ReadIdx1<1024, double, double, double>(weight, 8 * weight_num_alloc, global_thread_idx, r23); + r7 = fma(r23, r7, r22 * r2); + r7 = fma(r16, r15, r7); + r7 = fma(r21, r18, r7); + WriteIdx1<1024, double, double, double>(out_res, 2 * out_res_num_alloc, global_thread_idx, r7); + r8 = fma(r8, r8, r7 * r7); + r8 = fma(r19, r19, r8); }; - SumStore(out_rTr_local, (double*)inout_shared, 0, global_thread_idx < problem_size, r9); + SumStore(out_rTr_local, (double*)inout_shared, 0, global_thread_idx < problem_size, r8); if (global_thread_idx < problem_size) { - r9 = r7 * r2; - r8 = r10 * r10; - r14 = fma(r2, r8, r7 * r9); - r16 = r6 * r6; - r14 = fma(r2, r16, r14); - r17 = r6 * r12; - r18 = r10 * r13; - r18 = fma(r2, r18, r2 * r17); - r18 = fma(r11, r9, r18); + r8 = -1.00000000000000000e+00; + r19 = r10 * r8; + r7 = r16 * r16; + r18 = fma(r8, r7, r10 * r19); + r15 = r9 * r9; + r18 = fma(r8, r15, r18); + r2 = r9 * r17; + r24 = r16 * r21; + r24 = fma(r8, r24, r8 * r2); + r24 = fma(r20, r19, r24); WriteIdx2<1024, double, double, double2>(out_b_tridig_U, 0 * out_b_tridig_U_num_alloc, - global_thread_idx, r14, r18); - r14 = r6 * r3; - r17 = r10 * r15; - r17 = fma(r2, r17, r2 * r14); - r17 = fma(r4, r9, r17); + global_thread_idx, r18, r24); + r18 = r9 * r3; + r2 = r16 * r23; + r2 = fma(r8, r2, r8 * r18); + r2 = fma(r4, r19, r2); WriteIdx2<1024, double, double, double2>(out_b_tridig_U, 2 * out_b_tridig_U_num_alloc, - global_thread_idx, r17, r18); - r18 = r12 * r3; - r14 = r13 * r15; - r14 = fma(r2, r14, r2 * r18); - r18 = r11 * r4; - r14 = fma(r2, r18, r14); - r18 = r11 * r11; - r19 = r13 * r13; - r20 = fma(r2, r19, r2 * r18); - r21 = r12 * r12; - r20 = fma(r2, r21, r20); + global_thread_idx, r2, r24); + r24 = r17 * r3; + r18 = r21 * r23; + r18 = fma(r8, r18, r8 * r24); + r24 = r20 * r4; + r18 = fma(r8, r24, r18); + r24 = r20 * r20; + r25 = r21 * r21; + r26 = fma(r8, r25, r8 * r24); + r27 = r17 * r17; + r26 = fma(r8, r27, r26); WriteIdx2<1024, double, double, double2>(out_b_tridig_U, 4 * out_b_tridig_U_num_alloc, - global_thread_idx, r20, r14); + global_thread_idx, r26, r18); WriteIdx2<1024, double, double, double2>(out_b_tridig_U, 6 * out_b_tridig_U_num_alloc, - global_thread_idx, r17, r14); - r14 = r4 * r4; - r17 = r15 * r15; - r20 = fma(r2, r17, r2 * r14); - r22 = r3 * r3; - r20 = fma(r2, r22, r20); + global_thread_idx, r2, r18); + r18 = r4 * r4; + r2 = r23 * r23; + r26 = fma(r8, r2, r8 * r18); + r28 = r3 * r3; + r26 = fma(r8, r28, r26); WriteIdx1<1024, double, double, double>(out_b_tridig_U, 8 * out_b_tridig_U_num_alloc, - global_thread_idx, r20); - r20 = fma(r6, r0, r10 * r5); - r20 = fma(r7, r1, r20); - r23 = fma(r12, r0, r13 * r5); - r23 = fma(r11, r1, r23); - r24 = r13 * r2; - r25 = r12 * r2; - r25 = fma(r0, r25, r5 * r24); - r24 = r11 * r2; - r25 = fma(r1, r24, r25); - r24 = r10 * r2; - r26 = r6 * r2; - r26 = fma(r0, r26, r5 * r24); - r26 = fma(r1, r9, r26); + global_thread_idx, r26); + r5 = fma(r5, r8, r6); + r22 = fma(r23, r5, r22 * r8); + r11 = fma(r11, r8, r13); + r12 = fma(r12, r8, r14); + r22 = fma(r16, r11, r22); + r22 = fma(r21, r12, r22); + r0 = fma(r3, r5, r0 * r8); + r0 = fma(r9, r11, r0); + r0 = fma(r17, r12, r0); + r14 = fma(r9, r0, r16 * r22); + r5 = fma(r4, r5, r1 * r8); + r5 = fma(r10, r11, r5); + r5 = fma(r20, r12, r5); + r14 = fma(r10, r5, r14); + r12 = fma(r17, r0, r21 * r22); + r12 = fma(r20, r5, r12); + r11 = r21 * r8; + r1 = r17 * r8; + r1 = fma(r0, r1, r22 * r11); + r11 = r20 * r8; + r1 = fma(r5, r11, r1); + r11 = r16 * r8; + r13 = r9 * r8; + r13 = fma(r0, r13, r22 * r11); + r13 = fma(r5, r19, r13); }; ShuffleAndWrite2((double*)inout_shared, out_b_njtr, 0 * out_b_njtr_num_alloc, global_thread_idx, - problem_size, r20, r23, r26, r25); + problem_size, r14, r12, r13, r1); if (global_thread_idx < problem_size) { - r25 = fma(r3, r0, r15 * r5); - r25 = fma(r4, r1, r25); - r26 = r15 * r2; - r23 = r3 * r2; - r23 = fma(r0, r23, r5 * r26); - r26 = r4 * r2; - r23 = fma(r1, r26, r23); + r1 = fma(r3, r0, r23 * r22); + r1 = fma(r4, r5, r1); + r13 = r23 * r8; + r12 = r3 * r8; + r12 = fma(r0, r12, r22 * r13); + r13 = r4 * r8; + r12 = fma(r5, r13, r12); }; ShuffleAndWrite1((double*)inout_shared, out_b_njtr, 2 * out_b_njtr_num_alloc, global_thread_idx, - problem_size, r25, r23); + problem_size, r1, r12); if (global_thread_idx < problem_size) { - r8 = fma(r7, r7, r8); - r8 = r8 + r16; - r19 = r18 + r19; - r19 = r19 + r21; + r7 = fma(r10, r10, r7); + r7 = r7 + r15; + r25 = r24 + r25; + r25 = r25 + r27; }; ShuffleAndWrite2( (double*)inout_shared, out_b_precond_diag, 0 * out_b_precond_diag_num_alloc, - global_thread_idx, problem_size, r8, r19, r8, r19); + global_thread_idx, problem_size, r7, r25, r7, r25); if (global_thread_idx < problem_size) { - r17 = r14 + r17; - r17 = r17 + r22; + r2 = r18 + r2; + r2 = r2 + r28; }; ShuffleAndWrite1((double*)inout_shared, out_b_precond_diag, 2 * out_b_precond_diag_num_alloc, - global_thread_idx, problem_size, r17, r17); + global_thread_idx, problem_size, r2, r2); if (global_thread_idx < problem_size) { - r17 = fma(r10, r13, r6 * r12); - r17 = fma(r7, r11, r17); - r22 = fma(r10, r15, r6 * r3); - r22 = fma(r7, r4, r22); + r2 = fma(r16, r21, r9 * r17); + r2 = fma(r10, r20, r2); + r28 = fma(r16, r23, r9 * r3); + r28 = fma(r10, r4, r28); }; ShuffleAndWrite2( (double*)inout_shared, out_b_precond_tril, 0 * out_b_precond_tril_num_alloc, - global_thread_idx, problem_size, r17, r22, r17, r22); + global_thread_idx, problem_size, r2, r28, r2, r28); if (global_thread_idx < problem_size) { - r22 = fma(r13, r15, r12 * r3); - r22 = fma(r11, r4, r22); + r28 = fma(r21, r23, r17 * r3); + r28 = fma(r20, r4, r28); }; ShuffleAndWrite1((double*)inout_shared, out_b_precond_tril, 2 * out_b_precond_tril_num_alloc, - global_thread_idx, problem_size, r22, r22); + global_thread_idx, problem_size, r28, r28); SumFlushFinal(out_rTr_local, out_rTr, 1); } diff --git a/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_b_prior_res_jac.cu b/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_b_prior_res_jac.cu index 1d01a9ea..9ef47604 100644 --- a/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_b_prior_res_jac.cu +++ b/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_b_prior_res_jac.cu @@ -35,7 +35,7 @@ __global__ void __launch_bounds__(1024, 1) (global_thread_idx < problem_size ? b_indices[global_thread_idx] : SharedIndex{0xffffffff, 0xffff, 0xffff}); - double r0 = 0, r1 = 0, r2 = 0, r3 = 0, r4 = 0; + double r0 = 0, r1 = 0, r2 = 0, r3 = 0, r4 = 0, r5 = 0, r6 = 0; LoadShared<2, double, double>(b, 0 * b_num_alloc, b_indices_loc, (double*)inout_shared); if (global_thread_idx < problem_size) { ReadShared2((double*)inout_shared, b_indices_loc[threadIdx.x].target, r0, r1); @@ -45,40 +45,44 @@ __global__ void __launch_bounds__(1024, 1) ReadIdx2<1024, double, double, double2>(target, 0 * target_num_alloc, global_thread_idx, r2, r3); r4 = -1.00000000000000000e+00; - r2 = fma(r2, r4, r0); - r3 = fma(r3, r4, r1); - WriteIdx2<1024, double, double, double2>(out_res, 0 * out_res_num_alloc, global_thread_idx, r2, - r3); + r5 = fma(r2, r4, r0); + r6 = fma(r3, r4, r1); + WriteIdx2<1024, double, double, double2>(out_res, 0 * out_res_num_alloc, global_thread_idx, r5, + r6); }; LoadShared<1, double, double>(b, 2 * b_num_alloc, b_indices_loc, (double*)inout_shared); if (global_thread_idx < problem_size) { - ReadShared1((double*)inout_shared, b_indices_loc[threadIdx.x].target, r1); + ReadShared1((double*)inout_shared, b_indices_loc[threadIdx.x].target, r6); }; __syncthreads(); if (global_thread_idx < problem_size) { - ReadIdx1<1024, double, double, double>(target, 2 * target_num_alloc, global_thread_idx, r0); - r0 = fma(r0, r4, r1); - WriteIdx1<1024, double, double, double>(out_res, 2 * out_res_num_alloc, global_thread_idx, r0); + ReadIdx1<1024, double, double, double>(target, 2 * target_num_alloc, global_thread_idx, r5); + r4 = fma(r5, r4, r6); + WriteIdx1<1024, double, double, double>(out_res, 2 * out_res_num_alloc, global_thread_idx, r4); + r4 = -1.00000000000000000e+00; + r2 = fma(r2, r4, r0); r2 = r4 * r2; + r3 = fma(r3, r4, r1); r3 = r4 * r3; WriteSum2((double*)inout_shared, r2, r3); }; FlushSumShared<2, double>(out_b_njtr, 0 * out_b_njtr_num_alloc, b_indices_loc, (double*)inout_shared); if (global_thread_idx < problem_size) { - r0 = r4 * r0; - WriteSum1((double*)inout_shared, r0); + r5 = fma(r5, r4, r6); + r5 = r4 * r5; + WriteSum1((double*)inout_shared, r5); }; FlushSumShared<1, double>(out_b_njtr, 2 * out_b_njtr_num_alloc, b_indices_loc, (double*)inout_shared); if (global_thread_idx < problem_size) { - r0 = 1.00000000000000000e+00; - WriteSum2((double*)inout_shared, r0, r0); + r5 = 1.00000000000000000e+00; + WriteSum2((double*)inout_shared, r5, r5); }; FlushSumShared<2, double>(out_b_precond_diag, 0 * out_b_precond_diag_num_alloc, b_indices_loc, (double*)inout_shared); if (global_thread_idx < problem_size) { - WriteSum1((double*)inout_shared, r0); + WriteSum1((double*)inout_shared, r5); }; FlushSumShared<1, double>(out_b_precond_diag, 2 * out_b_precond_diag_num_alloc, b_indices_loc, (double*)inout_shared); diff --git a/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_b_prior_res_jac_first.cu b/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_b_prior_res_jac_first.cu index a7df9eb8..bbfd88e2 100644 --- a/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_b_prior_res_jac_first.cu +++ b/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_b_prior_res_jac_first.cu @@ -38,7 +38,7 @@ __global__ void __launch_bounds__(1024, 1) __shared__ double out_rTr_local[1]; - double r0 = 0, r1 = 0, r2 = 0, r3 = 0, r4 = 0; + double r0 = 0, r1 = 0, r2 = 0, r3 = 0, r4 = 0, r5 = 0, r6 = 0, r7 = 0, r8 = 0; LoadShared<2, double, double>(b, 0 * b_num_alloc, b_indices_loc, (double*)inout_shared); if (global_thread_idx < problem_size) { ReadShared2((double*)inout_shared, b_indices_loc[threadIdx.x].target, r0, r1); @@ -48,45 +48,49 @@ __global__ void __launch_bounds__(1024, 1) ReadIdx2<1024, double, double, double2>(target, 0 * target_num_alloc, global_thread_idx, r2, r3); r4 = -1.00000000000000000e+00; - r2 = fma(r2, r4, r0); - r3 = fma(r3, r4, r1); - WriteIdx2<1024, double, double, double2>(out_res, 0 * out_res_num_alloc, global_thread_idx, r2, - r3); + r5 = fma(r2, r4, r0); + r6 = fma(r3, r4, r1); + WriteIdx2<1024, double, double, double2>(out_res, 0 * out_res_num_alloc, global_thread_idx, r5, + r6); }; LoadShared<1, double, double>(b, 2 * b_num_alloc, b_indices_loc, (double*)inout_shared); if (global_thread_idx < problem_size) { - ReadShared1((double*)inout_shared, b_indices_loc[threadIdx.x].target, r1); + ReadShared1((double*)inout_shared, b_indices_loc[threadIdx.x].target, r7); }; __syncthreads(); if (global_thread_idx < problem_size) { - ReadIdx1<1024, double, double, double>(target, 2 * target_num_alloc, global_thread_idx, r0); - r0 = fma(r0, r4, r1); - WriteIdx1<1024, double, double, double>(out_res, 2 * out_res_num_alloc, global_thread_idx, r0); - r1 = fma(r2, r2, r0 * r0); - r1 = fma(r3, r3, r1); + ReadIdx1<1024, double, double, double>(target, 2 * target_num_alloc, global_thread_idx, r8); + r4 = fma(r8, r4, r7); + WriteIdx1<1024, double, double, double>(out_res, 2 * out_res_num_alloc, global_thread_idx, r4); + r5 = fma(r5, r5, r4 * r4); + r5 = fma(r6, r6, r5); }; - SumStore(out_rTr_local, (double*)inout_shared, 0, global_thread_idx < problem_size, r1); + SumStore(out_rTr_local, (double*)inout_shared, 0, global_thread_idx < problem_size, r5); if (global_thread_idx < problem_size) { - r2 = r4 * r2; - r3 = r4 * r3; + r5 = -1.00000000000000000e+00; + r2 = fma(r2, r5, r0); + r2 = r5 * r2; + r3 = fma(r3, r5, r1); + r3 = r5 * r3; WriteSum2((double*)inout_shared, r2, r3); }; FlushSumShared<2, double>(out_b_njtr, 0 * out_b_njtr_num_alloc, b_indices_loc, (double*)inout_shared); if (global_thread_idx < problem_size) { - r0 = r4 * r0; - WriteSum1((double*)inout_shared, r0); + r8 = fma(r8, r5, r7); + r8 = r5 * r8; + WriteSum1((double*)inout_shared, r8); }; FlushSumShared<1, double>(out_b_njtr, 2 * out_b_njtr_num_alloc, b_indices_loc, (double*)inout_shared); if (global_thread_idx < problem_size) { - r0 = 1.00000000000000000e+00; - WriteSum2((double*)inout_shared, r0, r0); + r8 = 1.00000000000000000e+00; + WriteSum2((double*)inout_shared, r8, r8); }; FlushSumShared<2, double>(out_b_precond_diag, 0 * out_b_precond_diag_num_alloc, b_indices_loc, (double*)inout_shared); if (global_thread_idx < problem_size) { - WriteSum1((double*)inout_shared, r0); + WriteSum1((double*)inout_shared, r8); }; FlushSumShared<1, double>(out_b_precond_diag, 2 * out_b_precond_diag_num_alloc, b_indices_loc, (double*)inout_shared); diff --git a/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_coupling_res_jac.cu b/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_coupling_res_jac.cu index 44138dfc..993f40cc 100644 --- a/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_coupling_res_jac.cu +++ b/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_coupling_res_jac.cu @@ -45,7 +45,7 @@ __global__ void __launch_bounds__(1024, 1) ChainCouplingResJacKernel( : SharedIndex{0xffffffff, 0xffff, 0xffff}); double r0 = 0, r1 = 0, r2 = 0, r3 = 0, r4 = 0, r5 = 0, r6 = 0, r7 = 0, r8 = 0, r9 = 0, r10 = 0, - r11 = 0, r12 = 0, r13 = 0; + r11 = 0, r12 = 0, r13 = 0, r14 = 0, r15 = 0, r16 = 0; LoadShared<2, double, double>(a, 0 * a_num_alloc, a_indices_loc, (double*)inout_shared); if (global_thread_idx < problem_size) { ReadShared2((double*)inout_shared, a_indices_loc[threadIdx.x].target, r0, r1); @@ -55,96 +55,114 @@ __global__ void __launch_bounds__(1024, 1) ChainCouplingResJacKernel( ReadIdx2<1024, double, double, double2>(offset, 0 * offset_num_alloc, global_thread_idx, r2, r3); r4 = -1.00000000000000000e+00; - r2 = fma(r2, r4, r0); + r5 = fma(r2, r4, r0); }; LoadShared<1, double, double>(b, 2 * b_num_alloc, b_indices_loc, (double*)inout_shared); if (global_thread_idx < problem_size) { - ReadShared1((double*)inout_shared, b_indices_loc[threadIdx.x].target, r0); + ReadShared1((double*)inout_shared, b_indices_loc[threadIdx.x].target, r6); }; __syncthreads(); if (global_thread_idx < problem_size) { - ReadIdx2<1024, double, double, double2>(weight, 4 * weight_num_alloc, global_thread_idx, r5, - r6); + ReadIdx2<1024, double, double, double2>(weight, 4 * weight_num_alloc, global_thread_idx, r7, + r8); }; LoadShared<2, double, double>(b, 0 * b_num_alloc, b_indices_loc, (double*)inout_shared); if (global_thread_idx < problem_size) { - ReadShared2((double*)inout_shared, b_indices_loc[threadIdx.x].target, r7, r8); + ReadShared2((double*)inout_shared, b_indices_loc[threadIdx.x].target, r9, r10); }; __syncthreads(); if (global_thread_idx < problem_size) { - ReadIdx2<1024, double, double, double2>(weight, 2 * weight_num_alloc, global_thread_idx, r9, - r10); - r11 = fma(r8, r9, r0 * r5); - ReadIdx2<1024, double, double, double2>(weight, 0 * weight_num_alloc, global_thread_idx, r12, - r13); - r11 = fma(r7, r12, r11); - r2 = fma(r4, r11, r2); - r3 = fma(r3, r4, r1); - r8 = fma(r8, r10, r0 * r6); - r8 = fma(r7, r13, r8); - r3 = fma(r4, r8, r3); - WriteIdx2<1024, double, double, double2>(out_res, 0 * out_res_num_alloc, global_thread_idx, r2, - r3); - r8 = r4 * r2; - r7 = r4 * r3; - WriteSum2((double*)inout_shared, r8, r7); + ReadIdx2<1024, double, double, double2>(weight, 2 * weight_num_alloc, global_thread_idx, r11, + r12); + r13 = fma(r10, r11, r6 * r7); + ReadIdx2<1024, double, double, double2>(weight, 0 * weight_num_alloc, global_thread_idx, r14, + r15); + r13 = fma(r9, r14, r13); + r5 = fma(r4, r13, r5); + r13 = fma(r3, r4, r1); + r16 = fma(r10, r12, r6 * r8); + r16 = fma(r9, r15, r16); + r13 = fma(r4, r16, r13); + WriteIdx2<1024, double, double, double2>(out_res, 0 * out_res_num_alloc, global_thread_idx, r5, + r13); + r13 = -1.00000000000000000e+00; + r5 = fma(r2, r13, r0); + r16 = fma(r10, r11, r6 * r7); + r16 = fma(r9, r14, r16); + r5 = fma(r13, r16, r5); + r5 = r13 * r5; + r16 = fma(r3, r13, r1); + r4 = fma(r10, r12, r6 * r8); + r4 = fma(r9, r15, r4); + r16 = fma(r13, r4, r16); + r16 = r13 * r16; + WriteSum2((double*)inout_shared, r5, r16); }; FlushSumShared<2, double>(out_a_njtr, 0 * out_a_njtr_num_alloc, a_indices_loc, (double*)inout_shared); if (global_thread_idx < problem_size) { - r7 = 1.00000000000000000e+00; - WriteSum2((double*)inout_shared, r7, r7); + r16 = 1.00000000000000000e+00; + WriteSum2((double*)inout_shared, r16, r16); }; FlushSumShared<2, double>(out_a_precond_diag, 0 * out_a_precond_diag_num_alloc, a_indices_loc, (double*)inout_shared); if (global_thread_idx < problem_size) { - r7 = r12 * r4; - r8 = r13 * r4; + r16 = -1.00000000000000000e+00; + r5 = r14 * r16; + r13 = r15 * r16; WriteIdx2<1024, double, double, double2>(out_b_jac, 0 * out_b_jac_num_alloc, global_thread_idx, - r7, r8); - r8 = r9 * r4; - r7 = r10 * r4; + r5, r13); + r13 = r11 * r16; + r5 = r12 * r16; WriteIdx2<1024, double, double, double2>(out_b_jac, 2 * out_b_jac_num_alloc, global_thread_idx, - r8, r7); - r7 = r5 * r4; - r4 = r6 * r4; + r13, r5); + r5 = r7 * r16; + r13 = r8 * r16; WriteIdx2<1024, double, double, double2>(out_b_jac, 4 * out_b_jac_num_alloc, global_thread_idx, - r7, r4); - r4 = fma(r12, r2, r13 * r3); - r7 = fma(r9, r2, r10 * r3); - WriteSum2((double*)inout_shared, r4, r7); + r5, r13); + r3 = fma(r3, r16, r1); + r1 = fma(r10, r12, r6 * r8); + r1 = fma(r9, r15, r1); + r3 = fma(r16, r1, r3); + r2 = fma(r2, r16, r0); + r10 = fma(r10, r11, r6 * r7); + r10 = fma(r9, r14, r10); + r2 = fma(r16, r10, r2); + r10 = fma(r14, r2, r15 * r3); + r16 = fma(r11, r2, r12 * r3); + WriteSum2((double*)inout_shared, r10, r16); }; FlushSumShared<2, double>(out_b_njtr, 0 * out_b_njtr_num_alloc, b_indices_loc, (double*)inout_shared); if (global_thread_idx < problem_size) { - r2 = fma(r5, r2, r6 * r3); + r2 = fma(r7, r2, r8 * r3); WriteSum1((double*)inout_shared, r2); }; FlushSumShared<1, double>(out_b_njtr, 2 * out_b_njtr_num_alloc, b_indices_loc, (double*)inout_shared); if (global_thread_idx < problem_size) { - r2 = fma(r12, r12, r13 * r13); - r3 = fma(r9, r9, r10 * r10); + r2 = fma(r14, r14, r15 * r15); + r3 = fma(r11, r11, r12 * r12); WriteSum2((double*)inout_shared, r2, r3); }; FlushSumShared<2, double>(out_b_precond_diag, 0 * out_b_precond_diag_num_alloc, b_indices_loc, (double*)inout_shared); if (global_thread_idx < problem_size) { - r3 = fma(r5, r5, r6 * r6); + r3 = fma(r7, r7, r8 * r8); WriteSum1((double*)inout_shared, r3); }; FlushSumShared<1, double>(out_b_precond_diag, 2 * out_b_precond_diag_num_alloc, b_indices_loc, (double*)inout_shared); if (global_thread_idx < problem_size) { - r3 = fma(r13, r10, r12 * r9); - r13 = fma(r13, r6, r12 * r5); - WriteSum2((double*)inout_shared, r3, r13); + r3 = fma(r15, r12, r14 * r11); + r15 = fma(r15, r8, r14 * r7); + WriteSum2((double*)inout_shared, r3, r15); }; FlushSumShared<2, double>(out_b_precond_tril, 0 * out_b_precond_tril_num_alloc, b_indices_loc, (double*)inout_shared); if (global_thread_idx < problem_size) { - r6 = fma(r10, r6, r9 * r5); - WriteSum1((double*)inout_shared, r6); + r8 = fma(r12, r8, r11 * r7); + WriteSum1((double*)inout_shared, r8); }; FlushSumShared<1, double>(out_b_precond_tril, 2 * out_b_precond_tril_num_alloc, b_indices_loc, (double*)inout_shared); diff --git a/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_coupling_res_jac_first.cu b/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_coupling_res_jac_first.cu index 38f5df97..8383ea46 100644 --- a/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_coupling_res_jac_first.cu +++ b/test/symforce_function_codegen_test_data/symengine/symforce_caspar_tridiagonal_test/kernel_chain_coupling_res_jac_first.cu @@ -47,7 +47,7 @@ __global__ void __launch_bounds__(1024, 1) ChainCouplingResJacFirstKernel( __shared__ double out_rTr_local[1]; double r0 = 0, r1 = 0, r2 = 0, r3 = 0, r4 = 0, r5 = 0, r6 = 0, r7 = 0, r8 = 0, r9 = 0, r10 = 0, - r11 = 0, r12 = 0, r13 = 0; + r11 = 0, r12 = 0, r13 = 0, r14 = 0, r15 = 0, r16 = 0; LoadShared<2, double, double>(a, 0 * a_num_alloc, a_indices_loc, (double*)inout_shared); if (global_thread_idx < problem_size) { ReadShared2((double*)inout_shared, a_indices_loc[threadIdx.x].target, r0, r1); @@ -57,100 +57,118 @@ __global__ void __launch_bounds__(1024, 1) ChainCouplingResJacFirstKernel( ReadIdx2<1024, double, double, double2>(offset, 0 * offset_num_alloc, global_thread_idx, r2, r3); r4 = -1.00000000000000000e+00; - r2 = fma(r2, r4, r0); + r5 = fma(r2, r4, r0); }; LoadShared<1, double, double>(b, 2 * b_num_alloc, b_indices_loc, (double*)inout_shared); if (global_thread_idx < problem_size) { - ReadShared1((double*)inout_shared, b_indices_loc[threadIdx.x].target, r0); + ReadShared1((double*)inout_shared, b_indices_loc[threadIdx.x].target, r6); }; __syncthreads(); if (global_thread_idx < problem_size) { - ReadIdx2<1024, double, double, double2>(weight, 4 * weight_num_alloc, global_thread_idx, r5, - r6); + ReadIdx2<1024, double, double, double2>(weight, 4 * weight_num_alloc, global_thread_idx, r7, + r8); }; LoadShared<2, double, double>(b, 0 * b_num_alloc, b_indices_loc, (double*)inout_shared); if (global_thread_idx < problem_size) { - ReadShared2((double*)inout_shared, b_indices_loc[threadIdx.x].target, r7, r8); + ReadShared2((double*)inout_shared, b_indices_loc[threadIdx.x].target, r9, r10); }; __syncthreads(); if (global_thread_idx < problem_size) { - ReadIdx2<1024, double, double, double2>(weight, 2 * weight_num_alloc, global_thread_idx, r9, - r10); - r11 = fma(r8, r9, r0 * r5); - ReadIdx2<1024, double, double, double2>(weight, 0 * weight_num_alloc, global_thread_idx, r12, - r13); - r11 = fma(r7, r12, r11); - r2 = fma(r4, r11, r2); - r3 = fma(r3, r4, r1); - r8 = fma(r8, r10, r0 * r6); - r8 = fma(r7, r13, r8); - r3 = fma(r4, r8, r3); - WriteIdx2<1024, double, double, double2>(out_res, 0 * out_res_num_alloc, global_thread_idx, r2, - r3); - r8 = fma(r2, r2, r3 * r3); + ReadIdx2<1024, double, double, double2>(weight, 2 * weight_num_alloc, global_thread_idx, r11, + r12); + r13 = fma(r10, r11, r6 * r7); + ReadIdx2<1024, double, double, double2>(weight, 0 * weight_num_alloc, global_thread_idx, r14, + r15); + r13 = fma(r9, r14, r13); + r5 = fma(r4, r13, r5); + r13 = fma(r3, r4, r1); + r16 = fma(r10, r12, r6 * r8); + r16 = fma(r9, r15, r16); + r13 = fma(r4, r16, r13); + WriteIdx2<1024, double, double, double2>(out_res, 0 * out_res_num_alloc, global_thread_idx, r5, + r13); + r5 = fma(r5, r5, r13 * r13); }; - SumStore(out_rTr_local, (double*)inout_shared, 0, global_thread_idx < problem_size, r8); + SumStore(out_rTr_local, (double*)inout_shared, 0, global_thread_idx < problem_size, r5); if (global_thread_idx < problem_size) { - r8 = r4 * r2; - r7 = r4 * r3; - WriteSum2((double*)inout_shared, r8, r7); + r5 = -1.00000000000000000e+00; + r13 = fma(r2, r5, r0); + r16 = fma(r10, r11, r6 * r7); + r16 = fma(r9, r14, r16); + r13 = fma(r5, r16, r13); + r13 = r5 * r13; + r16 = fma(r3, r5, r1); + r4 = fma(r10, r12, r6 * r8); + r4 = fma(r9, r15, r4); + r16 = fma(r5, r4, r16); + r16 = r5 * r16; + WriteSum2((double*)inout_shared, r13, r16); }; FlushSumShared<2, double>(out_a_njtr, 0 * out_a_njtr_num_alloc, a_indices_loc, (double*)inout_shared); if (global_thread_idx < problem_size) { - r7 = 1.00000000000000000e+00; - WriteSum2((double*)inout_shared, r7, r7); + r16 = 1.00000000000000000e+00; + WriteSum2((double*)inout_shared, r16, r16); }; FlushSumShared<2, double>(out_a_precond_diag, 0 * out_a_precond_diag_num_alloc, a_indices_loc, (double*)inout_shared); if (global_thread_idx < problem_size) { - r7 = r12 * r4; - r8 = r13 * r4; + r16 = -1.00000000000000000e+00; + r13 = r14 * r16; + r5 = r15 * r16; WriteIdx2<1024, double, double, double2>(out_b_jac, 0 * out_b_jac_num_alloc, global_thread_idx, - r7, r8); - r8 = r9 * r4; - r7 = r10 * r4; + r13, r5); + r5 = r11 * r16; + r13 = r12 * r16; WriteIdx2<1024, double, double, double2>(out_b_jac, 2 * out_b_jac_num_alloc, global_thread_idx, - r8, r7); - r7 = r5 * r4; - r4 = r6 * r4; + r5, r13); + r13 = r7 * r16; + r5 = r8 * r16; WriteIdx2<1024, double, double, double2>(out_b_jac, 4 * out_b_jac_num_alloc, global_thread_idx, - r7, r4); - r4 = fma(r12, r2, r13 * r3); - r7 = fma(r9, r2, r10 * r3); - WriteSum2((double*)inout_shared, r4, r7); + r13, r5); + r3 = fma(r3, r16, r1); + r1 = fma(r10, r12, r6 * r8); + r1 = fma(r9, r15, r1); + r3 = fma(r16, r1, r3); + r2 = fma(r2, r16, r0); + r10 = fma(r10, r11, r6 * r7); + r10 = fma(r9, r14, r10); + r2 = fma(r16, r10, r2); + r10 = fma(r14, r2, r15 * r3); + r16 = fma(r11, r2, r12 * r3); + WriteSum2((double*)inout_shared, r10, r16); }; FlushSumShared<2, double>(out_b_njtr, 0 * out_b_njtr_num_alloc, b_indices_loc, (double*)inout_shared); if (global_thread_idx < problem_size) { - r2 = fma(r5, r2, r6 * r3); + r2 = fma(r7, r2, r8 * r3); WriteSum1((double*)inout_shared, r2); }; FlushSumShared<1, double>(out_b_njtr, 2 * out_b_njtr_num_alloc, b_indices_loc, (double*)inout_shared); if (global_thread_idx < problem_size) { - r2 = fma(r12, r12, r13 * r13); - r3 = fma(r9, r9, r10 * r10); + r2 = fma(r14, r14, r15 * r15); + r3 = fma(r11, r11, r12 * r12); WriteSum2((double*)inout_shared, r2, r3); }; FlushSumShared<2, double>(out_b_precond_diag, 0 * out_b_precond_diag_num_alloc, b_indices_loc, (double*)inout_shared); if (global_thread_idx < problem_size) { - r3 = fma(r5, r5, r6 * r6); + r3 = fma(r7, r7, r8 * r8); WriteSum1((double*)inout_shared, r3); }; FlushSumShared<1, double>(out_b_precond_diag, 2 * out_b_precond_diag_num_alloc, b_indices_loc, (double*)inout_shared); if (global_thread_idx < problem_size) { - r3 = fma(r13, r10, r12 * r9); - r13 = fma(r13, r6, r12 * r5); - WriteSum2((double*)inout_shared, r3, r13); + r3 = fma(r15, r12, r14 * r11); + r15 = fma(r15, r8, r14 * r7); + WriteSum2((double*)inout_shared, r3, r15); }; FlushSumShared<2, double>(out_b_precond_tril, 0 * out_b_precond_tril_num_alloc, b_indices_loc, (double*)inout_shared); if (global_thread_idx < problem_size) { - r6 = fma(r10, r6, r9 * r5); - WriteSum1((double*)inout_shared, r6); + r8 = fma(r12, r8, r11 * r7); + WriteSum1((double*)inout_shared, r8); }; FlushSumShared<1, double>(out_b_precond_tril, 2 * out_b_precond_tril_num_alloc, b_indices_loc, (double*)inout_shared);