Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #14990 > unrolled thread

memory leak with Cuda

Started bygebe13@neuf.fr
First post2013-06-24 07:52 +0000
Last post2014-04-26 06:07 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica


Contents

  memory leak with Cuda gebe13@neuf.fr - 2013-06-24 07:52 +0000
    Re: memory leak with Cuda gustavo.carri@gmail.com - 2014-04-26 06:07 +0000

#14990 — memory leak with Cuda

Fromgebe13@neuf.fr
Date2013-06-24 07:52 +0000
Subjectmemory leak with Cuda
Message-ID<kq8tra$8oo$1@smc.vnet.net>
Here is an application of Wolfram white paper (Heterogeneous Computing in Mathematica page 16 and 17). After several cursor movement program stops because of a memory leak. How to fix it please?

Julia set with CUDA

Needs["CUDALink`"]

code = "
  __global__ void julia_kernel(Real_t * set, int width, int height, Real_t \
cx, Real_t cy) {
  	int xIndex = threadIdx.x + blockIdx.x*blockDim.x;
  	int yIndex = threadIdx.y + blockIdx.y*blockDim.y;
  	int ii;
  	Real_t x = ZOOM_LEVEL*(width/2 - xIndex);
  	Real_t y = ZOOM_LEVEL*(height/2 - yIndex);
  	Real_t tmp;
  	Real_t c;
  	if (xIndex < width && yIndex < height) {
  		for (ii = 0; ii < MAX_ITERATIONS && x*x + y*y < BAILOUT; ii++) {
  			tmp = x*x - y*y + cx;
  			y = 2*x*y + cy;
  			x = tmp;
  		}
  		c = log(0.1f + sqrt(x*x + y*y));
  		set[xIndex + yIndex*width] = c;
  	}
  }";

JuliaCalculate = 
  CUDAFunctionLoad[code, 
   "julia_kernel", {{_Real, "Output"}, _Integer, _Integer, _Real, _Real}, {16,
     16}, "Defines" -> {"MAX_ITERATIONS" -> 10, "ZOOM_LEVEL" -> "0.0050", 
     "BAILOUT" -> "4.0"}];

{width, height} = {512, 512};
jset = CUDAMemoryAllocate[Real, {height, width}];

Manipulate[
 JuliaCalculate[jset, width, height, c[[1]], c[[2]], {width, height}];
 ReliefPlot[Reverse@CUDAMemoryGet[jset], ColorFunction -> "Rainbow", 
  DataRange -> {{-2.0, 2.0}, {-2.0, 2.0}}, ImageSize -> 512, Frame -> None, 
  Epilog -> {Opacity[.5], Dashed, Thick, 
    Line[{{{c[[1]], -2}, {c[[1]], 2}}, {{-2, c[[2]]}, {2, 
        c[[2]]}}}]}], {{c, {0, 1}}, {-2, -2}, {2, 2}, Locator, 
  Appearance -> 
   Graphics[{Thick, Dashed, Opacity[.75], Circle[]}, ImageSize -> 50]}]


General::nomem: The current computation was aborted because there was insufficient memory available to complete the computation.

[toc] | [next] | [standalone]


#16854

Fromgustavo.carri@gmail.com
Date2014-04-26 06:07 +0000
Message-ID<ljfifv$gur$1@smc.vnet.net>
In reply to#14990
On Monday, June 24, 2013 3:52:10 AM UTC-4, geb...@neuf.fr wrote:
> Here is an application of Wolfram white paper (Heterogeneous Computing in Mathematica page 16 and 17). After several cursor movement program stops because of a memory leak. How to fix it please?
> 
> 
> 
> Julia set with CUDA
> 
> 
> 
> Needs["CUDALink`"]
> 
> 
> 
> code = "
> 
>   __global__ void julia_kernel(Real_t * set, int width, int height, Real_t \
> 
> cx, Real_t cy) {
> 
>   	int xIndex = threadIdx.x + blockIdx.x*blockDim.x;
> 
>   	int yIndex = threadIdx.y + blockIdx.y*blockDim.y;
> 
>   	int ii;
> 
>   	Real_t x = ZOOM_LEVEL*(width/2 - xIndex);
> 
>   	Real_t y = ZOOM_LEVEL*(height/2 - yIndex);
> 
>   	Real_t tmp;
> 
>   	Real_t c;
> 
>   	if (xIndex < width && yIndex < height) {
> 
>   		for (ii = 0; ii < MAX_ITERATIONS && x*x + y*y < BAILOUT; ii++) {
> 
>   			tmp = x*x - y*y + cx;
> 
>   			y = 2*x*y + cy;
> 
>   			x = tmp;
> 
>   		}
> 
>   		c = log(0.1f + sqrt(x*x + y*y));
> 
>   		set[xIndex + yIndex*width] = c;
> 
>   	}
> 
>   }";
> 
> 
> 
> JuliaCalculate = 
> 
>   CUDAFunctionLoad[code, 
> 
>    "julia_kernel", {{_Real, "Output"}, _Integer, _Integer, _Real, _Real}, {16,
> 
>      16}, "Defines" -> {"MAX_ITERATIONS" -> 10, "ZOOM_LEVEL" -> "0.0050", 
> 
>      "BAILOUT" -> "4.0"}];
> 
> 
> 
> {width, height} = {512, 512};
> 
> jset = CUDAMemoryAllocate[Real, {height, width}];
> 
> 
> 
> Manipulate[
> 
>  JuliaCalculate[jset, width, height, c[[1]], c[[2]], {width, height}];
> 
>  ReliefPlot[Reverse@CUDAMemoryGet[jset], ColorFunction -> "Rainbow", 
> 
>   DataRange -> {{-2.0, 2.0}, {-2.0, 2.0}}, ImageSize -> 512, Frame -> None, 
> 
>   Epilog -> {Opacity[.5], Dashed, Thick, 
> 
>     Line[{{{c[[1]], -2}, {c[[1]], 2}}, {{-2, c[[2]]}, {2, 
> 
>         c[[2]]}}}]}], {{c, {0, 1}}, {-2, -2}, {2, 2}, Locator, 
> 
>   Appearance -> 
> 
>    Graphics[{Thick, Dashed, Opacity[.75], Circle[]}, ImageSize -> 50]}]
> 
> 
> 
> 
> 
> General::nomem: The current computation was aborted because there was insufficient memory available to complete the computation.

I have the same problem. Did you figure this out?

Gus

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web