From cc01384da2cda1cb95e3ebe6f0c93aac01bba644 Mon Sep 17 00:00:00 2001
From: Mathieu Faverge <mathieu.faverge@inria.fr>
Date: Mon, 17 Feb 2025 14:05:29 +0100
Subject: [PATCH] starpu/codelet: Add new task submit to codelet_zlascal.c

---
 runtime/starpu/codelets/codelet_zlascal.c | 88 +++++++++++++++++++++--
 1 file changed, 82 insertions(+), 6 deletions(-)

diff --git a/runtime/starpu/codelets/codelet_zlascal.c b/runtime/starpu/codelets/codelet_zlascal.c
index 35fb10c35..c984f574d 100644
--- a/runtime/starpu/codelets/codelet_zlascal.c
+++ b/runtime/starpu/codelets/codelet_zlascal.c
@@ -25,9 +25,9 @@
 #include "runtime_codelet_z.h"
 
 struct cl_zlascal_args_s {
-    cham_uplo_t uplo;
-    int m;
-    int n;
+    cham_uplo_t           uplo;
+    int                   m;
+    int                   n;
     CHAMELEON_Complex64_t alpha;
 };
 
@@ -49,6 +49,7 @@ cl_zlascal_cpu_func( void *descr[], void *cl_arg )
  */
 CODELETS_CPU( zlascal, cl_zlascal_cpu_func )
 
+#if defined(CHAMELEON_STARPU_USE_INSERT)
 void INSERT_TASK_zlascal( const RUNTIME_option_t *options,
                           cham_uplo_t uplo,
                           int m, int n, int nb,
@@ -64,10 +65,10 @@ void INSERT_TASK_zlascal( const RUNTIME_option_t *options,
         return;
     }
 
-    struct cl_zlascal_args_s *clargs = NULL;
     void (*callback)(void*);
-    int                      exec = 0;
-    const char              *cl_name = "zlascal";
+    struct cl_zlascal_args_s *clargs  = NULL;
+    int                       exec    = 0;
+    const char               *cl_name = "zlascal";
 
     /* Handle cache */
     CHAMELEON_BEGIN_ACCESS_DECLARATION;
@@ -102,3 +103,78 @@ void INSERT_TASK_zlascal( const RUNTIME_option_t *options,
 
     (void)nb;
 }
+
+#else
+
+void INSERT_TASK_zlascal( const RUNTIME_option_t *options,
+                          cham_uplo_t uplo,
+                          int m, int n, int nb,
+                          CHAMELEON_Complex64_t alpha,
+                          const CHAM_desc_t *A, int Am, int An )
+{
+    if ( alpha == 0. ) {
+        INSERT_TASK_zlaset( options, uplo, m, n,
+                            alpha, alpha, A, Am, An );
+        return;
+    }
+    else if ( alpha == 1. ) {
+        return;
+    }
+
+    INSERT_TASK_COMMON_PARAMETERS( zlascal, 1 );
+
+    /*
+     * Set the data handles and initialize exchanges if needed
+     */
+    starpu_cham_exchange_init_params( options, &params, A->get_rankof( A, Am, An ) );
+    starpu_cham_exchange_data_before_execution( options, params, &nbdata, descrs, A, Am, An, STARPU_RW );
+
+    /*
+     * Not involved, let's return
+     */
+    if ( nbdata == 0 ) {
+        return;
+    }
+
+    if ( params.do_execute )
+    {
+        int ret;
+        struct starpu_task *task = starpu_task_create();
+        task->cl = cl;
+
+        /* Set codelet parameters */
+        clargs = malloc( sizeof( struct cl_zlascal_args_s ) );
+        clargs->uplo  = uplo;
+        clargs->m     = m;
+        clargs->n     = n;
+        clargs->alpha = alpha;
+
+        task->cl_arg      = clargs;
+        task->cl_arg_size = sizeof( struct cl_zlascal_args_s );
+        task->cl_arg_free = 1;
+
+        /* Set common parameters */
+        starpu_cham_task_set_options( options, task, nbdata, descrs, cl_zlascal_callback );
+
+        /* Flops */
+        //task->flops = flops_zlascal( uplo, m, n );
+
+        /* Refine name */
+        task->name = chameleon_codelet_name( cl_name, 1,
+                                             A->get_blktile( A, Am, An ) );
+
+        ret = starpu_task_submit( task );
+        if ( ret == -ENODEV ) {
+            task->destroy = 0;
+            starpu_task_destroy( task );
+            chameleon_error( "INSERT_TASK_zlascal", "Failed to submit the task to StarPU" );
+            return;
+        }
+    }
+
+    starpu_cham_task_exchange_data_after_execution( options, params, nbdata, descrs );
+
+    (void)nb;
+}
+
+#endif
-- 
GitLab