@@ -6,6 +6,7 @@ using ..SuiteSparseGraphBLAS: isGxB, isGrB, GBType,
66    GBArrayOrTranspose, AbstractTypedOp, @wraperror , load_global, OperatorCompiler, gbset!, irscratch
77using  .. LibGraphBLAS
88using  GPUCompiler
9+ import  LLVM
910export  unaryop, @unop 
1011
1112export  rowindex, colindex, frexpx, frexpe
@@ -79,21 +80,17 @@ const COMPILEDUNARYOPS = Dict()
7980const  BUILTINUNARYOPS =  Dict {<:Any, <:Any} () #  (f) -> name, inputtypes
8081
8182function  linker (job, compiled)
82-     ir =  compiled
83+     ir, meta  =  compiled
8384    (; fn, c_fn, intypes) =  job. config. params
8485    write (joinpath (irscratch, " $(hash (ir)) .o" 
8586    return  TypedUnaryOperator {typeof(fn), eltype(intypes[2]), eltype(intypes[1])} (
86-         false , false , job . config . name, LibGraphBLAS. GrB_UnaryOp (), fn, c_fn; docompilation =  true , ir =  joinpath (irscratch, " $(hash (ir)) .o" 
87+         false , false , LLVM . name (meta[ :entry ]) , LibGraphBLAS. GrB_UnaryOp (), fn, c_fn; docompilation =  true , ir =  joinpath (irscratch, " $(hash (ir)) .o" 
8788    )
8889end 
8990
90- function  unarycachecompile (f, :: Type{T} ) where  T
91-     function  unaryopfn (z, x)
92-         Base. unsafe_store! (z, f (Base. unsafe_load (x)))
93-         return  nothing 
94-     end 
91+ function  unarycachecompile (f, ptrfunction, :: Type{T} ) where  T
9592    O =  Base. Broadcast. combine_eltypes (f, (T,))
96-     job =  OperatorCompiler. operatorjob (f, unaryopfn , (Ptr{O}, Ptr{T},))
93+     job =  OperatorCompiler. operatorjob (f, ptrfunction , (Ptr{O}, Ptr{T},))
9794    return  GPUCompiler. cached_compilation (
9895        COMPILEDUNARYOPS, job. source, job. config,
9996        OperatorCompiler. compiler, linker
@@ -120,10 +117,17 @@ function unaryop(f, ::Type{T}) where T
120117            return  nothing 
121118        end 
122119    end 
123-     if  maybeop != =   nothing 
120+     if  maybeop isa  TypedUnaryOperator 
124121        return  maybeop
122+     elseif  maybeop ===  nothing 
123+         function  unaryopfn (z, x)
124+             Base. unsafe_store! (z, f (Base. unsafe_load (x)))
125+             return  nothing 
126+         end 
127+         UNARYOPS[(f, t)] =  unaryopfn
128+         return  unarycachecompile (f, unaryopfn, T)
125129    else 
126-         return  unarycachecompile (f, T)
130+         return  unarycachecompile (f, maybeop,  T)
127131    end 
128132end 
129133
0 commit comments