Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

V0.3 - Refactor #17

Merged
merged 1 commit into from
Nov 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .JuliaFormatter.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
style = "yas"
2 changes: 2 additions & 0 deletions .github/codecov.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
ignore:
- "src/lib"
29 changes: 21 additions & 8 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,8 +1,18 @@
name: CI
on:
- push
- pull_request
- workflow_dispatch
push:
branches:
- 'master'
- 'main'
- 'release-'
tags: '*'
pull_request:
workflow_dispatch:

concurrency:
group: ${{ github.workflow }}-${{ github.ref }}
cancel-in-progress: true

jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
Expand All @@ -11,24 +21,27 @@ jobs:
fail-fast: false
matrix:
version:
- '1.6'
- 'lts'
- '1' # automatically expands to the latest stable 1.x release of Julia
os:
- ubuntu-latest
- macOS-latest
arch:
- x64
steps:
- uses: actions/checkout@v2
- uses: julia-actions/setup-julia@v1
- uses: actions/checkout@v4
- uses: julia-actions/setup-julia@v2
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}
- uses: julia-actions/cache@v2
- uses: julia-actions/julia-buildpkg@latest
- uses: julia-actions/julia-runtest@latest
env:
JULIA_NUM_THREADS: 4
- uses: julia-actions/julia-processcoverage@v1
- uses: codecov/codecov-action@v1
- uses: codecov/codecov-action@v4
env:
CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }}
with:
file: lcov.info
file: lcov.info
32 changes: 32 additions & 0 deletions .github/workflows/FormatCheck.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: FormatCheck

on:
push:
branches:
- 'master'
tags: '*'
pull_request:
branches:
- 'master'
jobs:
build:
runs-on: ${{ matrix.os }}
strategy:
matrix:
version:
- '1' # automatically expands to the latest stable 1.x release of Julia
os:
- ubuntu-latest
arch:
- x64
steps:
- uses: julia-actions/setup-julia@latest
with:
version: ${{ matrix.version }}
arch: ${{ matrix.arch }}

- uses: actions/checkout@v4
- name: Install JuliaFormatter and format
run: |
julia -e 'using Pkg; Pkg.add(PackageSpec(name="JuliaFormatter"))'
julia -e 'using JuliaFormatter; format(".", verbose=true)'
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Manifest.toml
26 changes: 0 additions & 26 deletions .travis.yml

This file was deleted.

88 changes: 0 additions & 88 deletions Manifest.toml

This file was deleted.

26 changes: 17 additions & 9 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
name = "TBLIS"
uuid = "48530278-0828-4a49-9772-0f3830dfa1e9"
authors = ["MattDavis <matthew.davis010@gmail.com>"]
version = "0.2.0"
authors = ["Lukas Devos <ldevos98@gmail.com>"]
version = "0.3.0"

[deps]
Hwloc_jll = "e33a78d0-f292-5ffc-b300-72abe9b543c8"
Libdl = "8f399da3-3557-5675-b5ff-fb832c97cbdb"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"
tblis_jll = "9c7f617c-f299-5d18-afb6-044c7798b3d0"

[extras]
Aqua = "4c88cf16-eb10-579e-8560-4a9242c79595"
Random = "9a3f8284-a2c9-5f02-9a11-845980a1fd5c"
SafeTestsets = "1bc83da4-3b8d-516f-aca4-4fe02f6d838f"
Test = "8dfed614-e22c-5e08-85e1-65c5234f0b40"

[targets]
test = ["Test", "SafeTestsets", "Random", "Aqua"]

