Skip to content

Commit

Permalink
Initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Alec Hammond committed Jul 2, 2024
0 parents commit 609bc64
Show file tree
Hide file tree
Showing 50 changed files with 6,605 additions and 0 deletions.
8 changes: 8 additions & 0 deletions .github/workflows/Format.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
name: Format suggestions
on:
pull_request:
jobs:
code-style:
runs-on: ubuntu-latest
steps:
- uses: julia-actions/julia-format@v2
53 changes: 53 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
name: CI
on:
push:
branches:
- main
- release-*
tags: '*'
pull_request:
defaults:
run:
shell: bash
concurrency:
# Skip intermediate builds: always.
# Cancel intermediate builds: only if it is a pull request build.
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: ${{ startsWith(github.ref, 'refs/pull/') }}
jobs:
CI:
name: CI
runs-on: ${{ matrix.os }}
strategy:
fail-fast: false
matrix:
version:
- '1' # automatically expands to the latest stable 1.x release of Julia
os:
- ubuntu-20.04
arch:
- x64
steps:
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v1
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: actions/cache@v3
env:
cache-name: cache-artifacts
with:
path: ~/.julia/artifacts
key: ${{ runner.os }}-test-${{ env.cache-name }}-${{ hashFiles('**/Project.toml') }}
restore-keys: |
${{ runner.os }}-test-${{ env.cache-name }}-
${{ runner.os }}-test-
${{ runner.os }}-
- uses: julia-actions/julia-buildpkg@v1
- uses: julia-actions/julia-runtest@v1
with:
annotate: true
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v3
with:
file: lcov.info
52 changes: 52 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*.tar.gz
/tmp
/dist
/dist-extras
/julia
/julia.bat
/usr
/oprofile_data
/usr-staging
/Make.user
/julia-*
/source-dist.tmp
/source-dist.tmp1

*.expmap
*.exe
*.dll
*.dwo
*.do
*.o
*.o.tmp
*.obj
*.so
*.dylib
*.dSYM
*.h.gen
*.jl.cov
*.jl.*.cov
*.jl.mem
*.jl.*.mem
*.ji

