@@ -92,21 +92,17 @@ GrB_Info GB_colscale // C = A*D, column scale with diagonal D
9292 GB_void cscalar [GB_VLA (zsize )] ;
9393 bool C_iso = GB_AxB_iso (cscalar , A , D , A -> vdim , semiring , flipxy , true) ;
9494
95- //--------------------------------------------------------------------------
96- // copy the pattern of A into C
97- //--------------------------------------------------------------------------
98-
99- // allocate C->x but do not initialize it
100- GB_OK (GB_dup_worker (& C , C_iso , A , false, ztype )) ;
10195 info = GrB_NO_VALUE ;
102- ASSERT (C -> type == ztype ) ;
10396
10497 //--------------------------------------------------------------------------
10598 // C = A*D, column scale, compute numerical values
10699 //--------------------------------------------------------------------------
107100
108101 if (GB_IS_BUILTIN_BINOP_CODE_POSITIONAL (opcode ))
109- {
102+ {
103+ // Copy the pattern of A into C. Allocates, but does not initialize C->x.
104+ GB_OK (GB_dup_worker (& C , C_iso , A , false, ztype )) ;
105+ ASSERT (C -> type == ztype ) ;
110106
111107 //----------------------------------------------------------------------
112108 // apply a positional operator: convert C=A*D to C=op(A)
@@ -157,7 +153,10 @@ GrB_Info GB_colscale // C = A*D, column scale with diagonal D
157153
158154 }
159155 else if (C_iso )
160- {
156+ {
157+ // Copy the pattern of A into C. Allocates, but does not initialize C->x.
158+ GB_OK (GB_dup_worker (& C , C_iso , A , false, ztype )) ;
159+ ASSERT (C -> type == ztype ) ;
161160
162161 //----------------------------------------------------------------------
163162 // via the iso kernel
@@ -179,6 +178,17 @@ GrB_Info GB_colscale // C = A*D, column scale with diagonal D
179178 // determine if the values are accessed
180179 //----------------------------------------------------------------------
181180
181+ // Do not dup A->p, A->h into C yet; if we use CUDA, we'll do it on the
182+ // GPU
183+ int64_t * tmp_Ap = A -> p ;
184+ int64_t * tmp_Ah = A -> h ;
185+ A -> p = NULL ;
186+ A -> h = NULL ;
187+ GB_OK (GB_dup_worker (& C , C_iso , A , false, ztype )) ;
188+ A -> p = tmp_Ap ;
189+ A -> h = tmp_Ah ;
190+ ASSERT (C -> type == ztype ) ;
191+
182192 ASSERT (fmult != NULL ) ;
183193 bool op_is_first = (opcode == GB_FIRST_binop_code ) ;
184194 bool op_is_second = (opcode == GB_SECOND_binop_code ) ;
@@ -217,6 +227,26 @@ GrB_Info GB_colscale // C = A*D, column scale with diagonal D
217227 }
218228 #endif
219229
230+ // We are using the CPU. Finish the dup from A -> C.
231+ if (info == GrB_NO_VALUE )
232+ {
233+ // copy A->p, A->h into C->p, C->h
234+ size_t psize = A -> p_is_32 ?
235+ sizeof (uint32_t ) : sizeof (uint64_t ) ;
236+ size_t isize = A -> i_is_32 ?
237+ sizeof (uint32_t ) : sizeof (uint64_t ) ;
238+ int64_t anvec = A -> nvec ;
239+ int nthreads_max = GB_Context_nthreads_max ( ) ;
240+
241+ if (A -> p != NULL )
242+ {
243+ GB_memcpy (C -> p , A -> p , (anvec + 1 ) * psize , nthreads_max ) ;
244+ }
245+ if (A -> h != NULL )
246+ {
247+ GB_memcpy (C -> h , A -> h , anvec * isize , nthreads_max ) ;
248+ }
249+ }
220250 //----------------------------------------------------------------------
221251 // determine the number of threads to use
222252 //----------------------------------------------------------------------
0 commit comments