{"id":31505671,"url":"https://github.com/nekon69/fastnoiselitecuda","last_synced_at":"2025-10-02T20:10:14.231Z","repository":{"id":314320754,"uuid":"1055070540","full_name":"NeKon69/FastNoiseLiteCUDA","owner":"NeKon69","description":"A wrapper around C++ FastNoiseLite library for CUDA","archived":false,"fork":false,"pushed_at":"2025-09-26T15:36:54.000Z","size":84,"stargazers_count":2,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"main","last_synced_at":"2025-09-26T17:37:56.781Z","etag":null,"topics":["cellular-noise","computer-graphics","cpp","cuda","fastnoiselite","gamedev","generative-art","gpgpu","gpu","header-only","noise","opensimplex2-noise","pcg","perlin-noise","procedural-generation","simplex-noise","terrain-generation","texture-generation","worley-noise"],"latest_commit_sha":null,"homepage":"","language":"C++","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/NeKon69.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null,"notice":"NOTICE.md","maintainers":null,"copyright":null,"agents":null,"dco":null,"cla":null}},"created_at":"2025-09-11T18:12:35.000Z","updated_at":"2025-09-26T15:36:57.000Z","dependencies_parsed_at":"2025-09-11T21:19:28.429Z","dependency_job_id":"8a04e00b-6395-42c4-a239-aaf41a677af2","html_url":"https://github.com/NeKon69/FastNoiseLiteCUDA","commit_stats":null,"previous_names":["nekon69/fastnoiselightcuda","nekon69/fastnoiselitecuda"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/NeKon69/FastNoiseLiteCUDA","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NeKon69%2FFastNoiseLiteCUDA","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NeKon69%2FFastNoiseLiteCUDA/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NeKon69%2FFastNoiseLiteCUDA/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NeKon69%2FFastNoiseLiteCUDA/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/NeKon69","download_url":"https://codeload.github.com/NeKon69/FastNoiseLiteCUDA/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/NeKon69%2FFastNoiseLiteCUDA/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":278063119,"owners_count":25923594,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","status":"online","status_checked_at":"2025-10-02T02:00:08.890Z","response_time":67,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cellular-noise","computer-graphics","cpp","cuda","fastnoiselite","gamedev","generative-art","gpgpu","gpu","header-only","noise","opensimplex2-noise","pcg","perlin-noise","procedural-generation","simplex-noise","terrain-generation","texture-generation","worley-noise"],"created_at":"2025-10-02T20:10:12.503Z","updated_at":"2025-10-02T20:10:14.224Z","avatar_url":"https://github.com/NeKon69.png","language":"C++","readme":"# FastNoiseLiteCUDA\n\nThis is a CUDA-compatible wrapper for Auburn's popular [FastNoiseLite](https://github.com/Auburn/FastNoiseLite) library. It allows for the high-performance generation of various noise types directly on the GPU within CUDA kernels.\n\nThis port is designed to be a drop-in replacement for the original single-header file, enabling its use in both host (`__host__`) and device (`__device__`) code.\n\n---\n\n## *Please note: A Critical Note on Host-Side Usage*\n\nThe library's behavior changes depending on whether you are compiling a `.cu` file with NVCC or a standard `.cpp` file with a host compiler (like GCC/Clang/MSVC). This is crucial for understanding where you can safely call the `GetNoise` functions.\n\nThe reason for this is the `NOISE_CONSTANT` macro, which places large lookup tables into `__constant__` GPU memory when processed by NVCC, but compiles them as regular CPU memory otherwise.\n\n*   **In `.cu` files (compiled with NVCC):**\n    Any function that uses the lookup tables (like `GetNoise`) is prepared by NVCC for device execution. If you call such a function from host code within a `.cu` file, the CPU will try to access the `__constant__` memory on the GPU, which is an illegal operation and **will not work**.\n    *   **Rule:** Inside `.cu` files, only configure `FastNoiseLite` on the host. Noise generation must happen inside a `__global__` kernel.\n\n*   **In `.cpp` files (or other non-NVCC compiled sources):**\n    When you include `FastNoiseLiteCUDA.h` in a standard `.cpp` file, `NOISE_CONSTANT` is empty. The lookup tables are just standard global arrays in CPU memory.\n    *   **Rule:** Inside `.cpp` files, you can safely use the **entire** `FastNoiseLite` object on the host, including calling `GetNoise`. This allows for CPU-based noise generation for testing or other logic.\n\n**Recommendation:**\nFor consistency and to avoid mistakes, the best practice is to configure your `FastNoiseLite` instance on the CPU and then pass it by value to your kernels for noise generation, as shown in *Example 2*. Use host-side `GetNoise` calls from `.cpp` files only when you have a specific need for them.\n\n---\n\n## Key Modifications for CUDA Compatibility\n\nTo make the library compatible with CUDA, several key changes were made to the original source code:\n\n*   **CUDA Function Specifiers**: All class methods and helper functions are now decorated with `__device__ __host__` (via the `NOISE_DH` macro). This allows them to be called from both CPU (host) and GPU (device) code seamlessly.\n\n*   **Lookup Table Refactoring**: The original `Lookup` struct, which was a nested static member of the class, caused compilation issues with NVCC. The compiler struggles with the definition of static device-side members. To resolve this:\n    *   The large lookup arrays (for gradients and random vectors) have been moved into a global `detail` namespace.\n    *   These arrays are declared in `__constant__` memory using the `NOISE_CONSTANT` macro. Constant memory is a cached, read-only memory space on the GPU, making it highly efficient for data that is accessed uniformly by all threads in a warp.\n    *   A new `FastNoise` namespace now contains the `Lookup` struct, which safely references these constant memory arrays. This restructuring resolves compilation errors while improving performance on the GPU.\n\n## Usage\n\nInclude the `FastNoiseLiteCUDA.h` header in your `.cu` file. You can then instantiate and use the `FastNoiseLite` object directly inside your CUDA kernels.\n\n### Example 1: Creating Noise Object Inside Kernel\n\nHere is a simple example of a kernel that generates 2D OpenSimplex2 noise for a grid by creating the noise object on the device.\n\n```cuda\n#include \"FastNoiseLiteCUDA.h\"\n\n__global__ void generate_noise_kernel(float* output, int width, int height)\n{\n    int x = blockIdx.x * blockDim.x + threadIdx.x;\n    int y = blockIdx.y * blockDim.y + threadIdx.y;\n\n    if (x \u003e= width || y \u003e= height)\n    {\n        return;\n    }\n\n    // Create a FastNoiseLite instance on the stack for each thread\n    FastNoiseLite noise(1337); // Seed\n    noise.SetNoiseType(FastNoiseLite::NoiseType_OpenSimplex2);\n    noise.SetFrequency(0.05f);\n\n    // Calculate noise value\n    float noiseValue = noise.GetNoise((float)x, (float)y);\n\n    // Write the result to the output array\n    output[y * width + x] = noiseValue;\n}\n```\n\n### Example 2: Configuring on Host, Passing to Kernel\n\nA more common pattern is to configure the noise generator on the host and pass it by value to the kernel.\n\n```cuda\n#include \"FastNoiseLiteCUDA.h\"\n#include \u003ccuda_runtime.h\u003e\n\n// Kernel accepts a configured FastNoiseLite object\n__global__ void generate_noise_from_host_config(float* output, int width, int height, FastNoiseLite noise)\n{\n    int x = blockIdx.x * blockDim.x + threadIdx.x;\n    int y = blockIdx.y * blockDim.y + threadIdx.y;\n\n    if (x \u003e= width || y \u003e= height)\n    {\n        return;\n    }\n\n    // Use the pre-configured noise object passed from the host\n    float noiseValue = noise.GetNoise((float)x, (float)y);\n    output[y * width + x] = noiseValue;\n}\n\nint main()\n{\n    int width = 1024;\n    int height = 1024;\n    size_t bufferSize = width * height * sizeof(float);\n\n    float* d_output;\n    cudaMalloc(\u0026d_output, bufferSize);\n\n    // 1. Configure FastNoiseLite on the host\n    FastNoiseLite host_noise_generator;\n    host_noise_generator.SetNoiseType(FastNoiseLite::NoiseType_Perlin);\n    host_noise_generator.SetFrequency(0.02f);\n    host_noise_generator.SetFractalType(FastNoiseLite::FractalType_FBm);\n    host_noise_generator.SetFractalOctaves(5);\n\n    dim3 threadsPerBlock(16, 16);\n    dim3 numBlocks((width + threadsPerBlock.x - 1) / threadsPerBlock.x, (height + threadsPerBlock.y - 1) / threadsPerBlock.y);\n\n    // 2. Pass the configured object by value to the kernel\n    generate_noise_from_host_config\u003c\u003c\u003cnumBlocks, threadsPerBlock\u003e\u003e\u003e(d_output, width, height, host_noise_generator);\n\n    // ... copy data back to host and process ...\n\n    cudaFree(d_output);\n    return 0;\n}\n```\n\n## Original Library\n\nThis project is a wrapper and is entirely based on the fantastic work by Jordan Peck (Auburn). All noise generation algorithms and logic belong to the original author.\n\nFor more in-depth documentation on the noise algorithms, features, and settings, please refer to the [official repository](https://github.com/Auburn/FastNoiseLite).\n\n## License\n\nThis wrapper is distributed under the MIT License, consistent with the original FastNoiseLite library. See the [LICENSE](LICENSE) file for more detail.\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnekon69%2Ffastnoiselitecuda","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fnekon69%2Ffastnoiselitecuda","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fnekon69%2Ffastnoiselitecuda/lists"}