/perf*
.DS_Store
.idea/*
.vscode/*
*.heapsnapshot
.cache
# Buildkite: Ignore the entire .buildkite directory
/.buildkite

# Buildkite: Ignore the unencrypted repo_key
repo_key

# Buildkite: Ignore any agent keys (public or private) we have stored
agent_key*

# File generated by Pkg, the package manager, based on a corresponding Project.toml
# It records a fixed state of all packages used by the project. As such, it should not be
# committed for packages, but should be committed for applications that require a static
# environment.
Manifest.toml
80 changes: 80 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# Code of Conduct

## Our Pledge

In the interest of fostering an open and welcoming environment, we as
contributors and maintainers pledge to make participation in our project and
our community a harassment-free experience for everyone, regardless of age, body
size, disability, ethnicity, sex characteristics, gender identity and expression,
level of experience, education, socio-economic status, nationality, personal
appearance, race, religion, or sexual identity and orientation.

## Our Standards

Examples of behavior that contributes to creating a positive environment
include:

* Using welcoming and inclusive language
* Being respectful of differing viewpoints and experiences
* Gracefully accepting constructive criticism
* Focusing on what is best for the community
* Showing empathy towards other community members

Examples of unacceptable behavior by participants include:

* The use of sexualized language or imagery and unwelcome sexual attention or
advances
* Trolling, insulting/derogatory comments, and personal or political attacks
* Public or private harassment
* Publishing others' private information, such as a physical or electronic
address, without explicit permission
* Other conduct which could reasonably be considered inappropriate in a
professional setting

## Our Responsibilities

Project maintainers are responsible for clarifying the standards of acceptable
behavior and are expected to take appropriate and fair corrective action in
response to any instances of unacceptable behavior.

Project maintainers have the right and responsibility to remove, edit, or
reject comments, commits, code, wiki edits, issues, and other contributions
that are not aligned to this Code of Conduct, or to ban temporarily or
permanently any contributor for other behaviors that they deem inappropriate,
threatening, offensive, or harmful.

## Scope

This Code of Conduct applies within all project spaces, and it also applies when
an individual is representing the project or its community in public spaces.
Examples of representing a project or community include using an official
project e-mail address, posting via an official social media account, or acting
as an appointed representative at an online or offline event. Representation of
a project may be further defined and clarified by project maintainers.

This Code of Conduct also applies outside the project spaces when there is a
reasonable belief that an individual's behavior may have a negative impact on
the project or its community.

## Enforcement

Instances of abusive, harassing, or otherwise unacceptable behavior may be
reported by contacting the project team at <[email protected]>. All
complaints will be reviewed and investigated and will result in a response that
is deemed necessary and appropriate to the circumstances. The project team is
obligated to maintain confidentiality with regard to the reporter of an incident.
Further details of specific enforcement policies may be posted separately.

Project maintainers who do not follow or enforce the Code of Conduct in good
faith may face temporary or permanent repercussions as determined by other
members of the project's leadership.

## Attribution

This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
available at https://www.contributor-covenant.org/version/1/4/code-of-conduct.html

[homepage]: https://www.contributor-covenant.org

For answers to common questions about this code of conduct, see
https://www.contributor-covenant.org/faq
31 changes: 31 additions & 0 deletions CONTRIBUTING.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Contributing to Khronos.jl
We want to make contributing to this project as easy and transparent as
possible.

## Pull Requests
We actively welcome your pull requests.

1. Fork the repo and create your branch from `main`.
2. If you've added code that should be tested, add tests.
3. If you've changed APIs, update the documentation.
4. Ensure the test suite passes.
5. Make sure your code lints.
6. If you haven't already, complete the Contributor License Agreement ("CLA").

## Contributor License Agreement ("CLA")
In order to accept your pull request, we need you to submit a CLA. You only need
to do this once to work on any of Facebook's open source projects.

Complete your CLA here: <https://code.facebook.com/cla>

## Issues
We use GitHub issues to track public bugs. Please ensure your description is
clear and has sufficient instructions to be able to reproduce the issue.

Facebook has a [bounty program](https://www.facebook.com/whitehat/) for the safe
disclosure of security bugs. In those cases, please go through the process
outlined on that page and do not file a public issue.

## License
By contributing to Khronos.jl, you agree that your contributions will be licensed
under the LICENSE file in the root directory of this source tree.
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
MIT License

Copyright (c) 2024 Meta Research

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
34 changes: 34 additions & 0 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
name = "Khronos"
uuid = "1a8c1b36-e3c2-448e-9848-c1c7b39e0d79"
authors = ["Alec Hammond <[email protected]>"]
version = "0.1.0"

[deps]
ArgParse = "c7e460c6-2fb9-53a9-8c5b-16f535851c63"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
CairoMakie = "13f3f980-e62b-5c42-98c6-ff1f3baf88f0"
Einsum = "b7d42ee7-0b51-5a75-98ca-779d3107e4c0"
GeometryPrimitives = "17051e67-205e-509e-8301-03b320b998e6"
Interpolations = "a98d9a8b-a2ab-59e6-89dd-64a1c18fca59"
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
KernelAbstractions = "63c18a36-062a-441e-b654-da1e3ab1ce7c"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Makie = "ee78f7c6-11fb-53f2-987a-cfe4a2b5a57a"
Metal = "dde4c033-4e86-420c-a63e-0dd931031962"
OffsetArrays = "6fe1bfb0-de20-5000-8ca7-80f57d26f881"
Parameters = "d96e819e-fc66-5662-9728-84c9c7592b0a"
Revise = "295af30f-e4ad-537b-8983-00126c2a3abe"
Statistics = "10745b16-79ce-11e8-11f9-7d13ad32a3b2"
VectorModesolver = "8c544392-5fd9-4640-bea4-e12b3d59d9d1"
YAML = "ddb6d928-2868-570f-bddf-ab3f9cf99eb6"

[compat]
Makie = ">= 0.20"
julia = "1.8"

[extras]
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test"]
32 changes: 32 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# Khronos.jl

![Continuous integration](https://github.com/facebookresearch/Khronos.jl/actions/workflows/ci.yml/badge.svg)

Khronos is a GPU-accelerated Maxwell FDTD solver written entirely in Julia.

## Key Features

- GPU acceleration compatible with NVIDIA CUDA, AMD ROCm, Intel OneAPI, and Apple Metal (via [KernelAbstractions.jl](https://github.com/JuliaGPU/KernelAbstractions.jl))
- 100% Julia code (works with Windows, Mac, and Linux)
- Specifiable precision (e.g. `Float64`, `Float32`)
- Parameterizable geometry via GeometryPrimitives.jl
- Diagonally anisotropic permittivity ($\varepsilon$) and permeability ($\mu$), and electric/magnetic conductivity terms ($\sigma_D$ / $\sigma_B$) for either the permittivity or permeability, respectively.
- Predefined current sources (including planewaves and Gaussian beams) and arbitrary curret sources.
- _Equivalent_ sources from predefined electric and magnetic fields (e.g. to inject modes computed from a mode solver).
- Continuous-wave and Guassian-pulse time profiles
- Arbitrary 1D, 2D, or 3D (rectilinear) DFT monitors
- Perfectly matched layer (PML) absorbing boundaries
- Predefined simulation runtime functions, including run for an arbitray time and run until the DFT fields have converged.
- Simple plotting of visualization cross sections and overlayed field response, DFT monitors, and source frequency responses.
- Benchmark tooling to track performance regressions/enhancements on arbitrary hardware
- Composable kernel framework allows for the flexible definition of thousands of different kernels

## Current limitations

- All simulations require PML.
- Single GPU only.
- Only linear materials without any polarizabilities.
- Uniform gridding.

## License
Khronos is licensed under the [MIT license](https://github.com/facebookresearch/Khronos.jl/blob/main/LICENSE).
53 changes: 53 additions & 0 deletions benchmark/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Benchmarks

Here we describe the following performance benchmarks used to detect performance regressions:

* `dipole.jl` - A simple dipole in vacumm, run at multiple resolutions. (Future work could include symmetries and different kinds of boundary conditions, near2far transforms, dft monitors.)
* `periodic_stack.jl` - A 1D periodic stack (simulated in 3D), run at multiple resolutions. Consists of a planewave source, PML, and dielectric materials throughout the domain. (Future work could include periodic boundaries, dispersive materials, anisotropic materials, subpixel smoothing, DFT monitors, time monitors.)
* `metallic_sphere.jl` - A metallic sphere in vaccum, run at multiple resolutions. (Future work could DFT and time monitors, subpixel smoothing, and dispersive materials.)

All benchmarks detect the current hardware and flags the user if the performance of the bechmark is significantly different than what's expected. Each benchmark simulates the **timestepping rate** (voxels/second). Future work should also check for additional/different allocations.

The file, `benchmark_utils.jl` contains various refactored routines that are repeated throughout the benchmarks.

Future benchmarks include
* `grating_coupler.jl` - A simple silicon photonics grating coupler simulation (pulled from SiEPIC).
* `directional_coupler.jl` - A simple silicon photonics directional coupler simulation (pulled from SiEPIC).
* `metalens.jl` - A simple metalens simulation (pulled from the Tidy3D paper).
* `uLED.jl` - A simple uLED pixel.

## Usage

To run the suite of benchmarks on your platform, simply run:

```bash
julia run_benchmarks.jl
```

To (optionally) specify a particular hardware platform (either `CUDA`, `METAL` or `CPU`), use the `--backend` flag:

```bash
julia run_benchmarks.jl --backend=CUDA
```

To (optionally) specify the arithemtic precision (either `Float32` or `Float64`), use the `--precision` flag:

```bash
julia run_benchmarks.jl --backend=CUDA --precision=Float64
```

To (optionally) _profile_ the current hardware and save the results, us the `--profile` flag:

```bash
julia run_benchmarks.jl --backend=CUDA --precision=Float64 --profile
```

## Saving profiling results

All profiling results can be saved to the benchmark's corresponding yaml file. For example, all `dipole.jl` results will be saved in `dipole.yml`.

Whenever adding a new hardware platform or precision configuration, you must manually add in the appropriate tests to the yaml file. This allows you to cherrypick specific simulation parameters best geared for that particular hardware platform.

For example, since an NVIDIA H100 GPU has significantly more VRAM than an NVIDIA V100, you'll want to setup tests with larger domains, resolutions, etc.

Similarly, all profile configurations accept a "tolerance" parameter, which can be used to specify how sensitive a change in performance needs to be before alerting a user. For example, a tolerance of 1.1 indicates a change of 10% will raise a warning, encouraging the user to record the change.
Loading

0 comments on commit 609bc64

Please sign in to comment.