tari

Untitled

Jul 26th, 2010
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. //Creating map in host code pre-kernel:
  2. cl_int status;
  3. cl_image_format map_form = {CL_LUMINANCE, CL_UNORM_INT8};
  4. clCreateImage2D(context, CL_MEM_WRITE_ONLY, map_form,
  5. width, height, 0, NULL, &status);
  6.  
  7.  
  8. //Doing one worker per 4-pixel block so we can vectorize the transformations,
  9. //meaning dimensions of map must be divisible by 4. Kernel is dispatched in
  10. //two dimensions.
  11. __kernel __attribute__((vec_type_hint(float4)))
  12. void genMap( __global float min,
  13. __global float max,
  14. __global float *heights,
  15. __global image2d_t map) {
  16. //Worker ID on X and Y
  17. int x = get_global_id(0);
  18. int y = get_global_id(1);
  19. //Job size in X and Y
  20. int xs = get_global_size(0);
  21. //int ys = get_global_size(1); //Not needed
  22.  
  23. //TBD: is there any performance benefit to this explicit vectorization?
  24. //..maybe the compiler will know better what benefits it.
  25. float4 norm = vload4(&heights[y*xs + x];
  26. //Convert so 0 <= norm <= 1, treat it like luminance
  27. norm -= (float4)min;
  28. norm /= (float4)(max - min);
  29.  
  30. write_imagef(map, (int2)(x+0,y), norm.x);
  31. write_imagef(map, (int2)(x+1,y), norm.y);
  32. write_imagef(map, (int2)(x+2,y), norm.z);
  33. write_imagef(map, (int2)(x+3,y), norm.w);
  34. }
Add Comment
Please, Sign In to add comment