简体   繁体   English

Java线程或Cuda线程

[英]Java Threads or Cuda Threads

I'm going to be starting a project using parallel processing, and I am wondering if I will get more optimization from using Java threads or from Cuda programming? 我将使用并行处理开始一个项目,我想知道我是否将从使用Java线程或从Cuda编程中获得更多的优化? Also I'm not an expert with either scheme, which route would have the smaller learning curve? 我也不是这两种方案的专家,哪条路线的学习曲线较小?

The short answer: It depends on the problem you are trying to solve. 简短的答案:这取决于您要解决的问题。

The long answer: 长答案:

There are some very fundamental differences between parallel processing in Java and Cuda. Java和Cuda中的并行处理之间有一些非常根本的区别。 A big difference is how the jobs are packaged up and executed. 最大的区别是作业的打包和执行方式。 In Java, you're going to write a program that loads the data and then you'll use something like an ExecutorService to execute your tasks. 在Java中,您将编写一个程序来加载数据,然后使用ExecutorService之类的东西来执行任务。 In Cuda you will load the data, but then write a piece of code that actually does the execution (in Cuda, this is called a kernel). 在Cuda中,您将加载数据,然后编写一段实际执行代码(在Cuda中,这称为内核)。 Sounds similar, right? 听起来差不多吧? But not really. 但事实并非如此。 There is additional memory overhead involved in Cuda. Cuda涉及其他内存开销。 A GPU has limited memory so your software has to first load the data, then package it up as a part of the kernel then send it over to the GPU which then stores the data and performs the computation. GPU的内存有限,因此您的软件必须先加载数据,然后将其打包为内核的一部分,然后将其发送到GPU,然后再存储数据并执行计算。 Then your application has to retrieve the results. 然后,您的应用程序必须检索结果。 This works really well for some computational problems, but is really inefficient for other computational problems. 这对于某些计算问题确实非常有效,但对于其他计算问题却效率低下。 It all depends on what you are trying to accomplish. 这完全取决于您要完成的工作。

A GPU is useful if you have a simple task you need to perform many times (thousands or more) You can access a GPU using OpenCL. 如果您有一个简单的任务需要执行多次(数千次或更多次),则GPU很有用。您可以使用OpenCL访问GPU。 A Java wrapper for this is http://www.jocl.org/ Others are http://jogamp.org/jocl/www/ and http://code.google.com/p/nativelibs4java/wiki/OpenCL but I haven't tried them. 一个Java包装器是http://www.jocl.org/其他的是http://jogamp.org/jocl/www/http://code.google.com/p/nativelibs4java/wiki/OpenCL,但我还没尝试过

A CPU is much better for general purpose programming. 对于通用编程,CPU要好得多。 You may be surprised how much you can get done in a single thread let alone on a Socket with many cores. 您可能会惊讶于在单个线程中可以完成多少工作,更不用说在具有多个内核的Socket上了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM