|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| module @jst_sovereign_pipeline {
|
|
|
|
|
|
|
|
|
| func.func private @sov_plasma_verify_tensor(tensor<?xf64>) -> i1
|
| func.func private @sov_bifrost_sign_hash(tensor<32xi8>, tensor<32xi8>, tensor<64xi8>) -> ()
|
| func.func private @sov_blake3_hash_tensor(tensor<?xf64>, tensor<32xi8>) -> ()
|
| func.func private @sov_zmexp_scaling_squaring(tensor<?x?xf64>, tensor<?x?xf64>, f64) -> (tensor<?x?xf64>, tensor<?x?xf64>)
|
| func.func private @sov_spe_encode_frame(tensor<?x?xf64>, tensor<?x?xf64>, tensor<?x?x?xf64>, tensor<?x?x?xf64>) -> (tensor<?xf64>, tensor<?x?xf64>, tensor<?x?xf64>)
|
| func.func private @sov_spe_decode_frame(tensor<?x?xf64>, tensor<?x?xf64>, tensor<?x?x?xf64>, tensor<?x?x?xf64>) -> (tensor<?xf64>, tensor<?x?xf64>)
|
| func.func private @sov_boolean_lens_watch(tensor<?xf64>, tensor<32xi8>, tensor<?xi8>) -> ()
|
|
|
|
|
|
|
|
|
|
|
| func.func @jst_spe_encode_fused(
|
| %signal_real: tensor<?x?xf64>, %signal_imag: tensor<?x?xf64>,
|
| %frame_real: tensor<?x?x?xf64>, %frame_imag: tensor<?x?x?xf64>,
|
| %sk: tensor<32xi8>, %pk: tensor<32xi8>
|
| ) -> (tensor<?xf64>, tensor<?x?xf64>, tensor<?x?xf64>, tensor<32xi8>, tensor<64xi8>, i1) {
|
|
|
| %eigenvals, %rho_real, %rho_imag = func.call @sov_spe_encode_frame(
|
| %signal_real, %signal_imag, %frame_real, %frame_imag)
|
| : (tensor<?x?xf64>, tensor<?x?xf64>, tensor<?x?x?xf64>, tensor<?x?x?xf64>)
|
| -> (tensor<?xf64>, tensor<?x?xf64>, tensor<?x?xf64>)
|
|
|
| %plasma_ok = func.call @sov_plasma_verify_tensor(%rho_real)
|
| : (tensor<?xf64>) -> i1
|
|
|
| %hash = tensor.empty() : tensor<32xi8>
|
| %sig = tensor.empty() : tensor<64xi8>
|
| func.call @sov_blake3_hash_tensor(%rho_real, %hash) : (tensor<?xf64>, tensor<32xi8>) -> ()
|
| func.call @sov_bifrost_sign_hash(%hash, %sk, %sig) : (tensor<32xi8>, tensor<32xi8>, tensor<64xi8>) -> ()
|
|
|
| return %eigenvals, %rho_real, %rho_imag, %hash, %sig, %plasma_ok
|
| : tensor<?xf64>, tensor<?x?xf64>, tensor<?x?xf64>, tensor<32xi8>, tensor<64xi8>, i1
|
| }
|
|
|
|
|
|
|
|
|
|
|
| func.func @jst_jordan_block_fused(
|
| %rho_real: tensor<?x?xf64>, %rho_imag: tensor<?x?xf64>,
|
| %H_real: tensor<?x?xf64>, %H_imag: tensor<?x?xf64>,
|
| %dt: f64, %sk: tensor<32xi8>, %pk: tensor<32xi8>
|
| ) -> (tensor<?x?xf64>, tensor<?x?xf64>, tensor<32xi8>, tensor<64xi8>, i1) {
|
|
|
|
|
| %U_real, %U_imag = func.call @sov_zmexp_scaling_squaring(%H_real, %H_imag, %dt)
|
| : (tensor<?x?xf64>, tensor<?x?xf64>, f64) -> (tensor<?x?xf64>, tensor<?x?xf64>)
|
|
|
|
|
| %Ut_real = linalg.transpose ins(%U_real : tensor<?x?xf64>) outs(tensor<?x?xf64>) : tensor<?x?xf64> -> tensor<?x?xf64>
|
| %Ut_imag_t = linalg.transpose ins(%U_imag : tensor<?x?xf64>) outs(tensor<?x?xf64>) : tensor<?x?xf64> -> tensor<?x?xf64>
|
| %Ut_imag = linalg.map { arith.negf } ins(%Ut_imag_t : tensor<?x?xf64>) outs(tensor<?x?xf64>)
|
|
|
|
|
|
|
| %n = tensor.dim %rho_real, 0 : tensor<?x?xf64>
|
| %tmp_real = linalg.fill ins(%c0_f64 : f64) outs(tensor.empty(%n,%n) : tensor<?x?xf64>) -> tensor<?x?xf64>
|
| %tmp_imag = linalg.fill ins(%c0_f64 : f64) outs(tensor.empty(%n,%n) : tensor<?x?xf64>) -> tensor<?x?xf64>
|
|
|
| %tr = linalg.matmul ins(%U_real, %rho_real : tensor<?x?xf64>, tensor<?x?xf64>) outs(%tmp_real : tensor<?x?xf64>) -> tensor<?x?xf64>
|
| %ti = linalg.matmul ins(%U_real, %rho_imag : tensor<?x?xf64>, tensor<?x?xf64>) outs(%tmp_imag : tensor<?x?xf64>) -> tensor<?x?xf64>
|
|
|
| %rho_out_r = linalg.fill ins(%c0_f64 : f64) outs(tensor.empty(%n,%n) : tensor<?x?xf64>) -> tensor<?x?xf64>
|
| %rho_out_i = linalg.fill ins(%c0_f64 : f64) outs(tensor.empty(%n,%n) : tensor<?x?xf64>) -> tensor<?x?xf64>
|
| %orr = linalg.matmul ins(%tr, %Ut_real : tensor<?x?xf64>, tensor<?x?xf64>) outs(%rho_out_r : tensor<?x?xf64>) -> tensor<?x?xf64>
|
| %ori = linalg.matmul ins(%ti, %Ut_real : tensor<?x?xf64>, tensor<?x?xf64>) outs(%rho_out_i : tensor<?x?xf64>) -> tensor<?x?xf64>
|
|
|
| %plasma_ok = func.call @sov_plasma_verify_tensor(%orr) : (tensor<?xf64>) -> i1
|
|
|
| %hash = tensor.empty() : tensor<32xi8>
|
| %sig = tensor.empty() : tensor<64xi8>
|
| func.call @sov_blake3_hash_tensor(%orr, %hash) : (tensor<?xf64>, tensor<32xi8>) -> ()
|
| func.call @sov_bifrost_sign_hash(%hash, %sk, %sig) : (tensor<32xi8>, tensor<32xi8>, tensor<64xi8>) -> ()
|
|
|
| return %orr, %ori, %hash, %sig, %plasma_ok
|
| : tensor<?x?xf64>, tensor<?x?xf64>, tensor<32xi8>, tensor<64xi8>, i1
|
| }
|
|
|
|
|
|
|
|
|
|
|
| func.func @jst_measurement_head_fused(
|
| %rho_real: tensor<?x?xf64>, %rho_imag: tensor<?x?xf64>,
|
| %q_set_real: tensor<?x?x?xf64>, %q_set_imag: tensor<?x?x?xf64>,
|
| %frame_real: tensor<?x?x?xf64>, %frame_imag: tensor<?x?x?xf64>,
|
| %sk: tensor<32xi8>, %pk: tensor<32xi8>
|
| ) -> (tensor<?xf64>, tensor<?xf64>, tensor<?x?xf64>, tensor<?x?xf64>,
|
| tensor<32xi8>, tensor<64xi8>, i1, f64) {
|
|
|
| %n = tensor.dim %q_set_real, 0 : tensor<?x?x?xf64>
|
| %rank = tensor.dim %rho_real, 0 : tensor<?x?xf64>
|
| %c0_f64 = arith.constant 0.0 : f64
|
| %c1_f64 = arith.constant 1.0 : f64
|
| %eps = arith.constant 2.2250738585072014e-307 : f64
|
|
|
| %probs_init = linalg.fill ins(%c0_f64 : f64) outs(tensor.empty(%n) : tensor<?xf64>) -> tensor<?xf64>
|
|
|
|
|
| %probs_raw = scf.for %k = 0 to %n step 1 iter_args(%p_acc = %probs_init) -> (tensor<?xf64>) {
|
| %trace = scf.for %i = 0 to %rank step 1 iter_args(%t = %c0_f64) -> (f64) {
|
| %t_j = scf.for %j = 0 to %rank step 1 iter_args(%s = %t) -> (f64) {
|
| %qr = tensor.extract %q_set_real[%k, %i, %j] : tensor<?x?x?xf64>
|
| %qi = tensor.extract %q_set_imag[%k, %i, %j] : tensor<?x?x?xf64>
|
| %rr = tensor.extract %rho_real[%i, %j] : tensor<?x?xf64>
|
| %ri = tensor.extract %rho_imag[%i, %j] : tensor<?x?xf64>
|
|
|
| %t1 = arith.mulf %qr, %rr : f64
|
| %t2 = arith.mulf %qi, %ri : f64
|
| %add = arith.addf %t1, %t2 : f64
|
| %ns = arith.addf %s, %add : f64
|
| scf.yield %ns : f64
|
| }
|
| scf.yield %t_j : f64
|
| }
|
| %safe = arith.maxnumf %trace, %c0_f64 : f64
|
| %p_up = tensor.insert %safe into %p_acc[%k] : tensor<?xf64>
|
| scf.yield %p_up : tensor<?xf64>
|
| }
|
|
|
|
|
| %sum_p = linalg.reduce ins(%probs_raw : tensor<?xf64>) outs(tensor.empty() : tensor<f64>) dimensions=[0] {
|
| ^bb0(%a: f64, %b: f64): linalg.yield (arith.addf %a, %b) : f64 }
|
| %sum_v = tensor.extract %sum_p[] : tensor<f64>
|
| %has_m = arith.cmpf ogt, %sum_v, %c0_f64 : i1
|
| %probs = scf.if %has_m -> (tensor<?xf64>) {
|
| %inv = arith.divf %c1_f64, %sum_v : f64
|
| %sc = linalg.map { ^bb0(%x: f64): linalg.yield (arith.mulf %x, %inv) : f64 }
|
| ins(%probs_raw : tensor<?xf64>) outs(tensor.empty(%n) : tensor<?xf64>)
|
| scf.yield %sc : tensor<?xf64>
|
| } else {
|
| %inv_n = arith.divf %c1_f64, (arith.index_cast %n : f64) : f64
|
| %u = linalg.fill ins(%inv_n : f64) outs(tensor.empty(%n) : tensor<?xf64>) -> tensor<?xf64>
|
| scf.yield %u : tensor<?xf64>
|
| }
|
|
|
|
|
| %log_probs = linalg.map {
|
| ^bb0(%x: f64):
|
| %s = arith.maxnumf %x, %eps : f64
|
| linalg.yield (math.log %s) : f64
|
| } ins(%probs : tensor<?xf64>) outs(tensor.empty(%n) : tensor<?xf64>)
|
|
|
| %h_terms = linalg.map {
|
| ^bb0(%p: f64, %l: f64): linalg.yield (arith.mulf %p, (arith.negf %l)) : f64
|
| } ins(%probs, %log_probs : tensor<?xf64>, tensor<?xf64>) outs(tensor.empty(%n) : tensor<?xf64>)
|
| %h_sum = linalg.reduce ins(%h_terms : tensor<?xf64>) outs(tensor.empty() : tensor<f64>) dimensions=[0] {
|
| ^bb0(%a: f64, %b: f64): linalg.yield (arith.addf %a, %b) : f64 }
|
| %entropy = tensor.extract %h_sum[] : tensor<f64>
|
|
|
|
|
| %sr_0 = linalg.fill ins(%c0_f64 : f64) outs(tensor.empty(%rank,%rank) : tensor<?x?xf64>) -> tensor<?x?xf64>
|
| %si_0 = linalg.fill ins(%c0_f64 : f64) outs(tensor.empty(%rank,%rank) : tensor<?x?xf64>) -> tensor<?x?xf64>
|
| %sig_r, %sig_i = scf.for %k = 0 to %n step 1 iter_args(%sr = %sr_0, %si = %si_0) -> (tensor<?x?xf64>, tensor<?x?xf64>) {
|
| %pk = tensor.extract %probs[%k] : tensor<?xf64>
|
| %fr = tensor.extract_slice %frame_real[%k, 0, 0][1, %rank, %rank][1, 1, 1] : tensor<?x?x?xf64> -> tensor<?x?xf64>
|
| %fi = tensor.extract_slice %frame_imag[%k, 0, 0][1, %rank, %rank][1, 1, 1] : tensor<?x?x?xf64> -> tensor<?x?xf64>
|
| %ur = linalg.map { ^bb0(%acc: f64, %f: f64): linalg.yield (arith.addf %acc, (arith.mulf %pk, %f)) : f64 } ins(%sr, %fr : tensor<?x?xf64>, tensor<?x?xf64>) outs(tensor.empty(%rank,%rank) : tensor<?x?xf64>)
|
| %ui = linalg.map { ^bb0(%acc: f64, %f: f64): linalg.yield (arith.addf %acc, (arith.mulf %pk, %f)) : f64 } ins(%si, %fi : tensor<?x?xf64>, tensor<?x?xf64>) outs(tensor.empty(%rank,%rank) : tensor<?x?xf64>)
|
| scf.yield %ur, %ui : tensor<?x?xf64>, tensor<?x?xf64>
|
| }
|
|
|
| %plasma_ok = func.call @sov_plasma_verify_tensor(%sig_r) : (tensor<?xf64>) -> i1
|
|
|
| %hash = tensor.empty() : tensor<32xi8>
|
| %out_sig = tensor.empty() : tensor<64xi8>
|
| func.call @sov_blake3_hash_tensor(%sig_r, %hash) : (tensor<?xf64>, tensor<32xi8>) -> ()
|
| func.call @sov_bifrost_sign_hash(%hash, %sk, %out_sig) : (tensor<32xi8>, tensor<32xi8>, tensor<64xi8>) -> ()
|
|
|
| return %probs, %log_probs, %sig_r, %sig_i, %hash, %out_sig, %plasma_ok, %entropy
|
| : tensor<?xf64>, tensor<?xf64>, tensor<?x?xf64>, tensor<?x?xf64>,
|
| tensor<32xi8>, tensor<64xi8>, i1, f64
|
| }
|
|
|
|
|
|
|
|
|
| func.func @jst_boolean_lens_fused(
|
| %eigenvals: tensor<?xf64>,
|
| %frame_hash: tensor<32xi8>,
|
| %lisp_buffer: tensor<?xi8>
|
| ) -> () {
|
| func.call @sov_boolean_lens_watch(%eigenvals, %frame_hash, %lisp_buffer)
|
| : (tensor<?xf64>, tensor<32xi8>, tensor<?xi8>) -> ()
|
| return
|
| }
|
|
|
|
|
|
|
|
|
|
|
| func.func @jst_main(
|
| %signal_real: tensor<?x?xf64>, %signal_imag: tensor<?x?xf64>,
|
| %frame_real: tensor<?x?x?xf64>, %frame_imag: tensor<?x?x?xf64>,
|
| %H_stack_real: tensor<?x?x?xf64>, %H_stack_imag: tensor<?x?x?xf64>,
|
| %dt_stack: tensor<?xf64>,
|
| %q_set_real: tensor<?x?x?xf64>, %q_set_imag: tensor<?x?x?xf64>,
|
| %sk: tensor<32xi8>, %pk: tensor<32xi8>,
|
| %lisp_buffer: tensor<?xi8>
|
| ) -> (tensor<?x?xf64>, tensor<?x?xf64>, tensor<?xf64>, tensor<?xf64>, f64, i1) {
|
|
|
|
|
| %ev0, %rho_r, %rho_i, %h0, %s0, %p0 =
|
| func.call @jst_spe_encode_fused(%signal_real, %signal_imag, %frame_real, %frame_imag, %sk, %pk)
|
| : (tensor<?x?xf64>, tensor<?x?xf64>, tensor<?x?x?xf64>, tensor<?x?x?xf64>, tensor<32xi8>, tensor<32xi8>)
|
| -> (tensor<?xf64>, tensor<?x?xf64>, tensor<?x?xf64>, tensor<32xi8>, tensor<64xi8>, i1)
|
|
|
| func.call @jst_boolean_lens_fused(%ev0, %h0, %lisp_buffer) : (tensor<?xf64>, tensor<32xi8>, tensor<?xi8>) -> ()
|
|
|
|
|
| %depth = tensor.dim %H_stack_real, 0 : tensor<?x?x?xf64>
|
| %rho_cur_r, %rho_cur_i = scf.for %k = 0 to %depth step 1
|
| iter_args(%rr = %rho_r, %ri = %rho_i) -> (tensor<?x?xf64>, tensor<?x?xf64>) {
|
| %Hkr = tensor.extract_slice %H_stack_real[%k, 0, 0][1,-1,-1][1,1,1] : tensor<?x?x?xf64> -> tensor<?x?xf64>
|
| %Hki = tensor.extract_slice %H_stack_imag[%k, 0, 0][1,-1,-1][1,1,1] : tensor<?x?x?xf64> -> tensor<?x?xf64>
|
| %dtk = tensor.extract %dt_stack[%k] : tensor<?xf64>
|
| %nr, %ni, %hk, %sk2, %pk2 =
|
| func.call @jst_jordan_block_fused(%rr, %ri, %Hkr, %Hki, %dtk, %sk, %pk)
|
| : (tensor<?x?xf64>, tensor<?x?xf64>, tensor<?x?xf64>, tensor<?x?xf64>, f64,
|
| tensor<32xi8>, tensor<32xi8>) -> (tensor<?x?xf64>, tensor<?x?xf64>, tensor<32xi8>, tensor<64xi8>, i1)
|
| %evk, %_ = func.call @sov_spe_decode_frame(%nr, %ni, %frame_real, %frame_imag)
|
| : (tensor<?x?xf64>, tensor<?x?xf64>, tensor<?x?x?xf64>, tensor<?x?x?xf64>) -> (tensor<?xf64>, tensor<?x?xf64>)
|
| func.call @jst_boolean_lens_fused(%evk, %hk, %lisp_buffer) : (tensor<?xf64>, tensor<32xi8>, tensor<?xi8>) -> ()
|
| scf.yield %nr, %ni : tensor<?x?xf64>, tensor<?x?xf64>
|
| }
|
|
|
|
|
| %probs, %log_probs, %sig_r, %sig_i, %hm, %sm, %pm, %ent =
|
| func.call @jst_measurement_head_fused(%rho_cur_r, %rho_cur_i,
|
| %q_set_real, %q_set_imag, %frame_real, %frame_imag, %sk, %pk)
|
| : (tensor<?x?xf64>, tensor<?x?xf64>, tensor<?x?x?xf64>, tensor<?x?x?xf64>,
|
| tensor<?x?x?xf64>, tensor<?x?x?xf64>, tensor<32xi8>, tensor<32xi8>)
|
| -> (tensor<?xf64>, tensor<?xf64>, tensor<?x?xf64>, tensor<?x?xf64>,
|
| tensor<32xi8>, tensor<64xi8>, i1, f64)
|
|
|
| %evf, %_2 = func.call @sov_spe_decode_frame(%sig_r, %sig_i, %frame_real, %frame_imag)
|
| : (tensor<?x?xf64>, tensor<?x?xf64>, tensor<?x?x?xf64>, tensor<?x?x?xf64>) -> (tensor<?xf64>, tensor<?x?xf64>)
|
| func.call @jst_boolean_lens_fused(%evf, %hm, %lisp_buffer) : (tensor<?xf64>, tensor<32xi8>, tensor<?xi8>) -> ()
|
|
|
| %final_plasma = arith.andi %p0, %pm : i1
|
|
|
| return %sig_r, %sig_i, %probs, %log_probs, %ent, %final_plasma
|
| : tensor<?x?xf64>, tensor<?x?xf64>, tensor<?xf64>, tensor<?xf64>, f64, i1
|
| }
|
|
|
| }
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|