{"id":18153410,"url":"https://github.com/guoriyue/warp-from-device","last_synced_at":"2025-07-05T07:33:29.200Z","repository":{"id":220926300,"uuid":"752368366","full_name":"guoriyue/warp-from-device","owner":"guoriyue","description":null,"archived":false,"fork":false,"pushed_at":"2024-02-05T06:04:40.000Z","size":1792,"stargazers_count":0,"open_issues_count":0,"forks_count":1,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-02-13T06:35:55.228Z","etag":null,"topics":["cuda-programming","warp"],"latest_commit_sha":null,"homepage":"","language":"Cuda","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/guoriyue.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"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}},"created_at":"2024-02-03T18:18:19.000Z","updated_at":"2024-06-11T18:47:09.000Z","dependencies_parsed_at":"2024-02-05T08:25:58.290Z","dependency_job_id":"36e923f3-fa7c-4ee7-a67b-3c726d121023","html_url":"https://github.com/guoriyue/warp-from-device","commit_stats":null,"previous_names":["guoriyue/warp-from-device"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guoriyue%2Fwarp-from-device","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guoriyue%2Fwarp-from-device/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guoriyue%2Fwarp-from-device/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/guoriyue%2Fwarp-from-device/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/guoriyue","download_url":"https://codeload.github.com/guoriyue/warp-from-device/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247574097,"owners_count":20960495,"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","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":["cuda-programming","warp"],"created_at":"2024-11-02T03:06:55.139Z","updated_at":"2025-04-07T00:52:56.782Z","avatar_url":"https://github.com/guoriyue.png","language":"Cuda","funding_links":[],"categories":[],"sub_categories":[],"readme":"Call [NVIDIA Warp](https://github.com/nvidia/warp) kernels from device\n\nInstall Warp\n\n```\npip install numpy\ngit clone https://github.com/NVIDIA/warp.git\ncd warp\npython build_lib.py --cuda_path=/usr/local/warp\npip install -e .\n```\n\nRun this Warp Python example to jit compile the example_add_float_array.py\n```\npython3 float_arrays_add.py\n```\n\nNote the Kernel cache path, it will contain the generated CUDA code.\nWarp uses a Python-\u003eC++/CUDA compilation model that generates kernel code from Python function definitions. \nCopy the CUDA file and save it in current directory.\n\n```\nnvcc call_wp_add_float.cu -rdc=true -lcudadevrt\n./a.out\n```\n\n\nIn call_wp_add_float.cu, we need to include:\n\n```\n#include \"warp/warp/native/builtin.h\"\n#include \"wp_float_arrays_add.cu\"\n```\n\nTo call the Warp kernel function, we need to convert our data into Warp variables.\n```\nextern \"C\" __global__ void add_float_arrays_cuda_kernel_forward(\n    wp::launch_bounds_t dim,\n    wp::array_t\u003cwp::float32\u003e var_dest,\n    wp::array_t\u003cwp::float32\u003e var_a,\n    wp::array_t\u003cwp::float32\u003e var_b)\n```\n\nIf we only have the precompiled PTX file, we need to declare add_float_arrays_cuda_kernel_forward as an external function and perform a dry run to save the compilation commands. Afterward, we need to modify the intermediate PTX file during the compilation process using the PTX file generated by our Warp code.\n\n```\nnvcc call_wp_add_float.cu -rdc=true -lcudadevrt -dryrun\n```\n\nThen run everything before:\n\n```\nptxas -arch=sm_52 -m64 --compile-only  \"/tmp/tmpxft_0024aebf_00000000-6_call_wp_add_float.ptx\"  -o \"/tmp/tmpxft_0024aebf_00000000-10_call_wp_add_float.sm_52.cubin\" \n```\n\nRemove the undefined function 'add_float_arrays_cuda_kernel_forward' in the file '/tmp/tmpxft_0024aebf_00000000-6_call_wp_add_float.ptx' and replace it with the precompiled Warp PTX code. Due to the Static Single Assignment (SSA) form, we may want to rename the values to ensure correctness, though I have tested it without renaming, and it still works.\n\u003c!-- Copy the CUDA file and save it in current directory. --\u003e\n\nThen run the ptxas command and everything after to get a.out.\n\n\u003c!-- nvcc call_wp_max_block.cu -rdc=true -lcudadevrt --\u003e","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguoriyue%2Fwarp-from-device","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fguoriyue%2Fwarp-from-device","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fguoriyue%2Fwarp-from-device/lists"}