use gategen::boolvar::*;
use gategen::gatesim::*;
use gategen::intvar::*;
use gatenative::{opencl_build_exec::*, *};
use opencl3::device::{get_all_devices, Device, CL_DEVICE_TYPE_GPU};
fn mul_add_circuit() -> Circuit<u32> {
call32(|| {
let a = U16Var32::var();
let b = U16Var32::var();
let c = U16Var32::var();
let r = &a * &b + &c;
r.to_translated_circuit(a.concat(b).concat(c).iter())
})
}
fn main() -> Result<(), Box<dyn std::error::Error>> {
let device = Device::new(
*get_all_devices(CL_DEVICE_TYPE_GPU)?
.get(0)
.expect("No OpenCL devices"),
);
let b_start = 4782u16;
let c_start = 18941u16;
let circuit = mul_add_circuit();
let mut builder = OpenCLBuilder::new(&device, None);
builder.transform_helpers();
builder.add_with_config(
"mul_add",
circuit,
CodeConfig::new()
.arg_inputs(Some(&(16..48).collect::<Vec<_>>()))
.elem_inputs(Some(&(0..16).collect::<Vec<_>>()))
.aggr_output_len(Some(1 << 16))
.aggr_output_code(Some(
r##"{
global uint* output_u32 = (global uint*)output;
OUTPUT_TRANSFORM_B16(output_u32 + TYPE_LEN*idx, o0, o1, o2, o3, o4, o5, o6, o7,
o8, o9, o10, o11, o12, o13, o14, o15);
}"##,
)),
);
let mut execs = builder.build()?;
let input = execs[0].new_data(16);
let output = execs[0].execute(&input, ((c_start as u64) << 16) | (b_start as u64))?;
let output = output.release();
for (i, v) in output.into_iter().enumerate() {
println!("{}: {}", i, v);
}
Ok(())
}