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

Candlex: an Nx.Backend for candle ML framework #1294

Closed
wants to merge 196 commits into from
Closed
Changes from all commits
Commits
Show all changes
196 commits
Select commit Hold shift + click to select a range
b3e565b
mix new candlex
grzuy Aug 9, 2023
b1d89ec
mix rustler.new
grzuy Aug 11, 2023
1f70213
[native/candlex] cargo add candle-core
grzuy Aug 17, 2023
9fd2713
gitignore candlex nif .so
grzuy Aug 17, 2023
9e9e445
WIP feat: can create candle tensor
grzuy Aug 17, 2023
2e60089
support multi dimension tensor
grzuy Aug 21, 2023
cd43dfe
clean
grzuy Aug 21, 2023
56206af
clean
grzuy Aug 21, 2023
875f669
clean
grzuy Aug 21, 2023
868bf88
clean
grzuy Aug 21, 2023
fcec30c
fn order
grzuy Aug 21, 2023
815a733
fmt
grzuy Aug 21, 2023
6ea27bc
backend_copy
grzuy Aug 21, 2023
e44868d
backend_transfer
grzuy Aug 21, 2023
6988885
enable behaviour
grzuy Aug 21, 2023
d36aca6
f64
grzuy Aug 21, 2023
be7b29d
f32
grzuy Aug 21, 2023
26008e9
u8
grzuy Aug 21, 2023
a04345c
more scalar tensor types
grzuy Aug 21, 2023
89b84c4
clean
grzuy Aug 21, 2023
fe6f41e
clean
grzuy Aug 21, 2023
55a0693
handle errors from_binary native
grzuy Aug 22, 2023
c8ec618
handle errors to_binary native
grzuy Aug 22, 2023
d868284
no panic in tuple_to_vec
grzuy Aug 22, 2023
753f55b
better comment
grzuy Aug 22, 2023
1a6ee73
move ex tensor to mod
grzuy Aug 22, 2023
8a54be4
removes unnecessary pub resource
grzuy Aug 22, 2023
b551040
reorder structs
grzuy Aug 22, 2023
00515b4
removes unnecessary pub tensor field
grzuy Aug 22, 2023
5e08ecd
remove unnecessary pub TensorRef
grzuy Aug 22, 2023
1423ca5
removes unnecessary TensorRef::new
grzuy Aug 22, 2023
b3d2a43
refactor mods
grzuy Aug 22, 2023
801ceb7
update candle-core to v1.0.2
grzuy Aug 22, 2023
384d36c
support s64 after support added in candle
grzuy Aug 23, 2023
0e268ea
test
grzuy Aug 23, 2023
6800a05
support half precision float - f16 and bf16
grzuy Aug 23, 2023
2b68418
make clear which types no yet supported
grzuy Aug 23, 2023
2c4721d
candlex tensor add
grzuy Aug 23, 2023
010017e
candlex Nx.multiply
grzuy Aug 23, 2023
1ef1244
candlex tensors access
grzuy Aug 24, 2023
2bdd672
candlex iota
grzuy Aug 24, 2023
4fd3328
named dimensions
grzuy Aug 24, 2023
4250835
tril/u
grzuy Aug 28, 2023
2c4f412
candlex max/min
grzuy Aug 28, 2023
c11408a
candlex broadcast
grzuy Aug 28, 2023
2f8f9bd
improve from_nx
grzuy Aug 29, 2023
4b5065b
tests for concatenate
grzuy Aug 29, 2023
d729dd6
cargo fmt
grzuy Aug 29, 2023
bc5774f
support iota with float
grzuy Aug 29, 2023
90da90b
support concatenate of different type
grzuy Aug 29, 2023
de86886
broadcast add
grzuy Aug 29, 2023
021b3c6
non native bitwise ops
grzuy Aug 29, 2023
5918e85
less
grzuy Aug 29, 2023
19c51a7
less_equal
grzuy Aug 29, 2023
ad2398d
non native left_shift
grzuy Aug 29, 2023
f34799b
non native right_shift
grzuy Aug 29, 2023
bc0fa6c
bitcast
grzuy Aug 29, 2023
8c1d8e8
non native erf_inv
grzuy Aug 29, 2023
2217473
candlex lin reg example
grzuy Aug 29, 2023
54b8db3
use rust macro to define repetitive binary nifs
grzuy Aug 30, 2023
ba52ca1
eye
grzuy Aug 30, 2023
19f3215
negate
grzuy Aug 30, 2023
446fc8e
wip dot
grzuy Aug 30, 2023
9f7c26d
removes unnecessary elixir broadcasting for a few binary ops already …
grzuy Aug 31, 2023
3694942
prefer direct native call if possible
grzuy Aug 31, 2023
b98c617
prefer to flag as unsupported for now instaed of backend transfer
grzuy Aug 31, 2023
a2285d7
cargo fmt
grzuy Aug 31, 2023
2de0a23
mix format
grzuy Aug 31, 2023
86027f5
fix typo
grzuy Aug 31, 2023
9098019
handle device backend option but still only support CPU
grzuy Aug 31, 2023
612ee71
dont inspect in test
grzuy Aug 31, 2023
9542d8c
sin
grzuy Aug 31, 2023
b170cae
exp
grzuy Aug 31, 2023
20b4ed3
cos
grzuy Aug 31, 2023
c69a2f1
log
grzuy Aug 31, 2023
2afff41
tanh
grzuy Aug 31, 2023
c6f8583
abs
grzuy Aug 31, 2023
7ff257b
sqrt
grzuy Aug 31, 2023
3d5aba4
argmax
grzuy Sep 1, 2023
bfdfd85
argmin
grzuy Sep 1, 2023
6a68279
acos
grzuy Sep 1, 2023
02fd594
asin
grzuy Sep 1, 2023
c636535
cargo fmt
grzuy Sep 1, 2023
89f29b7
mix format
grzuy Sep 1, 2023
9d371eb
cargo update
grzuy Sep 1, 2023
a254c19
tan
grzuy Sep 1, 2023
3c04142
atan
grzuy Sep 1, 2023
9f7db4f
ceil/floor
grzuy Sep 1, 2023
7292924
cbrt
grzuy Sep 1, 2023
ad5b8c4
round
grzuy Sep 1, 2023
587a410
log1p
grzuy Sep 1, 2023
42ef7b7
bitwise_and/or/xor as CustomOp2
grzuy Sep 4, 2023
c9987e0
candlex right/left_shift
grzuy Sep 4, 2023
9323754
support u32 for custom binary ops
grzuy Sep 4, 2023
23b8a06
removes repeated/commented tests
grzuy Sep 4, 2023
7941d81
candlex bitwise_not
grzuy Sep 4, 2023
e2415f6
point back to candle upstream
grzuy Sep 5, 2023
2c650b5
candlex check nx vs candle dtype
grzuy Sep 5, 2023
b467c72
candlex is_infinity
grzuy Sep 6, 2023
ab244b8
more flexible op macros
grzuy Sep 6, 2023
c86fc51
mix format
grzuy Sep 6, 2023
3d0b46b
cargo fmt
grzuy Sep 6, 2023
e9a5698
candlex logical_or
grzuy Sep 6, 2023
b3cd336
candlex erf_inv
grzuy Sep 6, 2023
db08bbd
support erf_inv for f32
grzuy Sep 6, 2023
cd20b8f
support f16/bf16 erf_inv
grzuy Sep 6, 2023
6faae6f
better error message
grzuy Sep 6, 2023
a8b0288
ensure Candlex tensor matches type of native candle Tensor
grzuy Sep 6, 2023
6ebcc81
a few more test cases
grzuy Sep 7, 2023
8f69e1a
test 2-D tensors dot product
grzuy Sep 8, 2023
713f20d
commented tests for later
grzuy Sep 8, 2023
5814191
more clear about what dot is currently supported
grzuy Sep 8, 2023
e13bdb9
support dot/6 with axes [0] and [0]
grzuy Sep 8, 2023
3379899
support dot/6 with axes [0] and [1]
grzuy Sep 8, 2023
547daf9
sum/2
grzuy Sep 8, 2023
19dc54f
uncomment linear regression
grzuy Sep 8, 2023
afa4aad
divide/2
grzuy Sep 8, 2023
f35d648
to_batched/2
grzuy Sep 8, 2023
289ebb7
sigmoid/1
grzuy Sep 8, 2023
93597db
candlex support u64 using candle i64
grzuy Sep 11, 2023
4de34e3
candlex show device on inspect
grzuy Sep 11, 2023
5329b42
candlex mnist example
grzuy Sep 11, 2023
ceea256
cargo fmt
grzuy Sep 11, 2023
5bf1d16
mean
grzuy Sep 12, 2023
2779dfe
divide integer
grzuy Sep 12, 2023
155f6eb
fix sum out tensor type
grzuy Sep 12, 2023
79f02c1
cargo update
grzuy Sep 12, 2023
6ea8675
mix format
grzuy Sep 12, 2023
c209f52
candlex logical_xor
grzuy Sep 12, 2023
c8b8a2c
candlex float pow
grzuy Sep 14, 2023
719a382
candlex greater
grzuy Sep 14, 2023
b5f945d
Merge branch 'main' into candlex
grzuy Sep 14, 2023
b32e4fa
candlex to_batched (repeat)
grzuy Sep 15, 2023
c92c6b8
candlex conv (partially)
grzuy Sep 18, 2023
89bb0a3
candlex rsqrt
grzuy Sep 18, 2023
36fba4b
Merge branch 'main' into candlex
grzuy Sep 18, 2023
f506c31
candlex reduce_max
grzuy Sep 19, 2023
d21ee65
candlex take_along_axis
grzuy Sep 20, 2023
b61be28
candlex iota with axis argument
grzuy Sep 20, 2023
fe64758
Merge branch 'main' into candlex
grzuy Sep 20, 2023
4be4f1a
mix format
grzuy Sep 20, 2023
ff833d1
cargo fmt
grzuy Sep 20, 2023
0166279
cargo update
grzuy Sep 20, 2023
1dcdedc
decent CUDA support of some backend functions
grzuy Aug 31, 2023
bbae52c
cargo fmt
grzuy Sep 22, 2023
55c76d4
cuda: implement custom ops
grzuy Sep 22, 2023
3dd0a4a
cuda use as much device funs as possible
grzuy Sep 27, 2023
9cb36e5
merge 2 custom_unary_op macros into 1
grzuy Sep 28, 2023
3022e99
Merge branch 'candlex' into candlex-cuda
grzuy Sep 28, 2023
4547f34
removes unnecessary data local var
grzuy Sep 28, 2023
e5851bf
Merge branch 'candlex' into candlex-cuda
grzuy Sep 28, 2023
008cbe4
Merge branch 'main' into candlex
grzuy Sep 28, 2023
001bd81
candlex transpose
grzuy Sep 28, 2023
4f40b59
cargo update
grzuy Sep 28, 2023
2170f04
candlex partial put_slice
grzuy Sep 20, 2023
3641d94
back to candle-core upstream after PRs fixes merged
grzuy Sep 29, 2023
ccac324
candlex pad
grzuy Sep 28, 2023
cde65ce
candlex take
grzuy Sep 29, 2023
947aefa
candlex clip
grzuy Oct 3, 2023
5e740fd
Merge branch 'candlex' into candlex-cuda
grzuy Oct 3, 2023
c91d326
candlex not_equal
grzuy Oct 3, 2023
4845ec7
Merge branch 'candlex' into candlex-cuda
grzuy Oct 3, 2023
df34c1e
fix automatic order after compile
grzuy Oct 3, 2023
6307474
fix eye when backend options present
grzuy Oct 3, 2023
e9d81ec
Merge branch 'candlex' into candlex-cuda
grzuy Oct 3, 2023
02b57e2
memoize Device::new_cuda
grzuy Oct 3, 2023
97a91c1
cargo update
grzuy Oct 4, 2023
0aa97d1
replace custom rounding ops with recently-added candle-native roundin…
grzuy Oct 4, 2023
4f3c2af
cargo fmt
grzuy Oct 4, 2023
0c95417
mix format
grzuy Oct 4, 2023
b4af44a
removes unnecessary alias
grzuy Oct 4, 2023
1937cdd
fix warnings
grzuy Oct 4, 2023
27b34d5
cargo update
grzuy Oct 5, 2023
085e4e4
test binary ops between tensors in different devices
grzuy Oct 4, 2023
e5e8b96
add acosh/asinh/atanh/cosh/sinh
grzuy Oct 5, 2023
4d607cb
candlex is_nan
grzuy Oct 5, 2023
efbb099
candlex logical_and
grzuy Oct 5, 2023
8ea2d03
candlex erf/erfc
grzuy Oct 5, 2023
b274ae3
candlex expm1
grzuy Oct 5, 2023
9d009ac
candlex remainder
grzuy Oct 6, 2023
ba264f1
candlex atan2
grzuy Oct 6, 2023
52e9806
candlex gather for tensor of rank=1
grzuy Oct 6, 2023
c0b8df6
candlex indexed_add for tensor of rank=1
grzuy Oct 6, 2023
12c011f
candlex reduce_min
grzuy Oct 6, 2023
ec17e7d
cargo fmt
grzuy Oct 6, 2023
15888ba
candlex quotient
grzuy Oct 6, 2023
b687f17
candlex sign
grzuy Oct 6, 2023
1d47f1e
fix remainder in cuda
grzuy Oct 6, 2023
b4f8fe9
cuda sign i64
grzuy Oct 6, 2023
1222d86
fix cuda remainder integer
grzuy Oct 6, 2023
45f8cf7
candlex put_slice, support longer start_indices
grzuy Oct 6, 2023
94ac2c2
add error impl for missing backend callbacks
grzuy Oct 6, 2023
e00b9f3
fix warning
grzuy Oct 6, 2023
7fba195
Merge branch 'main' into candlex
grzuy Nov 3, 2023
405a081
update with upstream
grzuy Nov 3, 2023
5a6f3cd
Merge branch 'main' into candlex
grzuy Nov 3, 2023
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
5 changes: 5 additions & 0 deletions candlex/.formatter.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Used by "mix format"
[
import_deps: [:nx],
inputs: ["{mix,.formatter}.exs", "{config,lib,test}/**/*.{ex,exs}"]
]
29 changes: 29 additions & 0 deletions candlex/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
# The directory Mix will write compiled artifacts to.
/_build/

# If you run "mix test --cover", coverage assets end up here.
/cover/

# The directory Mix downloads your dependencies sources to.
/deps/

# Where third-party dependencies like ExDoc output generated docs.
/doc/

# Ignore .fetch files in case you like to edit your project deps locally.
/.fetch

# If the VM crashes, it generates a dump, let's ignore it too.
erl_crash.dump

# Also ignore archive artifacts (built via "mix archive.build").
*.ez

# Ignore package tarball (built via "mix hex.build").
candlex-*.tar

# Temporary files, for example, from tests.
/tmp/

# Shared objects build by Rust.
*.so
14 changes: 14 additions & 0 deletions candlex/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).

## [Unreleased]

## [0.1.2] - 2023-10-30

### Added

- Precompiled binaries for a few CPU targets.
177 changes: 177 additions & 0 deletions candlex/LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@

Apache License
Version 2.0, January 2004
http://www.apache.org/licenses/

TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION

1. Definitions.

"License" shall mean the terms and conditions for use, reproduction,
and distribution as defined by Sections 1 through 9 of this document.

"Licensor" shall mean the copyright owner or entity authorized by
the copyright owner that is granting the License.

"Legal Entity" shall mean the union of the acting entity and all
other entities that control, are controlled by, or are under common
control with that entity. For the purposes of this definition,
"control" means (i) the power, direct or indirect, to cause the
direction or management of such entity, whether by contract or
otherwise, or (ii) ownership of fifty percent (50%) or more of the
outstanding shares, or (iii) beneficial ownership of such entity.

"You" (or "Your") shall mean an individual or Legal Entity
exercising permissions granted by this License.

"Source" form shall mean the preferred form for making modifications,
including but not limited to software source code, documentation
source, and configuration files.

"Object" form shall mean any form resulting from mechanical
transformation or translation of a Source form, including but
not limited to compiled object code, generated documentation,
and conversions to other media types.

"Work" shall mean the work of authorship, whether in Source or
Object form, made available under the License, as indicated by a
copyright notice that is included in or attached to the work
(an example is provided in the Appendix below).

"Derivative Works" shall mean any work, whether in Source or Object
form, that is based on (or derived from) the Work and for which the
editorial revisions, annotations, elaborations, or other modifications
represent, as a whole, an original work of authorship. For the purposes
of this License, Derivative Works shall not include works that remain
separable from, or merely link (or bind by name) to the interfaces of,
the Work and Derivative Works thereof.

"Contribution" shall mean any work of authorship, including
the original version of the Work and any modifications or additions
to that Work or Derivative Works thereof, that is intentionally
submitted to Licensor for inclusion in the Work by the copyright owner
or by an individual or Legal Entity authorized to submit on behalf of
the copyright owner. For the purposes of this definition, "submitted"
means any form of electronic, verbal, or written communication sent
to the Licensor or its representatives, including but not limited to
communication on electronic mailing lists, source code control systems,
and issue tracking systems that are managed by, or on behalf of, the
Licensor for the purpose of discussing and improving the Work, but
excluding communication that is conspicuously marked or otherwise
designated in writing by the copyright owner as "Not a Contribution."

