cpu_cuda_mandelbrot.jl 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. include("../../src/Compiler/include.jl")
  2. starpu_new_cpu_kernel_file("../build/generated_cpu_mandelbrot.c")
  3. starpu_new_cuda_kernel_file("../build/generated_cuda_mandelbrot.cu")
  4. @cpu_cuda_kernel function mandelbrot(pixels ::Matrix{Int64}, params ::Vector{Float64}, slice_pos ::Vector{Int64}) :: Void
  5. local_width ::Int64 = width(pixels)
  6. local_height ::Int64 = height(pixels)
  7. #max_iterations ::Int64 = 250
  8. conv_limit ::Float64 = 2.0
  9. @indep for x in (1 : local_width)
  10. @indep for y in (1 : local_height)
  11. max_iterations ::Float64 = params[5]
  12. zoom ::Float64 = params[3] * 0.25296875
  13. X ::Int64 = x + local_width * (slice_pos[1] - 1)
  14. Y ::Int64 = y + local_height * (slice_pos[2] - 1)
  15. cr ::Float64 = params[1] + (X - params[3]/2)/zoom
  16. zr ::Float64 = cr
  17. ci ::Float64 = params[2] + (Y - params[4]/2)/zoom
  18. zi ::Float64 = ci
  19. n ::Int64 = 0
  20. b1 ::Int64 = (n < max_iterations) + (zr*zr + zi*zi < conv_limit * conv_limit)
  21. while (b1 >= 2)#n <= max_iterations) && (z * z < conv_limit * conv_limit) #Double condition impossible!!!
  22. tmp ::Float64 = zr*zr - zi*zi + cr
  23. zi = 2*zr*zi + ci
  24. zr = tmp
  25. n = n + 1
  26. b1 = (n <= max_iterations) + (zr*zr + zi*zi <= conv_limit * conv_limit)
  27. end
  28. if (n < max_iterations)
  29. pixels[y,x] = 255 * n / max_iterations
  30. else
  31. pixels[y,x] = 0
  32. end
  33. end
  34. end
  35. end
  36. compile_cpu_kernels("../build/generated_cpu_mandelbrot.so")
  37. compile_cuda_kernels("../build/generated_cuda_mandelbrot.so")
  38. combine_kernel_files("../build/generated_tasks_mandelbrot.so", ["../build/generated_cpu_mandelbrot.so","../build/generated_cuda_mandelbrot.so"])