Skip to content

Commit

Permalink
Merge pull request #79 from Zinoex/fm/implicit_sink_state
Browse files Browse the repository at this point in the history
Implicit sink state
  • Loading branch information
Zinoex authored Jan 14, 2025
2 parents 9400c06 + 9249073 commit 5b44edb
Show file tree
Hide file tree
Showing 8 changed files with 964 additions and 208 deletions.
2 changes: 1 addition & 1 deletion Project.toml
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
name = "IntervalMDP"
uuid = "051c988a-e73c-45a4-90ec-875cac0402c7"
authors = ["Frederik Baymler Mathiesen <[email protected]> and contributors"]
version = "0.4.1"
version = "0.4.2"

[deps]
JSON = "682c06a0-de6a-54ab-a142-c8b1cf79cde6"
Expand Down
6 changes: 3 additions & 3 deletions ext/cuda/bellman/dense.jl
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,11 @@ function IntervalMDP.bellman!(
# - squeeze as many states as possible in a block
# - use shared memory to store the values and permutation
# - use bitonic sort to sort the values for all states in a block
wanted_threads = min(1024, 32 * length(Vres))
wanted_threads = min(1024, 32 * num_source(prob))

threads = min(max_threads, wanted_threads)
warps = div(threads, 32)
blocks = min(2^16 - 1, cld(length(Vres), warps))
blocks = min(2^16 - 1, cld(num_source(prob), warps))
shmem =
length(V) * (sizeof(Int32) + sizeof(Tv)) +
warps * workspace.max_actions * sizeof(Tv)
Expand Down Expand Up @@ -132,7 +132,7 @@ end
wid = fld1(threadIdx().x, warpsize())

j = wid + (blockIdx().x - one(Int32)) * warps
@inbounds while j <= length(Vres)
@inbounds while j <= num_source(prob)
state_dense_omaximization!(
action_workspace,
strategy_cache,
Expand Down
8 changes: 4 additions & 4 deletions ext/cuda/bellman/sparse.jl
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ function try_small_sparse_bellman!(
# TODO: Dynamically maximize the number of states per block

threads = desired_warps * 32
blocks = min(2^16 - 1, cld(length(Vres), desired_warps))
blocks = min(2^16 - 1, cld(num_source(prob), desired_warps))

kernel(
workspace,
Expand Down Expand Up @@ -169,7 +169,7 @@ function small_sparse_bellman_kernel!(

# Grid-stride loop
j = wid + (blockIdx().x - one(Int32)) * nwarps
while j <= length(Vres)
while j <= num_source(prob)
state_small_sparse_omaximization!(
action_workspace,
value_ws,
Expand Down Expand Up @@ -463,7 +463,7 @@ function try_large_sparse_bellman!(
wanted_threads = min(1024, nextwarp(device(), cld(workspace.max_nonzeros, 2)))

threads = min(max_threads, wanted_threads)
blocks = min(2^16 - 1, length(Vres))
blocks = min(2^16 - 1, num_source(prob))

kernel(
T1,
Expand Down Expand Up @@ -507,7 +507,7 @@ function large_sparse_bellman_kernel!(

# Grid-stride loop
j = blockIdx().x
@inbounds while j <= length(Vres)
@inbounds while j <= num_source(prob)
state_sparse_omaximization!(
action_workspace,
value_ws,
Expand Down
14 changes: 11 additions & 3 deletions src/models/IntervalMarkovDecisionProcess.jl
Original file line number Diff line number Diff line change
Expand Up @@ -151,15 +151,23 @@ function checksize_imdp!(p::IntervalProbabilities, stateptr::AbstractVector{Int3
throw(ArgumentError("The number of actions per state must be positive."))
end

if num_target(p) != num_states
if num_states > num_target(p)
throw(
DimensionMismatch(
"The number of target states ($(num_target(p))) is not equal to the number of states in the stateptr $(num_states).",
"The number of target states ($(num_target(p))) is less than the number of states in the stateptr $(num_states).",
),
)
end

return Int32(num_states)
if stateptr[end] - 1 != num_source(p)
throw(
DimensionMismatch(
"The number of source states ($(num_source(p))) must be equal to the number of states in the stateptr $(num_states).",
),
)
end

return Int32(num_target(p))
end

"""
Expand Down
8 changes: 5 additions & 3 deletions src/models/OrthogonalIntervalMarkovDecisionProcess.jl
Original file line number Diff line number Diff line change
Expand Up @@ -116,15 +116,17 @@ function checksize_imdp!(
throw(ArgumentError("The number of actions per state must be positive."))
end

if prod(num_target, p.probs) != num_states
if num_states > prod(num_target, p.probs)
throw(
DimensionMismatch(
"The number of target states ($(prod(num_target, p.probs)) = $(map(num_target, p.probs))) is not equal to the number of states in the problem $(num_states).",
"The number of target states ($(prod(num_target, p.probs)) = $(map(num_target, p.probs))) is less than the number of states in the problem $(num_states).",
),
)
end

return Int32(num_states)
# TODO:: Check that source_dims match stateptr

return Int32(prod(num_target, p.probs))
end

"""
Expand Down
Loading

2 comments on commit 5b44edb

@Zinoex
Copy link
Owner Author

@Zinoex Zinoex commented on 5b44edb Jan 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@JuliaRegistrator
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Registration pull request created: JuliaRegistries/General/122973

Tip: Release Notes

Did you know you can add release notes too? Just add markdown formatted text underneath the comment after the text
"Release notes:" and it will be added to the registry PR, and if TagBot is installed it will also be added to the
release that TagBot creates. i.e.

@JuliaRegistrator register

Release notes:

## Breaking changes

- blah

To add them here just re-invoke and the PR will be updated.

Tagging

After the above pull request is merged, it is recommended that a tag is created on this repository for the registered package version.

This will be done automatically if the Julia TagBot GitHub Action is installed, or can be done manually through the github interface, or via:

git tag -a v0.4.2 -m "<description of version>" 5b44edb632e9a4056c3fb50973673230aa1a5159
git push origin v0.4.2

Please sign in to comment.