cuTENSOR uses a two-step process for execution: first, you define a plan preference, and then you create an execution plan based on that preference and the required workspace size.
- Plan Preference: Use
create_plan_preference to specify algorithm preferences and JIT modes. - Workspace Estimation: Use
estimate_workspace_size to determine how much memory is needed for the operation. - Execution Plan: Use
create_plan to generate the actual plan used for execution.
Safety Requirements:
- All handles and descriptors must be valid.
plan must not have been freed already when calling destroy_plan.
// 1. Create preference
let pref = unsafe {
create_plan_preference(handle, algo, jit_mode).expect("Failed to create preference")
};
// 2. Estimate workspace
let workspace_size = unsafe {
estimate_workspace_size(handle, op_desc, pref, workspace_pref).expect("Failed to estimate workspace")
};
// 3. Create plan
let plan = unsafe {
create_plan(handle, op_desc, pref, workspace_size).expect("Failed to create plan")
};
// ... execute ...
// Cleanup
unsafe {
destroy_plan(plan).expect("Failed to destroy plan");
destroy_plan_preference(pref).expect("Failed to destroy preference");
}