"Contributor" shall mean Licensor and any individual or Legal Entity
on behalf of whom a Contribution has been received by Licensor and
subsequently incorporated within the Work.

2. Grant of Copyright License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
copyright license to reproduce, prepare Derivative Works of,
publicly display, publicly perform, sublicense, and distribute the
Work and such Derivative Works in Source or Object form.

3. Grant of Patent License. Subject to the terms and conditions of
this License, each Contributor hereby grants to You a perpetual,
worldwide, non-exclusive, no-charge, royalty-free, irrevocable
(except as stated in this section) patent license to make, have made,
use, offer to sell, sell, import, and otherwise transfer the Work,
where such license applies only to those patent claims licensable
by such Contributor that are necessarily infringed by their
Contribution(s) alone or by combination of their Contribution(s)
with the Work to which such Contribution(s) was submitted. If You
institute patent litigation against any entity (including a
cross-claim or counterclaim in a lawsuit) alleging that the Work
or a Contribution incorporated within the Work constitutes direct
or contributory patent infringement, then any patent licenses
granted to You under this License for that Work shall terminate
as of the date such litigation is filed.

4. Redistribution. You may reproduce and distribute copies of the
Work or Derivative Works thereof in any medium, with or without
modifications, and in Source or Object form, provided that You
meet the following conditions:

