New answers tagged

0

Most likely your code has some undefined behavior (as others explained, you are much more likely to have bugs in your code than in the compiler, even if C++ compilers are so complex that they do have bugs; even the C++ specification has design bugs). And UB can be here even if the compiled executable happens to work (by bad luck). So you should read Lattner'...


1

An increasingly common situation is that compilers break code written for dialects of C that supported behaviors not mandated by the Standard, and allowed code targeting those dialects to be more efficient than strictly-conforming code could be. In such a case, it would be unfair to describe as "broken" code which would be 100% reliable on compilers that ...


0

Yes, it's certainly possible. Any computation that a CPU can do, a GPU can also do, and vice versa. But it's uncommon because: Engineering complexity While it is possible to run the same code on a CPU and GPU (e.g. CUDA), the processors have different abilities and performance characteristics. One is MIMD; the other, SIMD. What is fast on one is slow on ...


0

One real world example is the open source LuxRender rendering engine, which is capable of fully loading a CPU and GPU at the same time. In addition, it can load multiple GPUs at the same time and can also distribute across multiple computers. LuxRender uses OpenCL to facilitate this, although builds without OpenCL also exist. This is practical because ...


1

You might be interested in checking out the Servo browser engine being developed at Mozilla Research, and more specifically its Web Render (video). While shifting a task from CPU to GPU dynamically might be impractical, as mentioned in other answers (notably @Philip's), it can be practical to study the load of CPU/GPU on typical workloads in advance and ...


10

From a supercomputing viewpoint it is better not to think in CPU/GPU load in percentage but rather determine how many operations your problem at hand needs and then compare that to the peak performance of the system. If you get 100% CPU utilization it does not necessarily mean that you get all the performance out of the system. CPUs can often do multiple ...


0

With a focus on games (since you mentioned it specifically in your post), there are some ways you can balance the load. One example is "skinning", i.e. animating a model. For each frame to be rendered, you have to generate the transformation matrices for each frame of animation and apply it to the vertices of the model to transform it into the pose it needs ...


56

Theoretically yes, but practically it's rarely worth it. Both CPUs and GPUs are turing-complete, so any algorithm which can be calculated by one can also be calculated by the other. The question is how fast and how convenient. While the GPU excels at doing the same simple calculations on many data-points of a large dataset, the CPU is better at more ...


32

It is not related to game programming. Some scientific code can also use both the GPU and the CPU. With careful -and painful- programming, e.g. by using OpenCL or CUDA, you could load both your GPU and your CPU near 100%. Very probably you'll need to write different pieces of code for the GPU (so called "kernel" code) and for the CPU, and some boring glue ...


3

The compiler operates under the as-if rule that allows any and all code transformations that don't change the observable behavior of the program. [C++14: 1.5/8] The least requirements on a conforming implementation are: Access to volatile objects are evaluated strictly according to the rules of the abstract machine. At program termination, all ...


0

have I just been lucky enough to not to have to worry too much about it, or am I a bad programmer? Do you care about your requirements? If performance isn't a requirement then don't worry about it. Spending any significant time on it is a disservice to your employer. To an extent performance is always a requirement. If you can hit it without thinking ...


-1

Cumulative energy use There's one answer that I always think is missing from these discussion and which bothers me a bit - cumulative energy usage. Sure, maybe it does not matter much if you write your program in a high level interpreted language, and let it run in a browser with a couple of layers of indirection, or if your loop takes 0.01 seconds instead ...


4

Yes, though, not necessarily in the manners you've described. But, there's at least 1 very specific case wherein Google's Closure Compiler optimizes for gzip: Closure Compiler can even tell when two different variables are never used at the same time, letting both share the same name and ensuring that as many variables as possible use very short ...


5

These are both highly unlikely, and I would actively avoid any optimiser which did make these transformations because I would suspect that it might have subtle bugs. Case1: There are two snippets of code that are very similar and very gzip-able, one at the start of the document and the other is beyond 32kb at the end of the document. Does the minifier ...


-1

Minifiers reduce the amount of disk space taken up by a file while preserving it's functionality. They typically do so by deleting technically unnecessary white-spaces, indents, new lines and comments. Then they'll reduce variable names down to letters function helloWorld() { //helloWorld string would be preserved console.log("...


1

Matrix decomposition is definitely the way to go here. Which decomposition you use will be determined by the structure of the systems you are are trying to solve: solving using Cholesky decomposition requires a square, symmetric, positive definite, matrix. You can solve a general square matrix using LU or QR. LU is typically used because it usually takes ...



Top 50 recent answers are included