cpu_cuda_mandelbrot.jl 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. # StarPU --- Runtime system for heterogeneous multicore architectures.
  2. #
  3. # Copyright (C) 2020 Université de Bordeaux, CNRS (LaBRI UMR 5800), Inria
  4. #
  5. # StarPU is free software; you can redistribute it and/or modify
  6. # it under the terms of the GNU Lesser General Public License as published by
  7. # the Free Software Foundation; either version 2.1 of the License, or (at
  8. # your option) any later version.
  9. #
  10. # StarPU is distributed in the hope that it will be useful, but
  11. # WITHOUT ANY WARRANTY; without even the implied warranty of
  12. # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  13. #
  14. # See the GNU Lesser General Public License in COPYING.LGPL for more details.
  15. #
  16. include("../../src/Compiler/include.jl")
  17. starpu_new_cpu_kernel_file("../build/generated_cpu_mandelbrot.c")
  18. starpu_new_cuda_kernel_file("../build/generated_cuda_mandelbrot.cu")
  19. @cpu_cuda_kernel function mandelbrot(pixels ::Matrix{Int64}, params ::Vector{Float64}, slice_pos ::Vector{Int64}) :: Void
  20. local_width ::Int64 = width(pixels)
  21. local_height ::Int64 = height(pixels)
  22. #max_iterations ::Int64 = 250
  23. conv_limit ::Float64 = 2.0
  24. @indep for x in (1 : local_width)
  25. @indep for y in (1 : local_height)
  26. max_iterations ::Float64 = params[5]
  27. zoom ::Float64 = params[3] * 0.25296875
  28. X ::Int64 = x + local_width * (slice_pos[1] - 1)
  29. Y ::Int64 = y + local_height * (slice_pos[2] - 1)
  30. cr ::Float64 = params[1] + (X - params[3]/2)/zoom
  31. zr ::Float64 = cr
  32. ci ::Float64 = params[2] + (Y - params[4]/2)/zoom
  33. zi ::Float64 = ci
  34. n ::Int64 = 0
  35. b1 ::Int64 = (n < max_iterations) + (zr*zr + zi*zi < conv_limit * conv_limit)
  36. while (b1 >= 2)#n <= max_iterations) && (z * z < conv_limit * conv_limit) #Double condition impossible!!!
  37. tmp ::Float64 = zr*zr - zi*zi + cr
  38. zi = 2*zr*zi + ci
  39. zr = tmp
  40. n = n + 1
  41. b1 = (n <= max_iterations) + (zr*zr + zi*zi <= conv_limit * conv_limit)
  42. end
  43. if (n < max_iterations)
  44. pixels[y,x] = 255 * n / max_iterations
  45. else
  46. pixels[y,x] = 0
  47. end
  48. end
  49. end
  50. end
  51. compile_cpu_kernels("../build/generated_cpu_mandelbrot.so")
  52. compile_cuda_kernels("../build/generated_cuda_mandelbrot.so")
  53. combine_kernel_files("../build/generated_tasks_mandelbrot.so", ["../build/generated_cpu_mandelbrot.so","../build/generated_cuda_mandelbrot.so"])