(a) You must give any other recipients of the Work or
Derivative Works a copy of this License; and

(b) You must cause any modified files to carry prominent notices
stating that You changed the files; and

(c) You must retain, in the Source form of any Derivative Works
that You distribute, all copyright, patent, trademark, and
attribution notices from the Source form of the Work,
excluding those notices that do not pertain to any part of
the Derivative Works; and

(d) If the Work includes a "NOTICE" text file as part of its
distribution, then any Derivative Works that You distribute must
include a readable copy of the attribution notices contained
within such NOTICE file, excluding those notices that do not
pertain to any part of the Derivative Works, in at least one
of the following places: within a NOTICE text file distributed
as part of the Derivative Works; within the Source form or
documentation, if provided along with the Derivative Works; or,
within a display generated by the Derivative Works, if and
wherever such third-party notices normally appear. The contents
of the NOTICE file are for informational purposes only and
do not modify the License. You may add Your own attribution
notices within Derivative Works that You distribute, alongside
or as an addendum to the NOTICE text from the Work, provided
that such additional attribution notices cannot be construed
as modifying the License.

You may add Your own copyright statement to Your modifications and
may provide additional or different license terms and conditions
for use, reproduction, or distribution of Your modifications, or
for any such Derivative Works as a whole, provided Your use,
reproduction, and distribution of the Work otherwise complies with
the conditions stated in this License.

5. Submission of Contributions. Unless You explicitly state otherwise,
any Contribution intentionally submitted for inclusion in the Work
by You to the Licensor shall be under the terms and conditions of
this License, without any additional terms or conditions.
Notwithstanding the above, nothing herein shall supersede or modify
the terms of any separate license agreement you may have executed
with Licensor regarding such Contributions.

6. Trademarks. This License does not grant permission to use the trade
names, trademarks, service marks, or product names of the Licensor,
except as required for reasonable and customary use in describing the
origin of the Work and reproducing the content of the NOTICE file.

7. Disclaimer of Warranty. Unless required by applicable law or
agreed to in writing, Licensor provides the Work (and each
Contributor provides its Contributions) on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
implied, including, without limitation, any warranties or conditions
of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
PARTICULAR PURPOSE. You are solely responsible for determining the
appropriateness of using or redistributing the Work and assume any
risks associated with Your exercise of permissions under this License.

