{"id":13718844,"url":"https://github.com/sonots/cumo","last_synced_at":"2025-04-10T00:19:39.456Z","repository":{"id":62556546,"uuid":"110840073","full_name":"sonots/cumo","owner":"sonots","description":"Cumo (pronounced like \"koomo\") is CUDA aware numerical library whose interface is highly compatible with Ruby Numo","archived":false,"fork":false,"pushed_at":"2019-10-01T00:58:46.000Z","size":2637,"stargazers_count":96,"open_issues_count":10,"forks_count":7,"subscribers_count":7,"default_branch":"master","last_synced_at":"2025-04-01T20:45:30.015Z","etag":null,"topics":["cuda","numo","ruby","scicentific-computing"],"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/sonots.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":"CODE_OF_CONDUCT.md","threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2017-11-15T13:56:36.000Z","updated_at":"2025-03-03T23:15:31.000Z","dependencies_parsed_at":"2022-11-03T06:15:28.090Z","dependency_job_id":null,"html_url":"https://github.com/sonots/cumo","commit_stats":null,"previous_names":[],"tags_count":32,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonots%2Fcumo","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonots%2Fcumo/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonots%2Fcumo/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/sonots%2Fcumo/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/sonots","download_url":"https://codeload.github.com/sonots/cumo/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248131603,"owners_count":21052881,"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","numo","ruby","scicentific-computing"],"created_at":"2024-08-03T01:00:38.591Z","updated_at":"2025-04-10T00:19:39.434Z","avatar_url":"https://github.com/sonots.png","language":"C","readme":"# Cumo\n\nCumo (pronounced \"koomo\") is a CUDA-aware, GPU-optimized numerical library that offers a significant performance boost over [Ruby Numo](https://github.com/ruby-numo), while (mostly) maintaining drop-in compatibility.\n\n\u003cimg src=\"https://raw.githubusercontent.com/sonots/cumo-logo/master/logo_transparent.png\" alt=\"cumo logo\" title=\"cumo logo\" width=\"50%\"\u003e\n\n## Requirements\n\n* Ruby 2.5 or later\n* NVIDIA GPU Compute Capability 3.5 (Kepler) or later\n* CUDA 9.0 or later\n\n## Preparation\n\nInstall CUDA and set your environment variables as follows:\n\n```bash\nexport CUDA_PATH=\"/usr/local/cuda\"\nexport CPATH=\"$CUDA_PATH/include:$CPATH\"\nexport LD_LIBRARY_PATH=\"$CUDA_PATH/lib64:$CUDA_PATH/lib:$LD_LIBRARY_PATH\"\nexport PATH=\"$CUDA_PATH/bin:$PATH\"\nexport LIBRARY_PATH=\"$CUDA_PATH/lib64:$CUDA_PATH/lib:$LIBRARY_PATH\"\n```\n\nTo use cuDNN features, install cuDNN and set your environment variables as follows:\n\n```\nexport CUDNN_ROOT_DIR=/path/to/cudnn\nexport CPATH=$CUDNN_ROOT_DIR/include:$CPATH\nexport LD_LIBRARY_PATH=$CUDNN_ROOT_DIR/lib64:$LD_LIBRARY_PATH\nexport LIBRARY_PATH=$CUDNN_ROOT_DIR/lib64:$LIBRARY_PATH\n```\n\nFYI: I use [cudnnenv](https://github.com/unnonouno/cudnnenv) to install cudnn under my home directory like `export CUDNN_ROOT_DIR=/home/sonots/.cudnn/active/cuda`.\n\n## Installation\n\nAdd the following line to your Gemfile:\n\n```ruby\ngem 'cumo'\n```\n\nAnd then execute:\n\n    $ bundle\n\nOr install it yourself as:\n\n    $ gem install cumo\n\n## How To Use\n\n### Quick start\n\nAn example:\n\n```ruby\n[1] pry(main)\u003e require \"cumo/narray\"\n=\u003e true\n[2] pry(main)\u003e a = Cumo::DFloat.new(3,5).seq\n=\u003e Cumo::DFloat#shape=[3,5]\n[[0, 1, 2, 3, 4],\n [5, 6, 7, 8, 9],\n [10, 11, 12, 13, 14]]\n[3] pry(main)\u003e a.shape\n=\u003e [3, 5]\n[4] pry(main)\u003e a.ndim\n=\u003e 2\n[5] pry(main)\u003e a.class\n=\u003e Cumo::DFloat\n[6] pry(main)\u003e a.size\n=\u003e 15\n```\n\n### Switching from Numo to Cumo\n\nThe following find-and-replace should just work:\n\n```\nfind . -type f | xargs sed -i -e 's/Numo/Cumo/g' -e 's/numo/cumo/g'\n```\n\nIf you want to dynamically switch between Numo and Cumo, something like the following will work:\n\n```ruby\nif gpu\n  require 'cumo/narray'\n  xm = Cumo\nelse\n  require 'numo/narray'\n  xm = Numo\nend\n\na = xm::DFloat.new(3,5).seq\n```\n\n### Incompatibility With Numo\n\nThe following methods behave incompatibly with Numo by default for performance reasons:\n\n* `extract`\n* `[]`\n* `count_true`\n* `count_false`\n\nNumo returns a Ruby numeric object for 0-dimensional NArray, while Cumo returns the 0-dimensional NArray instead of a Ruby numeric object.\nCumo differs in this way to avoid synchronization and minimize CPU ⇄ GPU data transfer.\n\nSet the `CUMO_COMPATIBLE_MODE` environment variable to `ON` to force Numo NArray compatibility (for worse performance).\n\nYou may enable or disable `compatible_mode` as:\n\n```\nrequire 'cumo'\nCumo.enable_compatible_mode # enable\nCumo.compatible_mode_enabled? #=\u003e true\nCumo.disable_compatible_mode # disable\nCumo.compatible_mode_enabled? #=\u003e false\n```\n\nYou can also use the following methods which behave like Numo's NArray methods. The behavior of these methods does not depend on `compatible_mode`.\n\n* `extract_cpu`\n* `aref_cpu(*idx)`\n* `count_true_cpu`\n* `count_false_cpu`\n\n### Select a GPU device ID\n\nSet the `CUDA_VISIBLE_DEVICES=id` environment variable, or\n\n```\nrequire 'cumo'\nCumo::CUDA::Runtime.cudaSetDevice(id)\n```\n\nwhere `id` is an integer.\n\n### Disable GPU Memory Pool\n\nGPU memory pool is enabled by default. To disable it, set `CUMO_MEMORY_POOL=OFF`, or:\n\n```\nrequire 'cumo'\nCumo::CUDA::MemoryPool.disable\n```\n\n## Documentation\n\nSee https://github.com/ruby-numo/numo-narray#documentation, replacing Numo with Cumo.\n\n## Contributions\n\nThis project is under active development. See [issues](https://github.com/sonots/cumo/issues) for future works.\n\n## Development\n\nInstall ruby dependencies:\n\n```\nbundle install --path vendor/bundle\n```\n\nCompile:\n\n```\nbundle exec rake compile\n```\n\nRun tests:\n\n```\nbundle exec rake test\n```\n\nGenerate docs:\n\n```\nbundle exec rake docs\n```\n\n## Advanced Development Tips\n\n### ccache\n\n[ccache](https://ccache.samba.org/) would be useful to speedup compilation time.\nInstall ccache and configure with:\n\n\n```bash\nexport PATH=\"$HOME/opt/ccache/bin:$PATH\"\nln -sf \"$HOME/opt/ccache/bin/ccache\" \"$HOME/opt/ccache/bin/gcc\"\nln -sf \"$HOME/opt/ccache/bin/ccache\" \"$HOME/opt/ccache/bin/g++\"\nln -sf \"$HOME/opt/ccache/bin/ccache\" \"$HOME/opt/ccache/bin/nvcc\"\n```\n\n### Build in parallel\n\nSet `MAKEFLAGS` to specify `make` command options. You can build in parallel as:\n\n```\nbundle exec env MAKEFLAG=-j8 rake compile\n```\n\n### Specify nvcc --generate-code options\n\n```\nbundle exec env CUMO_NVCC_GENERATE_CODE=arch=compute_60,code=sm_60 rake compile\n```\n\nThis is useful even on development because it makes it possible to skip JIT compilation of PTX to cubin during runtime.\n\n### Run tests with gdb\n\nCompile with debugging enabled:\n\n```\nbundle exec DEBUG=1 rake compile\n```\n\nRun tests with gdb:\n\n```\nbundle exec gdb -x run.gdb --args ruby test/narray_test.rb\n```\n\nYou may put a breakpoint by calling `cumo_debug_breakpoint()` at C source codes.\n\n### Run tests only a specific line\n`--location` option is available as:\n\n```\nbundle exec ruby test/narray_test.rb --location 121\n```\n\n### Compile and run tests only a specific type\n\n`DTYPE` environment variable is available as:\n\n```\nbundle exec DTYPE=dfloat rake compile\n```\n\n```\nbundle exec DTYPE=dfloat ruby test/narray_test.rb\n```\n\n### Run program always synchronizing CPU and GPU\n\n```\nbundle exec CUDA_LAUNCH_BLOCKING=1\n```\n\n### Show GPU synchronization warnings\n\nCumo shows warnings if CPU and GPU synchronization occurs if:\n\n```\nexport CUMO_SHOW_WARNING=ON\n```\n\nBy default, Cumo shows warnings that occurred at the same place only once.\nTo show all, multiple warnings, set:\n\n```\nexport CUMO_SHOW_WARNING=ON\nexport CUMO_SHOW_WARNING_ONCE=OFF\n```\n\n## Contributing\n\nBug reports and pull requests are welcome on GitHub at https://github.com/sonots/cumo.\n\n## License\n\n* [LICENSE.txt](./LICENSE.txt)\n* [3rd_party/LICENSE.txt](./3rd_party/LICENSE.txt)\n\n## Related Materials\n\n* [Fast Numerical Computing and Deep Learning in Ruby with Cumo](https://speakerdeck.com/sonots/fast-numerical-computing-and-deep-learning-in-ruby-with-cumo) - Presentation Slide at [RubyKaigi 2018](https://rubykaigi.org/2018/presentations/sonots.html#may31)\n","funding_links":[],"categories":["Data Structures"],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsonots%2Fcumo","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsonots%2Fcumo","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsonots%2Fcumo/lists"}