Is it possible to perform some computations within the RAM?

前端 未结 2 1872
星月不相逢
星月不相逢 2021-01-20 18:32

Theoretically, is there any way to perform any computations within the RAM, using memory related instructions such as move, clflush or whatever, su

相关标签:
2条回答
  • 2021-01-20 18:50

    No, any computation is done in the CPU (or GPU, or other system devices that can load/store to RAM). Even the Turing-complete mov stuff that @PaulR linked in a comment is just using the CPU's address-generation hardware with data in registers to do calculations.

    The memory still just sees 64B burst-loads and 64B burst-stores when the CPU has cache misses.

    See also What Every Programmer Should Know About Memory for some background on how the DDR protocol works (send address, then transfer a burst of data to/from the RAM)


    Related: is num++ atomic in C, or with x86 inc [mem]?

    lock inc [mem] is actually implemented inside the CPU with a load/modify/store that the CPU makes look atomic to all possible other observers in the system (e.g. other CPU cores, and PCIe devices). But not including stuff like hooking up a logic analyzer to the memory bus, which doesn't respect the cache-coherency protocol that a CPU core uses to hold exclusive rights to a cache line while it's doing the atomic read-modify-write.

    Some people thought that the add is done "inside" the memory chips, but they are mistaken. There is no adder, or even boolean AND/OR/XOR hardware in a DRAM chip (or in the interface chips that connect it to a DDR4 bus); all it can do is load or store from a given address. Any chip that can do more than that is not just DRAM.

    Well obviously there's logic in the memory interface chips, but it isn't hooked up to operate on the data.

    If it did have that, it would be a type of Computational RAM. (Thanks linking that in comments, BTW. Interesting computer-architecture idea. AFAIK, no mainstream CPU or GPUs use C-RAM, though.)

    You can't even ask DDR4 DRAM to zero a page for you. The CPU has to do that through the memory controllers.

    0 讨论(0)
  • 2021-01-20 18:51

    Amazingly, yes, as per Paul R's comment: mov is Turing complete.

    Such a mov only computer would be (highly) impractical however. not to mention the fact that it would be fiendishly hard to write a compiler for it. There is a c compiler that translates general purpose c programs into x86 mov instructions. Amazingly it does allows floating point calculations.
    Because it is based on a Turing machine and not a Von Neumann computer it is horribly slow, (but it's a great way to obfuscate your code :-1).

    For all practical purposes you can only do calculations via registers.
    AFIAK only movs takes 2 memory operands, every other instruction that accesses memory uses a constant or register operand in addition.

    Rowhammer is not a calculation mechanism, because it is non-deterministic.
    It's also a artefact of the way dram is implemented, cache memory does not suffer from this effect.

    0 讨论(0)
提交回复
热议问题