8. Limitation of Liability. In no event and under no legal theory,
whether in tort (including negligence), contract, or otherwise,
unless required by applicable law (such as deliberate and grossly
negligent acts) or agreed to in writing, shall any Contributor be
liable to You for damages, including any direct, indirect, special,
incidental, or consequential damages of any character arising as a
result of this License or out of the use or inability to use the
Work (including but not limited to damages for loss of goodwill,
work stoppage, computer failure or malfunction, or any and all
other commercial damages or losses), even if such Contributor
has been advised of the possibility of such damages.

9. Accepting Warranty or Additional Liability. While redistributing
the Work or Derivative Works thereof, You may choose to offer,
and charge a fee for, acceptance of support, warranty, indemnity,
or other liability obligations and/or rights consistent with this
License. However, in accepting such obligations, You may act only
on Your own behalf and on Your sole responsibility, not on behalf
of any other Contributor, and only if You agree to indemnify,
defend, and hold each Contributor harmless for any liability
incurred by, or claims asserted against, such Contributor by reason
of your accepting any such warranty or additional liability.

END OF TERMS AND CONDITIONS
89 changes: 89 additions & 0 deletions candlex/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
# Candlex

[![ci](https://github.com/mimiquate/candlex/actions/workflows/ci.yml/badge.svg?branch=main)](https://github.com/mimiquate/candlex/actions?query=branch%3Amain)
[![Hex.pm](https://img.shields.io/hexpm/v/candlex.svg)](https://hex.pm/packages/candlex)
[![Docs](https://img.shields.io/badge/docs-gray.svg)](https://hexdocs.pm/candlex)

An `Nx` [backend](https://hexdocs.pm/nx/Nx.html#module-backends) for [candle](https://huggingface.github.io/candle) machine learning minimalist framework

## Installation

If [available in Hex](https://hex.pm/docs/publish), the package can be installed
by adding `candlex` to your list of dependencies in `mix.exs`:

```elixir
def deps do
[
{:candlex, "~> 0.1.2"}
]
end
```

Documentation can be generated with [ExDoc](https://github.com/elixir-lang/ex_doc)
and published on [HexDocs](https://hexdocs.pm). Once published, the docs can
be found at <https://hexdocs.pm/candlex>.

## Usage

Just configure Nx to default to Candlex backend in your configuration:

```elixir
# Possibly config/runtime.exs

config :nx, default_backend: Candlex.Backend
```

or in your scripts, precede all your Nx operations with:

```elixir
Nx.default_backend(Candlex.Backend)
```

More details in [Nx backends](https://hexdocs.pm/nx/Nx.html#module-backends)

#### `CANDLEX_NIF_BUILD`

Defaults to `false`. If `true` the native binary is built locally, which may be useful
if no precompiled binary is available for your target environment. Once set, you
must run `mix deps.clean candlex --build` explicitly to force to recompile.
Building has a number of dependencies, see *Building from source* below.

## Building from source

To build the native binary locally you need to set `CANDLEX_NIF_BUILD=true`.
Keep in mind that the compilation usually takes time.

You will need the following installed in your system for the compilation:

* [Git](https://git-scm.com) for fetching candle-core source
* [Rust](https://www.rust-lang.org) with cargo to compile rustler NIFs

## Releasing

To publish a new version of this package:

1. Update `@version` in `mix.exs` and `project-version` in `.github/workflows/binaries.yml`.
1. `git tag -s <tag-version>` to create new signed tag.
1. `git push origin <tag-version>` to push the tag.
1. Wait for the `binaries.yml` GitHub workflow to build all the NIF binaries.
1. `mix rustler_precompiled.download Candlex.Native --all --print` to generate binaries checksums locally.
1. `rm -r native/candlex/target` to leave out rust crate build artifacts from published elixir package.
1. `mix hex.build --unpack` to check the package includes the correct files.
1. Publish the release from draft in GitHub.
1. `mix hex.publish` to publish package to Hex.pm.

## License

Copyright 2023 Mimiquate

Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
17 changes: 17 additions & 0 deletions candlex/config/config.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
import Config

enable_cuda =
case System.get_env("CUDA") do
nil -> System.find_executable("nvcc") && System.find_executable("nvidia-smi")
"false" -> false
_ -> true
end

crate_features =
if enable_cuda do
[:cuda]
else
[]
end

config :candlex, crate_features: crate_features
Loading