Skip to content

Commit

Permalink
docs and cuda
Browse files Browse the repository at this point in the history
  • Loading branch information
viciopoli01 committed Nov 29, 2024
1 parent 86432dc commit 315acd6
Show file tree
Hide file tree
Showing 19 changed files with 1,510 additions and 0 deletions.
20 changes: 20 additions & 0 deletions docs/Makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Minimal makefile for Sphinx documentation
#

# You can set these variables from the command line, and also
# from the environment for the first two.
SPHINXOPTS ?=
SPHINXBUILD ?= sphinx-build
SOURCEDIR = .
BUILDDIR = _build

# Put it first so that "make" without argument is like "make help".
help:
@$(SPHINXBUILD) -M help "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)

.PHONY: help Makefile

# Catch-all target: route all unknown targets to Sphinx using the new
# "make mode" option. $(O) is meant as a shortcut for $(SPHINXOPTS).
%: Makefile
@$(SPHINXBUILD) -M $@ "$(SOURCEDIR)" "$(BUILDDIR)" $(SPHINXOPTS) $(O)
38 changes: 38 additions & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Configuration file for the Sphinx documentation builder.
#
# For the full list of built-in configuration values, see the documentation:
# https://www.sphinx-doc.org/en/master/usage/configuration.html

# -- Project information -----------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#project-information

project = 'FaVoR'
copyright = '2024, Vincenzo Polizzi'
author = 'Vincenzo Polizzi'
release = '1.0.0'

import os
import sys
sys.path.insert(0, os.path.abspath('..'))

# -- General configuration ---------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#general-configuration

extensions = ['sphinx.ext.autodoc', 'sphinx.ext.coverage', 'sphinx.ext.napoleon']
autodoc_mock_imports = []
try:
import numpy
except ImportError:
autodoc_mock_imports.append('numpy')


templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']



# -- Options for HTML output -------------------------------------------------
# https://www.sphinx-doc.org/en/master/usage/configuration.html#options-for-html-output

html_theme = 'sphinx_rtd_theme'
html_static_path = ['_static']
30 changes: 30 additions & 0 deletions docs/datasets.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
Datasets
========

Bla bla bla


Download
------------

Bla bla bla


Dataloader Base Class
---------------------

.. automodule:: lib.data_loaders.Dataloader
:members:
:undoc-members:
:show-inheritance:
:no-index:

Dataloader for Cambridge Landmarks Dataset
------------------------------------------

The class :class:`lib.data_loaders.CambridgeLandmarksDataloader` is a subclass of :class:`lib.data_loaders.Dataloader` and is used to load the Cambridge Landmarks Dataset.

Dataloader for 7Scenes Dataset
-------------------------------

The class :class:`lib.data_loaders.SevenScenesDataloader` is a subclass of :class:`lib.data_loaders.Dataloader` and is used to load the 7Scenes Dataset.
23 changes: 23 additions & 0 deletions docs/home.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
FaVoR Documentation
===================

.. figure:: media/eyecatcher.png
:alt: FaVoR pipeline
:figclass: align-center


About
-----
FaVoR is a 3D representation of keypoints descriptors, which
can be used for camera relocalization.
If you use plan to use FaVoR for your research, please cite::

