IntelLabs / ParallelAccelerator.jl

The ParallelAccelerator package, part of the High Performance Scripting project at Intel Labs
BSD 2-Clause "Simplified" License
294 stars 32 forks source link

bool to int conversion is not supported in j2c_array #113

Closed Wajihulhassan closed 8 years ago

Wajihulhassan commented 8 years ago

In my julia code, I have convert(Vector{Int64},(array1 .== var_tmp)). For expression (array1 .== var_tmp), it generates the following mmap

GenSym(154) = $(Expr(:mmap, Any[:(array1::Array{Int64,1})], [:x]" -> ""["(:x,:x,Int64)(:y,:y,Int64)(GenSym(0),GenSym(0),Bool)";"var_tmp",""]":\
(begin  # promotion.jl, line 225:
        GenSym(0) = x::Int64 === var_tmp::Int64::Bool
        (GenSym(0),)::Bool
    end::Bool)))

and for conversion part it generates

(Base.convert(Array{Int64,1},GenSym(154))::Array{Int64,1}

This Base.convert call is not handled in CGen as compiler throws following error while typecasting.

/home/whassan/.julia/v0.4/ParallelAccelerator/src/../deps/generated/cgen_output0.cpp(2100): error: no suitable user-defined conversion from "j2c_array<bool>" to "j2c_array<int64_t={lon\
g}>" exists
      GenSym19 = ( j2c_array< int64_t > )(GenSym17);

While GenSym17 is a bool j2c_array and GenSym19 is int64 j2c_array.

Thanks

ninegua commented 8 years ago

In general, we do not support convert call when compiling to C. Its semantics is complex, and Julia 0.4 also has difficulty inferring its return type.

We can write the same thing as 1 .* (array1 .== var_tmp), or (array1 .== var_tmp) .* 1. Both works in Julia 0.5 rc. However, the latter was failing in Julia 0.4 due to some inference issue, and is now fixed by CompilerTools commit e294daef.