https://www.reddit.com/r/adventofcode/comments/18dry49/2023_day_8_part_2glsl_brute_forced_in_under_a/

  • velox_vulnus@lemmy.ml
    ·
    edit-2
    7 months ago

    An extremely watered-down version for a non-tech person: Let's say you want to hack an account's password. When you try all combinations of characters continuously like how they do in the movies, that is a type of brute-force algorithm. It is considered the least efficient form of problem-solving.

    Now, instead of using a CPU, they're using a GPU. A GPU is also known as a display driver. It calculates and renders graphical stuff. That's not the CPU's job - it is simply not good at it, for a bunch of reasons.

    Now, a CPU is very fast, but can calculate fewer results. However, a GPU is slow, but can calculate in bulk. This is for the same reason why some people use GPU for mining crypto coin (they have been superseded by FGPA and ASIC).

    Calculating on a GPU is not as straight forward as using a CPU. Now, I did not read the post clearly, but this Reddit guy apparently used GLSL to calculate stuff? I am not really sure about the specifics of how, and why was this used. Last I remember using GLSL, you can't simply use that to print log on the screen. Maybe they're using OpenGL? Maybe Vulkan?

    • coloredgrayscale@programming.dev
      ·
      7 months ago

      One way to get the data is to render to a (hidden) surface/canvas. It's just bytes to the computer, so just dump the result data in the display buffer. Then you take a "screenshot" and interpret the RGBA values as data.

      • graphicsguy@programming.dev
        ·
        7 months ago

        Graphics Programmer here.

        More likely you would just write data to a buffer (basically an array of whatever element type you want) rather than a render target and then read it back to the cpu. Dx, vulkan, etc. all have APIs to upload / download to / from the GPU quite easily, and CUDA makes it even easier, so a simple compute shader or CUDA kernel that writes to a buffer would make the most sense for general purpose computation like an advent of code problem.