@misc{polizzi2024arXiv,
title={FaVoR: Features via Voxel Rendering for Camera Relocalization},
author={Vincenzo Polizzi and Marco Cannici and Davide Scaramuzza and Jonathan Kelly},
year={2024},
eprint={2409.07571},
archivePrefix={arXiv},
primaryClass={cs.CV},
url={https://arxiv.org/abs/2409.07571},
}
12 changes: 12 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
.. include::
home.rst

Contents:
----------
.. toctree::
:maxdepth: 2
:caption: Contents:

home
installation
datasets
20 changes: 20 additions & 0 deletions docs/installation.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Installation
============

Follow the steps below to install and set up the environment for the project.

Requirements
------------

To run the project, you need Python 3.x and the following dependencies:

- `numpy`
- `scipy`
- `torch` (if using PyTorch)
- `sphinx` (for generating documentation)

You can install the dependencies by running:

```bash
pip install -r requirements.txt
```
35 changes: 35 additions & 0 deletions docs/make.bat
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
@ECHO OFF

pushd %~dp0

REM Command file for Sphinx documentation

if "%SPHINXBUILD%" == "" (
set SPHINXBUILD=sphinx-build
)
set SOURCEDIR=.
set BUILDDIR=_build

%SPHINXBUILD% >NUL 2>NUL
if errorlevel 9009 (
echo.
echo.The 'sphinx-build' command was not found. Make sure you have Sphinx
echo.installed, then set the SPHINXBUILD environment variable to point
echo.to the full path of the 'sphinx-build' executable. Alternatively you
echo.may add the Sphinx directory to PATH.
echo.
echo.If you don't have Sphinx installed, grab it from
echo.https://www.sphinx-doc.org/
exit /b 1
)

if "%1" == "" goto help

%SPHINXBUILD% -M %1 %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%
goto end

:help
%SPHINXBUILD% -M help %SOURCEDIR% %BUILDDIR% %SPHINXOPTS% %O%

:end
popd
Binary file added docs/media/eyecatcher.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
38 changes: 38 additions & 0 deletions lib/cuda/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
try:
library_loaded = False


def load_library():
global library_loaded
if not library_loaded:
import torch
from pathlib import Path

file_path = Path(__file__)
so_files = list(file_path.parent.glob('*.so'))
if not so_files:
print('\033[1;41;37m No CUDA libraries found to load!\033[0m')
return

for f in so_files:
torch.ops.load_library(f)

library_loaded = True
print('\033[1;42;38m CUDA libraries loaded successfully!\033[0m')
else:
print('\033[1;43;38m CUDA libraries already loaded!\033[0m')


load_library()

except ImportError as e:
print('\033[1;41;37m Failed to import torch! Make sure PyTorch is installed.\033[0m')
print(e)

except OSError as e:
print('\033[1;41;37m Failed to load CUDA libraries! Build the CUDA libraries first.\033[0m')
print(e)

except Exception as e:
print('\033[1;41;37m An unexpected error occurred!\033[0m')
print(e)
84 changes: 84 additions & 0 deletions lib/cuda/adam_upd.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,84 @@
#include <torch/extension.h>

#include <vector>

// CUDA forward declarations

void adam_upd_cuda(
torch::Tensor param,
torch::Tensor grad,
torch::Tensor exp_avg,
torch::Tensor exp_avg_sq,
int64_t step, double beta1, double beta2, double lr, double eps);

void masked_adam_upd_cuda(
torch::Tensor param,
torch::Tensor grad,
torch::Tensor exp_avg,
torch::Tensor exp_avg_sq,
int64_t step, double beta1, double beta2, double lr, double eps);

void adam_upd_with_perlr_cuda(
torch::Tensor param,
torch::Tensor grad,
torch::Tensor exp_avg,
torch::Tensor exp_avg_sq,
torch::Tensor perlr,
int64_t step, double beta1, double beta2, double lr, double eps);


// C++ interface

#define CHECK_CUDA(x) TORCH_CHECK(x.is_cuda(), #x " must be a CUDA tensor")
#define CHECK_CONTIGUOUS(x) TORCH_CHECK(x.is_contiguous(), #x " must be contiguous")
#define CHECK_INPUT(x) CHECK_CUDA(x); CHECK_CONTIGUOUS(x)

void adam_upd(
torch::Tensor param,
torch::Tensor grad,
torch::Tensor exp_avg,
torch::Tensor exp_avg_sq,
int64_t step, double beta1, double beta2, double lr, double eps) {
CHECK_INPUT(param);
CHECK_INPUT(grad);
CHECK_INPUT(exp_avg);
CHECK_INPUT(exp_avg_sq);
adam_upd_cuda(param, grad, exp_avg, exp_avg_sq,
step, beta1, beta2, lr, eps);
}

void masked_adam_upd(
torch::Tensor param,
torch::Tensor grad,
torch::Tensor exp_avg,
torch::Tensor exp_avg_sq,
int64_t step, double beta1, double beta2, double lr, double eps) {
CHECK_INPUT(param);
CHECK_INPUT(grad);
CHECK_INPUT(exp_avg);
CHECK_INPUT(exp_avg_sq);
masked_adam_upd_cuda(param, grad, exp_avg, exp_avg_sq,
step, beta1, beta2, lr, eps);
}

void adam_upd_with_perlr(
torch::Tensor param,
torch::Tensor grad,
torch::Tensor exp_avg,
torch::Tensor exp_avg_sq,
torch::Tensor perlr,
int64_t step, double beta1, double beta2, double lr, double eps) {
CHECK_INPUT(param);
CHECK_INPUT(grad);
CHECK_INPUT(exp_avg);
CHECK_INPUT(exp_avg_sq);
adam_upd_with_perlr_cuda(param, grad, exp_avg, exp_avg_sq, perlr,
step, beta1, beta2, lr, eps);
}

TORCH_LIBRARY(adam_upd, m) {
m.def("adam_upd", &adam_upd); // "Adam update")
m.def("masked_adam_upd", &masked_adam_upd); // "Adam update ignoring zero grad"
m.def("adam_upd_with_perlr", &adam_upd_with_perlr); // "Adam update ignoring zero grad with per-voxel lr"
}

Loading

0 comments on commit 315acd6

Please sign in to comment.