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

Cray bug workarounds for compile time bugs #146

Merged
merged 20 commits into from
Apr 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
d69d657
Add workaround to cray bug in `merge` function
ktras Apr 10, 2024
f957b91
Add workarounds for cray bugs related to associate-stmt
ktras Apr 10, 2024
27bd171
Add workaround for cray bug related to name resolution issues of a
ktras Apr 10, 2024
94e4f1e
Add workaround for cray bug around associate-stmt
ktras Apr 11, 2024
a0ae713
Add more workarounds for cray bug around associate-stmt
ktras Apr 11, 2024
23a0294
Update macros in `training_configuration_s.F90` to include
ktras Apr 11, 2024
876ae89
Update more macros in `training_configuration_s.F90` to include
ktras Apr 11, 2024
76f42b2
Add workaround to cray bug with associate-stmt
ktras Apr 12, 2024
8c136fe
Add more workarounds to cray bug with associate-stmt
ktras Apr 12, 2024
a5b6c07
Add workaround to cray bug with reshape function call
ktras Apr 12, 2024
37f2391
Add more workarounds to cray bug with associate-stmt
ktras Apr 12, 2024
60e2453
Add more workarounds to cray bug with associate-stmt
ktras Apr 12, 2024
8c593ad
Add another workaround to cray bug with associate-stmt
ktras Apr 12, 2024
515688a
Add more workarounds to cray bug with associate-stmt
ktras Apr 15, 2024
1bf26cb
Add more workarounds to cray bug with associate-stmt
ktras Apr 16, 2024
8abe8ae
Add workaround to cray bug for a 3d constant array declaration
ktras Apr 18, 2024
c3210e2
Add workaround for cray bug with nested implied do-loops and
ktras Apr 18, 2024
1399283
Add workarounds for runtime cray bug with associate-stmt
ktras Apr 18, 2024
97a6a0b
Add workaround for runtime cray bug with associate-stmt
ktras Apr 18, 2024
b3a9043
Add workarounds for runtime cray bug with associate-stmt
ktras Apr 18, 2024
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
8 changes: 7 additions & 1 deletion example/learn-addition.F90
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,19 @@ program learn_addition
block
real, parameter :: tolerance = 1.E-06
integer p

#ifdef _CRAYFTN
type(tensor_t), allocatable :: network_outputs(:)
network_outputs = trainable_engine%infer(inputs)
#else
associate(network_outputs => trainable_engine%infer(inputs))
#endif
print "(a,69x,a)"," Outputs", "| Desired outputs"
do p = 1, num_pairs
print "(6G13.5, a1, 6G13.5)",network_outputs(p)%values(), "|", desired_outputs(p)%values()
end do
#ifndef _CRAYFTN
end associate
#endif
end block

end associate
Expand Down
8 changes: 7 additions & 1 deletion example/learn-exponentiation.F90
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,19 @@ program learn_exponentiation
block
real, parameter :: tolerance = 1.E-06
integer p

#ifdef _CRAYFTN
type(tensor_t), allocatable :: network_outputs(:)
network_outputs = trainable_engine%infer(inputs)
#else
associate(network_outputs => trainable_engine%infer(inputs))
#endif
print "(a,69x,a)"," Outputs", "| Desired outputs"
do p = 1, num_pairs
print "(6G13.5, a1, 6G13.5)",network_outputs(p)%values(), "|", desired_outputs(p)%values()
end do
#ifndef _CRAYFTN
end associate
#endif
end block

end associate
Expand Down
8 changes: 7 additions & 1 deletion example/learn-microphysics-procedures.F90
Original file line number Diff line number Diff line change
Expand Up @@ -120,13 +120,19 @@ program learn_microphysics_procedures
report_network_performance: &
block
integer p

#ifdef _CRAYFTN
type(tensor_t), allocatable :: network_outputs(:)
network_outputs = trainable_engine%infer(inputs)
#else
associate(network_outputs => trainable_engine%infer(inputs))
#endif
print *," Inputs (normalized) | Outputs | Desired outputs"
do p = 1, num_pairs
print "(6(G13.5,2x))", inputs(p)%values(), network_outputs(p)%values(), desired_outputs(p)%values()
end do
#ifndef _CRAYFTN
end associate
#endif
end block report_network_performance

end block
Expand Down
8 changes: 7 additions & 1 deletion example/learn-multiplication.F90
Original file line number Diff line number Diff line change
Expand Up @@ -84,13 +84,19 @@ program learn_multiplication
block
real, parameter :: tolerance = 1.E-06
integer p

#ifdef _CRAYFTN
type(tensor_t), allocatable :: network_outputs(:)
network_outputs = trainable_engine%infer(inputs)
#else
associate(network_outputs => trainable_engine%infer(inputs))
#endif
print "(a,69x,a)"," Outputs", "| Desired outputs"
do p = 1, num_pairs
print "(6G13.5, a1, 6G13.5)",network_outputs(p)%values(), "|", desired_outputs(p)%values()
end do
#ifndef _CRAYFTN
end associate
#endif
end block

end associate
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,19 @@ program learn_power_series
block
real, parameter :: tolerance = 1.E-06
integer p

#ifdef _CRAYFTN
type(tensor_t), allocatable :: network_outputs(:)
network_outputs = trainable_engine%infer(inputs)
#else
associate(network_outputs => trainable_engine%infer(inputs))
#endif
print "(a,69x,a)"," Outputs", "| Desired outputs"
do p = 1, num_pairs
print "(6G13.5, a1, 6G13.5)",network_outputs(p)%values(), "|", desired_outputs(p)%values()
end do
#ifndef _CRAYFTN
end associate
#endif
end block

end associate
Expand Down
8 changes: 7 additions & 1 deletion example/learn-saturated-mixing-ratio.F90
Original file line number Diff line number Diff line change
Expand Up @@ -119,13 +119,19 @@ program train_saturated_mixture_ratio
report_network_performance: &
block
integer p

#ifdef _CRAYFTN
type(tensor_t), allocatable :: network_outputs(:)
network_outputs = trainable_engine%infer(inputs)
#else
associate(network_outputs => trainable_engine%infer(inputs))
#endif
print *,"Inputs (normalized) | Outputs | Desired outputs"
do p = 1, num_pairs
print "(4(G13.5,2x))", inputs(p)%values(), network_outputs(p)%values(), desired_outputs(p)%values()
end do
#ifndef _CRAYFTN
end associate
#endif
end block report_network_performance

end block
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,15 @@ program print_training_configuration
use inference_engine_m, only : training_configuration_t, hyperparameters_t, network_configuration_t
use sourcery_m, only : file_t
implicit none

#ifdef _CRAYFTN
type(training_configuration_t) :: training_configuration
type(file_t) :: json_file
training_configuration = training_configuration_t( &
hyperparameters_t(mini_batches=10, learning_rate=1.5, optimizer = "adam"), &
network_configuration_t(skip_connections=.false., nodes_per_layer=[2,72,2], activation_name="sigmoid"))
json_file = file_t(training_configuration%to_json())
call json_file%write_lines()
#else
associate(training_configuration => training_configuration_t( &
hyperparameters_t(mini_batches=10, learning_rate=1.5, optimizer = "adam"), &
network_configuration_t(skip_connections=.false., nodes_per_layer=[2,72,2], activation_name="sigmoid") &
Expand All @@ -12,4 +20,5 @@ program print_training_configuration
call json_file%write_lines()
end associate
end associate
#endif
end program
8 changes: 7 additions & 1 deletion example/train-and-write.F90
Original file line number Diff line number Diff line change
Expand Up @@ -72,15 +72,21 @@ program train_and_write
block
real, parameter :: tolerance = 1.E-06
integer p

#ifdef _CRAYFTN
type(tensor_t), allocatable :: network_outputs(:)
network_outputs = trainable_engine%infer(inputs)
#else
associate(network_outputs => trainable_engine%infer(inputs))
#endif
print *," Outputs |&
Desired outputs |&
Errors"
do p = 1, num_pairs
print *,network_outputs(p)%values(),"|", inputs(p)%values(), "|", network_outputs(p)%values() - inputs(p)%values()
end do
#ifndef _CRAYFTN
end associate
#endif
end block

end associate
Expand Down
13 changes: 11 additions & 2 deletions example/write-read-infer.f90 → example/write-read-infer.F90
Original file line number Diff line number Diff line change
Expand Up @@ -30,14 +30,23 @@ function identity_network() result(inference_engine)
type(inference_engine_t) inference_engine
integer, parameter :: nodes_per_layer(*) = [2, 2, 2]
integer, parameter :: max_n = maxval(nodes_per_layer), layers = size(nodes_per_layer)

#ifdef _CRAYFTN
real(rkind), allocatable :: weights(:,:,:)
weights = reshape([real(rkind):: [1,0, 0,1], [1,0, 0,1]], [max_n, max_n, layers-1])
inference_engine = inference_engine_t( &
metadata = [string_t("Identity"), string_t("Damian Rouson"), string_t("2023-09-18"), string_t("relu"), string_t("false")], &
weights = weights, &
biases = reshape([real(rkind):: [0,0], [0,0]], [max_n, layers-1]), &
nodes = nodes_per_layer &
)
#else
inference_engine = inference_engine_t( &
metadata = [string_t("Identity"), string_t("Damian Rouson"), string_t("2023-09-18"), string_t("relu"), string_t("false")], &
weights = reshape([real(rkind):: [1,0, 0,1], [1,0, 0,1]], [max_n, max_n, layers-1]), &
biases = reshape([real(rkind):: [0,0], [0,0]], [max_n, layers-1]), &
nodes = nodes_per_layer &
)

#endif
end function

subroutine write_read_query_infer(output_file_name)
Expand Down
30 changes: 29 additions & 1 deletion src/inference_engine/inference_engine_s.F90
Original file line number Diff line number Diff line change
Expand Up @@ -40,20 +40,38 @@

allocate(a(maxval(n), input_layer:output_layer))

#ifndef _CRAYFTN
associate(normalized_inputs => self%input_range_%map_to_training_range(inputs))
a(1:n(input_layer),input_layer) = normalized_inputs%values()
end associate
#else
block
type(tensor_t) normalized_inputs
normalized_inputs = self%input_range_%map_to_training_range(inputs)
a(1:n(input_layer),input_layer) = normalized_inputs%values()
end block
#endif

feed_forward: &
do l = input_layer+1, output_layer
associate(z => matmul(w(1:n(l),1:n(l-1),l), a(1:n(l-1),l-1)) + b(1:n(l),l))
a(1:n(l),l) = self%activation_strategy_%activation(z)
end associate
end do feed_forward


#ifdef _CRAYFTN
block
type(tensor_t) :: normalized_outputs
normalized_outputs = tensor_t(a(1:n(output_layer), output_layer))
#else
associate(normalized_outputs => tensor_t(a(1:n(output_layer), output_layer)))
#endif
outputs = self%output_range_%map_from_training_range(normalized_outputs)
#ifdef _CRAYFTN
end block
#else
end associate
#endif

end associate

Expand Down Expand Up @@ -193,14 +211,24 @@ pure subroutine set_activation_strategy(inference_engine)

call assert(adjustl(lines(l)%string())=='"tensor_range": {', 'from_json: expecting "tensor_range": {', lines(l)%string())

#ifndef _CRAYFTN
associate(prototype => tensor_range_t("",[0.],[1.]))
#else
block
type(tensor_range_t) prototype
prototype = tensor_range_t("",[0.],[1.])
#endif
associate(num_lines => size(prototype%to_json()))
input_range = tensor_range_t(lines(l:l+num_lines-1))
l = l + num_lines
output_range = tensor_range_t(lines(l:l+num_lines-1))
l = l + num_lines
end associate
#ifndef _CRAYFTN
end associate
#else
end block
#endif

call assert(adjustl(lines(l)%string())=='"hidden_layers": [', 'from_json: expecting "hidden_layers": [', lines(l)%string())
l = l + 1
Expand Down
4 changes: 2 additions & 2 deletions src/inference_engine/layer_m.f90
Original file line number Diff line number Diff line change
Expand Up @@ -55,10 +55,10 @@ module function count_layers(layer) result(num_layers)
integer num_layers
end function

module function count_neurons(layer) result(neurons_per_layer)
module function count_neurons(layer) result(neurons_per_layer_result)
implicit none
class(layer_t), intent(in), target :: layer
integer, allocatable :: neurons_per_layer(:)
integer, allocatable :: neurons_per_layer_result(:)
end function

module function count_inputs(layer) result(num_inputs)
Expand Down
4 changes: 2 additions & 2 deletions src/inference_engine/layer_s.f90
Original file line number Diff line number Diff line change
Expand Up @@ -132,7 +132,7 @@

layer_ptr => layer

allocate(neurons_per_layer(0))
allocate(neurons_per_layer_result(0))

do
num_neurons = 1
Expand All @@ -142,7 +142,7 @@
neuron_ptr => neuron_ptr%next_pointer()
num_neurons = num_neurons + 1
end do
neurons_per_layer = [neurons_per_layer, num_neurons]
neurons_per_layer_result = [neurons_per_layer_result, num_neurons]
if (.not. allocated(layer_ptr%next)) exit
layer_ptr => layer_ptr%next
end do
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,15 @@

allocate(character(len=size(self%nodes_per_layer_)*char_per_elem + brackets) :: nodes_per_layer_string)

#ifdef _CRAYFTN
if (self%skip_connections_) then
write(skip_connections_string,*) "true"
else
write(skip_connections_string,*) "false"
end if
#else
write(skip_connections_string,*) trim(merge("true ","false",self%skip_connections_))
#endif
write(nodes_per_layer_string, csv) self%nodes_per_layer_

lines = [ &
Expand Down
33 changes: 32 additions & 1 deletion src/inference_engine/trainable_engine_s.F90
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,9 @@
use assert_m, only : assert
use intrinsic_array_m, only : intrinsic_array_t
use tensor_m, only : tensor_t
#ifdef _CRAYFTN
use input_output_pair_m, only : input_output_pair_t
#endif
implicit none

integer, parameter :: input_layer = 0
Expand All @@ -24,7 +27,13 @@

module procedure construct_from_inference_engine

#ifndef _CRAYFTN
associate(exchange => inference_engine%to_exchange())
#else
use inference_engine_m_, only: exchange_t
type(exchange_t) exchange
exchange = inference_engine%to_exchange()
#endif
trainable_engine%input_range_ = exchange%input_range_
trainable_engine%output_range_ = exchange%output_range_
trainable_engine%metadata_ = exchange%metadata_
Expand All @@ -38,7 +47,9 @@
error stop &
"trainable_engine_s(from_inference_engine): activation strategy must be a differentiable_activation_stragegy_t"
end select
#ifndef _CRAYFTN
end associate
#endif

end procedure

Expand Down Expand Up @@ -70,9 +81,19 @@

allocate(a(maxval(n), input_layer:output_layer)) ! Activations

#ifndef _CRAYFTN
associate(normalized_inputs => self%input_range_%map_to_training_range(inputs))
#else
block
type(tensor_t) normalized_inputs
normalized_inputs = self%input_range_%map_to_training_range(inputs)
#endif
a(1:n(input_layer),input_layer) = normalized_inputs%values()
#ifndef _CRAYFTN
end associate
#else
end block
#endif

feed_forward: &
do l = 1,output_layer
Expand Down Expand Up @@ -134,12 +155,22 @@

if (present(cost)) cost(batch) = 0.
dcdw = 0.; dcdb = 0.


#ifndef _CRAYFTN
associate(input_output_pairs => mini_batches_arr(batch)%input_output_pairs())
#else
block
type(input_output_pair_t), allocatable :: input_output_pairs(:)
input_output_pairs = mini_batches_arr(batch)%input_output_pairs()
#endif
inputs = input_output_pairs%inputs()
expected_outputs = input_output_pairs%expected_outputs()
mini_batch_size = size(input_output_pairs)
#ifndef _CRAYFTN
end associate
#else
end block
#endif

iterate_through_batch: &
do pair = 1, mini_batch_size
Expand Down
Loading
Loading