{"action":"created","issue":{"url":"https://api.github.com/repos/gpu/JOCL/issues/12","repository_url":"https://api.github.com/repos/gpu/JOCL","labels_url":"https://api.github.com/repos/gpu/JOCL/issues/12/labels{/name}","comments_url":"https://api.github.com/repos/gpu/JOCL/issues/12/comments","events_url":"https://api.github.com/repos/gpu/JOCL/issues/12/events","html_url":"https://github.com/gpu/JOCL/issues/12","id":190136760,"number":12,"title":"Non deterministic segfault with Intel CPU","user":{"login":"TPolzer","id":6651466,"avatar_url":"https://avatars.githubusercontent.com/u/6651466?v=3","gravatar_id":"","url":"https://api.github.com/users/TPolzer","html_url":"https://github.com/TPolzer","followers_url":"https://api.github.com/users/TPolzer/followers","following_url":"https://api.github.com/users/TPolzer/following{/other_user}","gists_url":"https://api.github.com/users/TPolzer/gists{/gist_id}","starred_url":"https://api.github.com/users/TPolzer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TPolzer/subscriptions","organizations_url":"https://api.github.com/users/TPolzer/orgs","repos_url":"https://api.github.com/users/TPolzer/repos","events_url":"https://api.github.com/users/TPolzer/events{/privacy}","received_events_url":"https://api.github.com/users/TPolzer/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":6,"created_at":"2016-11-17T19:13:48Z","updated_at":"2016-11-21T14:52:10Z","closed_at":null,"body":"I have some scala code that puts the contents of an iterator into OpenCL device memory. If I do this in parallel on the Intel CPU OpenCL implementation it segfaults most of the time. I have reduced it down to the following code:\r\n```scala\r\nimport org.jocl.CL._\r\nimport org.jocl._\r\nimport java.nio.ByteOrder\r\nimport java.nio.ByteBuffer\r\n\r\nobject OpenCL\r\n{\r\n  setExceptionsEnabled(true)\r\n  val deviceType = CL_DEVICE_TYPE_CPU\r\n  val devices = {\r\n    val numPlatforms = Array(0)\r\n    clGetPlatformIDs(0, null, numPlatforms)\r\n    val platforms = new Array[cl_platform_id](numPlatforms(0))\r\n    clGetPlatformIDs(platforms.length, platforms, null)\r\n    platforms.flatMap(platform => {\r\n      try {\r\n        val contextProperties = new cl_context_properties\r\n        contextProperties.addProperty(CL_CONTEXT_PLATFORM, platform)\r\n        val numDevices = Array(0)\r\n        clGetDeviceIDs(platform, deviceType, 0, null, numDevices)\r\n        val devices = new Array[cl_device_id](numDevices(0))\r\n        clGetDeviceIDs(platform, deviceType, numDevices(0), devices, null)\r\n        devices.flatMap(device => {\r\n          try{\r\n            val vendorIdBuffer = new Array[Byte](1024)\r\n            clGetDeviceInfo(device, CL_DEVICE_VENDOR, 1024, Pointer.to(vendorIdBuffer), null)\r\n            val vendorId = new String(vendorIdBuffer, \"UTF-8\")\r\n            if(!vendorId.matches(\".*Intel.*\")) {\r\n              None\r\n            } else {\r\n              println(vendorId)\r\n              val context = clCreateContext(contextProperties, 1, Array(device), null, null, null)\r\n              val queue = clCreateCommandQueue(context, device, CL_QUEUE_OUT_OF_ORDER_EXEC_MODE_ENABLE | CL_QUEUE_PROFILING_ENABLE, null)\r\n              Some(new OpenCLSession(context, queue, device))\r\n            }\r\n          } catch {\r\n            case e: CLException => None\r\n          }\r\n        })\r\n      } catch {\r\n        case e: CLException => Nil\r\n      }\r\n    })\r\n  }\r\n  def main(args: Array[String]) : Unit = println((0 to 30).par.map(x => OpenCL.devices(0).stream((0 to 1024*1024*256).iterator.map(_.toDouble),1024*1024*256)))\r\n}\r\n\r\nclass OpenCLSession (val context: cl_context, val queue: cl_command_queue, val device: cl_device_id)\r\n{\r\n  def stream(it: Iterator[Double], groupSize: Int = 1024*1024*256) : cl_mem = {\r\n    var on_host : Option[cl_mem] = None\r\n    try {\r\n      on_host = Some(clCreateBuffer(context, CL_MEM_ALLOC_HOST_PTR, groupSize, null, null))\r\n      val rawBuffer = clEnqueueMapBuffer(queue, on_host.get, true, CL_MAP_WRITE, 0, groupSize, 0, null, null, null)\r\n      val buffer = rawBuffer.order(ByteOrder.nativeOrder).asDoubleBuffer\r\n      var copied = 0\r\n      while(copied < groupSize/Sizeof.cl_double && it.hasNext) {\r\n        buffer.put(copied, it.next)\r\n        copied += 1\r\n      }\r\n      clEnqueueUnmapMemObject(queue, on_host.get, rawBuffer, 0, null, null)\r\n      clRetainMemObject(on_host.get)\r\n      on_host.get\r\n      } finally {\r\n        on_host.foreach(clReleaseMemObject)\r\n      }\r\n  }\r\n\r\n  override def finalize = {\r\n    clReleaseCommandQueue(queue)\r\n    clReleaseContext(context)\r\n  }\r\n}\r\n```\r\nI suspect it is some unfortunate interference between the jvm and the Intel OpenCL implementation. I would be glad for some expert judgment on this."},"comment":{"url":"https://api.github.com/repos/gpu/JOCL/issues/comments/261958735","html_url":"https://github.com/gpu/JOCL/issues/12#issuecomment-261958735","issue_url":"https://api.github.com/repos/gpu/JOCL/issues/12","id":261958735,"user":{"login":"TPolzer","id":6651466,"avatar_url":"https://avatars.githubusercontent.com/u/6651466?v=3","gravatar_id":"","url":"https://api.github.com/users/TPolzer","html_url":"https://github.com/TPolzer","followers_url":"https://api.github.com/users/TPolzer/followers","following_url":"https://api.github.com/users/TPolzer/following{/other_user}","gists_url":"https://api.github.com/users/TPolzer/gists{/gist_id}","starred_url":"https://api.github.com/users/TPolzer/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/TPolzer/subscriptions","organizations_url":"https://api.github.com/users/TPolzer/orgs","repos_url":"https://api.github.com/users/TPolzer/repos","events_url":"https://api.github.com/users/TPolzer/events{/privacy}","received_events_url":"https://api.github.com/users/TPolzer/received_events","type":"User","site_admin":false},"created_at":"2016-11-21T14:52:10Z","updated_at":"2016-11-21T14:52:10Z","body":"I have tested this on several OpenCL implementations, and the Intel CPU one is the only crashing one. I have only observed it under parallel execution (the more threads, the more likely it crashes).\r\n\r\nWhen it crashes, it produces no hs_err file. The coredump file (not sure if that helps) is huge."}}
{"actor":{"display_login":"TPolzer"}}