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

Refactor #2

Merged
merged 15 commits into from
Apr 25, 2024
40 changes: 22 additions & 18 deletions .github/workflows/CI.yml
Original file line number Diff line number Diff line change
@@ -1,37 +1,41 @@
name: CI
on:
- push
- pull_request
pull_request:
branches:
- master
workflow_dispatch:
jobs:
test:
name: Julia ${{ matrix.version }} - ${{ matrix.os }} - ${{ matrix.arch }}
runs-on: ${{ matrix.os }}
name: Julia ${{ matrix.version }}
runs-on: [self-hosted,titan,gpu]
strategy:
fail-fast: false
matrix:
version:
- '1.7'
- '1.8'
os:
- ubuntu-latest
- macOS-latest
arch:
- x64
- '1.9'
- '1.10'
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/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
# with:
# file: lcov.info
- uses: coverallsapp/github-action@master
with:
github-token: ${{ secrets.GITHUB_TOKEN }}
path-to-lcov: lcov.info
path-to-lcov: lcov.info
parallel: true
flag-name: run-${{ matrix.version }}
finish:
needs: test
runs-on: [self-hosted,titan]
steps:
- name: Close parallel build
uses: coverallsapp/github-action@v1
with:
parallel-finished: true
carryforward: "run-1.9,run-1.10"
Empty file removed .github/workflows/CompatHelper.yml
Empty file.
30 changes: 9 additions & 21 deletions Project.toml
Original file line number Diff line number Diff line change
@@ -1,37 +1,25 @@
name = "SpinGlassExhaustive"
uuid = "a894d7c4-7f54-4100-9d77-d00d924adeb3"
uuid = "40b79dc1-e706-48b7-a5ed-397fb6101cb7"
authors = ["Bartłomiej Gardas <[email protected]>", "Dariusz Kurzyk <[email protected]>", "Łukasz Pawela <[email protected]>"]
version = "0.1.7"
version = "1.0.0"

[deps]
BenchmarkTools = "6e4b80f9-dd63-53aa-95a3-0cdb28fa8baf"
Bits = "1654ce90-6ed3-553a-957f-9452c3a40996"
CUDA = "052768ef-5323-5732-b1bb-66c8b64840ba"
Distributions = "31c24e10-a181-5473-b8eb-7969acd0382f"
DocStringExtensions = "ffbed154-4ef7-542d-bbb7-c09d3a79fcae"
Flux = "587475ba-b771-5e3f-ad9e-33799f191a9c"
Graphs = "86223c79-3864-5bf0-83f7-82e725a168b6"
LabelledGraphs = "605abd48-4d17-4660-b914-d4df33194460"
LightGraphs = "093fc24a-ae57-5d10-9952-331d41423f4d"
LinearAlgebra = "37e2e46d-f89d-539d-b4ee-838fcccc9c8e"
LinearMaps = "7a12625a-238d-50fd-b39a-03d52299707e"
MetaGraphs = "626554b9-1ddb-594c-aa3c-2596fe9399a5"
SortingAlgorithms = "a2af1166-a08f-5f64-846c-94a0d3cef48c"
SpinGlassEngine = "0563570f-ea1b-4080-8a64-041ac6565a4e"
SpinGlassNetworks = "b7f6bd3e-55dc-4da6-96a9-ef9dbec6ac19"

[compat]
BenchmarkTools = "1.3"
Bits = "0.2"
CUDA = "3.12"
Distributions = "0.25"
DocStringExtensions = "0.8.6"
Flux = "0.13"
LabelledGraphs = "0.3"
LightGraphs = "1.3"
LinearMaps = "3.8"
MetaGraphs = "0.6, 0.7"
SortingAlgorithms = "1.0"
julia = "1.8, 1.9"
CUDA = "5"
DocStringExtensions = "0.9"
Graphs = "1.9"
LabelledGraphs = "0.4"
SpinGlassNetworks = "1.1.2"
julia = "1.9, 1.10"

[extras]
Logging = "56ddb016-857b-54e1-b83d-db4d58db5568"
Expand Down
7 changes: 5 additions & 2 deletions benchmarks/bf_bench.jl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
using SpinGlassNetworks
using LightGraphs
using Graphs
using SpinGlassExhaustive
using LinearAlgebra
using CUDA
Expand All @@ -13,6 +13,7 @@ function bench_cpu(instance::String, max_states::Int=100)
ig = ising_graph(instance)
cl = split_into_clusters(ig, super_square_lattice((m, n, t)))
@time sp = brute_force(cl[1, 1], num_states=max_states)
Spectrum
sp
end

Expand All @@ -36,7 +37,9 @@ sp_gpu = bench_gpu("$(@__DIR__)/pegasus_droplets/2_2_3_00.txt")
sp_gpu = bench_gpu("$(@__DIR__)/pegasus_droplets/2_2_3_00.txt")

@assert sp_gpu.energies ≈ sp_cpu.energies
@assert sp_gpu.states == sp_cpu.states
@show sp_gpu.states
@show sp_cpu.states[1]
@assert sp_gpu.states == sp_cpu.states[1]

