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

Mysterious Readonlymemory error in simple code #58

Closed jpfairbanks closed 8 years ago

jpfairbanks commented 8 years ago

I wrote a simple benchmark Matvec in order to get some experience and was surprised to see this code fail.

The following code causes a segfault for me

module MatVec
using ParallelAccelerator

@noinline function matvec!(y::Vector, A::Matrix, b::Vector)
    @inbounds for i in 1:length(b)
        for j in 1:length(y)
            y[j] += A[j,i]*b[i]
        end
    end
end
@acc function parmatvec!(y::AbstractVector, A::AbstractMatrix, b::AbstractVector)
    for i in 1:length(b)
        #= for j in 1:length(y) =#
        #=     y[j] += A[j,i]*b[i] =#
        #= end =#
        y += sum(A[:,i].*b[i])
    end
end

function main(n::Int)
    b = randn(n)
    y = zeros(n)
    A = rand(n,n)
    z = A*b
    info("Serial: $n")
    @time matvec!(y,A,b)
    info("Parallel: $n")
    @time parmatvec!(y,A,b)
end
info("Compilling")
main(10)

end

for n in [4,8,16,32,65,128,256,512, 1024, 2048, 4096]
    MatVec.main(n)
end

The output of this code is:

for n in [4,8,16,32,65,128,256,512, 1024, 2048, 4096]
           MatVec.main(n)
       end
INFO: Serial: 4
  0.000000 seconds
INFO: Parallel: 4
  0.000399 seconds (40 allocations: 1.750 KB)
INFO: Serial: 8
  0.000000 seconds
INFO: Parallel: 8
  0.000066 seconds (40 allocations: 1.750 KB)
INFO: Serial: 16
  0.000000 seconds
INFO: Parallel: 16
  0.000030 seconds (40 allocations: 1.750 KB)
INFO: Serial: 32
  0.000001 seconds
INFO: Parallel: 32
  0.000949 seconds (40 allocations: 1.750 KB)
INFO: Serial: 65
  0.000004 seconds
INFO: Parallel: 65
  0.000075 seconds (40 allocations: 1.750 KB)
INFO: Serial: 128
  0.000014 seconds
INFO: Parallel: 128
  0.008083 seconds (40 allocations: 1.750 KB)
INFO: Serial: 256
  0.000116 seconds
INFO: Parallel: 256
  0.008073 seconds (40 allocations: 1.750 KB)
INFO: Serial: 512
  0.000196 seconds
INFO: Parallel: 512
  0.054306 seconds (40 allocations: 1.750 KB)
INFO: Serial: 1024
  0.000885 seconds
INFO: Parallel: 1024
ERROR: ReadOnlyMemoryError()

I am surprised that it doesn't fail until the input is 1024x1024.

ninegua commented 8 years ago

@jpfairbanks Thanks for the report. Can you provide some information on your platform, Julia version and C compiler version? I can't seem to re-produce this bug on my machine.

jpfairbanks commented 8 years ago

Ubuntu 14.04 with Julia 0.4.0. I just updated to v0.4.2 from the ppa and I sill get the same error.

julia> versioninfo() Julia Version 0.4.2 Commit bb73f34* (2015-12-06 21:47 UTC) Platform Info: System: Linux (x86_64-linux-gnu) CPU: Intel(R) Core(TM) i7-2600 CPU @ 3.40GHz WORD_SIZE: 64 BLAS: libopenblas (USE64BITINT DYNAMIC_ARCH NOAFFINITY Sandybridge) LAPACK: libopenblas64 LIBM: libopenlibm LLVM: libLLVM-3.3

gcc (Ubuntu 4.8.4-2ubuntu1~14.04.1) 4.8.4

ehsantn commented 8 years ago

Could you switch to master branch and see if it works? http://parallelacceleratorjl.readthedocs.org/en/latest/install.html

We should get used to tagging new versions frequently!

jpfairbanks commented 8 years ago

Now it works, thanks for getting back to me.