[compat]
julia = "1"
Hwloc_jll = "2"
tblis_jll = "1"
Aqua = "0.8.9"
Random = "1"
SafeTestsets = "0.1.0"
Test = "1"
julia = "1.10"
tblis_jll = "1.2"
58 changes: 14 additions & 44 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,52 +1,22 @@
# TBLIS.jl
[![CI](https://github.com/FermiQC/TBLIS.jl/actions/workflows/CI.yml/badge.svg)](https://github.com/FermiQC/TBLIS.jl/actions/workflows/CI.yml)

[![CI][ci-img]][ci-url] [![][codecov-img]][codecov-url]

> If you are planning to use TBLIS with TensorOperations.jl a more convenient option might be the [BliContractor.jl](https://github.com/xrq-phys/BliContractor.jl) package.
Julia wrapper for TBLIS tensor contraction library.
[ci-img]: https://github.com/QuantumKitHub/TBLIS.jl/actions/workflows/ci.yml/badge.svg
[ci-url]: https://github.com/QuantumKitHub/TBLIS.jl/actions/workflows/ci.yml

Currently only tensor addition and multiplication are implemented.
[codecov-img]: https://codecov.io/gh/QuantumKitHub/TBLIS.jl/graph/badge.svg?token=Nlju9D2P1A
[codecov-url]: https://codecov.io/gh/QuantumKitHub/TBLIS.jl

## Install
```
julia>]
pkg>add TBLIS
```
Julia wrapper for the [TBLIS](https://github.com/devinamatthews/tblis) tensor contraction library.
This provides basic bindings for the functions defined in TBLIS.
The target audience is mostly package developers rather than users, as the interface is low-level
and does not include argument checking.

> Due to an issue with `tblis_jll`, TBLIS is not working on MAC.
For users, it is recommended to try out:
- [TensorOperations.jl](https://github.com/Jutho/TensorOperations.jl)
- [ITensors.jl](https://github.com/ITensor/ITensors.jl)

## Usage
```
using TBLIS
TBLIS.init()
## Acknowledgements

TT = Float32
O = 10
V = 50

_A = rand(TT,O,O,O,O)
_B = rand(TT,O,O,V,V)
_C = zeros(TT,O,O,V,V)
```
Arrays must be converted to TTensor objects.
```
A = TBLIS.TTensor(_A)
B = TBLIS.TTensor(_B)
C = TBLIS.TTensor(_C)
```
This object only creates a pointer to the original data.
```
julia> A.data === _A
true
```
* For a general contraction, the syntax is `TBLIS.mul!(C, A, B, Aind, Bind, Cind)`
where `Aind`, `Bind`, and `Cind` are strings following Einstein's notation.

* Addition is performing following `TBLIS.add!(A, B, Aind, Bind)`.
```
# C[i,j,a,b] += A[i,j,k,l]*B[k,l,a,b]
TBLIS.mul!(C, A, B, "ijkl", "klab", "ijab")

# B += A
TBLIS.add!(A, B, "ijkl", "ijkl")
```
This package is the continuation of a package previously hosted by https://github.com/FermiQC/TBLIS.jl.
4 changes: 4 additions & 0 deletions gen/Project.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
[deps]
Clang = "40e3b903-d033-50b4-a0cc-940c62c95e31"
JuliaFormatter = "98e50ef6-434e-11e9-1051-2b60c6c9e899"
tblis_jll = "9c7f617c-f299-5d18-afb6-044c7798b3d0"
9 changes: 9 additions & 0 deletions gen/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# How to auto-generate the wrappers

1. `cd` to this directory
2. run `julia --project generator.jl`, then you could find the updated wrappers in the `lib` folder

## How to upgrade Clang.jl

1. `cd` to this directory
2. run `julia --project` and then in the Julia REPL, run `pkg> up`
38 changes: 38 additions & 0 deletions gen/generator.jl
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
using Pkg
Pkg.activate(@__DIR__)
Pkg.instantiate()
using Pkg.Artifacts
using Clang.Generators
using Clang.Generators.JLLEnvs
using tblis_jll
using JuliaFormatter

cd(@__DIR__)

# ensure output path exists
outpath = joinpath(@__DIR__, "..", "src", "lib")
!isdir(outpath) && mkpath(outpath)

# headers
include_dir = normpath(joinpath(tblis_jll.artifact_dir, "include"))

tci_h = joinpath(include_dir, "tci.h")
@assert isfile(tci_h)
tblis_h = joinpath(include_dir, "tblis", "tblis.h")
@assert isfile(tblis_h)

# load common option
options = load_options(joinpath(@__DIR__, "generator.toml"))

# run generator for all platforms
for target in JLLEnvs.JLL_ENV_TRIPLES
@info "processing $target"
options["general"]["output_file_path"] = joinpath(outpath, "$target.jl")
path = options["general"]["output_file_path"]
args = get_default_args(target)
push!(args, "-I$include_dir")
header_files = [tci_h, tblis_h]
ctx = create_context(header_files, args, options)
build!(ctx)
format_file(path, YASStyle())
end
24 changes: 24 additions & 0 deletions gen/generator.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
[general]

library_name = "tblis"

use_julia_native_enum_type = true
use_deterministic_symbol = true
auto_mutability = true

output_ignorelist = [
"TCI_WORK_ITEM_INIT",
"TBLIS_RESTRICT",
"scomplex",
"dcomplex",
]

[codegen]
use_ccall_macro = true

[codegen.macro]
macro_mode = "basic"

functionlike_macro_includelist = [

]
Loading
Loading