"""
$(SIGNATURES)
Expand Down
24 changes: 12 additions & 12 deletions docs/src/man/details.md
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ k = 2

energies = CUDA.zeros(2^N);

threadsPerBlock = 2^k
blocksPerGrid = 2^(N-k)
threads = 512
blocks = cld(N, threads)

@cuda blocks=(blocksPerGrid) threads=(threadsPerBlock) SpinGlassExhaustive.kernel_qubo(cu_qubo, energies);
@cuda blocks=blocks threads=threads SpinGlassExhaustive.kernel_qubo(cu_qubo, energies);

states = sortperm(energies);
energies[states];
Expand All @@ -49,10 +49,10 @@ k = 2

energies = CUDA.zeros(2^N);

threadsPerBlock = 2^k
blocksPerGrid = 2^(N-k)
threads = 512
blocks = cld(N, threads)

@cuda blocks=(blocksPerGrid) threads=(threadsPerBlock) SpinGlassExhaustive.kernel(cu_graph, energies);
@cuda blocks=blocks threads=threads SpinGlassExhaustive.kernel(cu_graph, energies);

states = sortperm(energies);
energies[states]
Expand All @@ -70,10 +70,10 @@ energies = CUDA.zeros(2^N);
part_st = CUDA.zeros(2^(N-k));
part_lst = CUDA.zeros(2^(N-k));

threadsPerBlock = 2^k
blocksPerGrid = 2^(N-k)
threads = 512
blocks = cld(N, threads)

@cuda blocks=(blocksPerGrid) threads=(threadsPerBlock) SpinGlassExhaustive.kernel_part(cu_graph, energies, part_lst, part_st);
@cuda blocks=blocks threads=threads SpinGlassExhaustive.kernel_part(cu_graph, energies, part_lst, part_st);

idx = sortperm(part_lst);
states = part_st[idx];
Expand Down Expand Up @@ -109,16 +109,16 @@ lowest_d = CUDA.zeros(Float64, how_many*2);
lowest_states_d = CUDA.zeros(Int64, how_many*2);

k = 2
threadsPerBlock = 2^k
blocksPerGrid = 2^(chunk_size-k)
threads = 512
blocks = cld(chunk_size, threads)



for i in 1:2^(N-chunk_size)

idx = (i-1)*(2^chunk_size) + 1

@cuda blocks=(blocksPerGrid) threads=(threadsPerBlock) SpinGlassExhaustive.kernel_bucket(J_dev, energies_d, idx)
@cuda blocks=blocks threads=threads SpinGlassExhaustive.kernel_bucket(J_dev, energies_d, idx)

states_d = sortperm(energies_d)[1:how_many]

Expand Down
12 changes: 6 additions & 6 deletions examples/experiment.jl
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ function exp_exhaustive_search()
graph = generate_random_graph(N)
cu_graph = graph |> cu

ig = SpinGlassEngine.ising_graph(graph_to_dict(cu_graph))
ig = ising_graph(graph_to_dict(cu_graph))

exhaustive_search(ig)
end
Expand All @@ -15,7 +15,7 @@ function exp_bucket_exhaustive_search()
graph = generate_random_graph(N)
cu_graph = graph |> cu

ig = SpinGlassEngine.ising_graph(graph_to_dict(cu_graph))
ig = ising_graph(graph_to_dict(cu_graph))

exhaustive_search_bucket(ig)
end
Expand All @@ -25,7 +25,7 @@ function exp_partial_exhaustive_search()
graph = generate_random_graph(N)
cu_graph = graph |> cu

ig = SpinGlassEngine.ising_graph(graph_to_dict(cu_graph))
ig = ising_graph(graph_to_dict(cu_graph))

partial_exhaustive_search(ig)
end
Expand All @@ -44,7 +44,7 @@ function exp_qubo()
threadsPerBlock::Int64 = 2^k
blocksPerGrid::Int64 = 2^(N-k)

@cuda blocks=(blocksPerGrid) threads=(threadsPerBlock) kernel_qubo(cu_qubo, energies)
@cuda blocks=blocks threads=threads kernel_qubo(cu_qubo, energies)

# sort!(energies)
# or
Expand All @@ -67,7 +67,7 @@ function exp_ising()
threadsPerBlock::Int64 = 2^k
blocksPerGrid::Int64 = 2^(N-k)

@cuda blocks=(blocksPerGrid) threads=(threadsPerBlock) kernel(cu_graph, energies)
@cuda blocks=blocks threads=threads kernel(cu_graph, energies)

sort!(energies)

Expand All @@ -91,7 +91,7 @@ function exp_ising_part()
threadsPerBlock::Int64 = 2^k
blocksPerGrid::Int64 = 2^(N-k)

@cuda blocks=(blocksPerGrid) threads=(threadsPerBlock) kernel_part(cu_graph, energies, part_lst, part_st)
@cuda blocks=blocks threads=threads kernel_part(cu_graph, energies, part_lst, part_st)

sort!(part_lst)

Expand Down
13 changes: 6 additions & 7 deletions src/SpinGlassExhaustive.jl
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,14 @@ Main module for `SpinGlassExhaustive.jl` -- a Julia package for brute-force spin

module SpinGlassExhaustive
using SpinGlassNetworks
using Graphs
using LabelledGraphs
using MetaGraphs
using CUDA
using BenchmarkTools
using Bits
using LinearAlgebra
using DocStringExtensions
using CUDA


include("bitonicsort.jl")
include("ising.jl")
include("naive.jl")
include("utils.jl")

include("ising.jl")
end
Loading
Loading