From 88ac5f09c57ff9b682be9640cee5221394848a31 Mon Sep 17 00:00:00 2001
From: Damian Rouson <rouson@lbl.gov>
Date: Sat, 20 Jul 2024 17:55:42 -0700
Subject: [PATCH 1/3] fix(single-source):mv script outside fpm's purview

---
 example/single-file/single-file-compile.sh    |  79 -----------
 scripts/create-single-source-file-programs.sh | 128 ++++++++++++++++++
 2 files changed, 128 insertions(+), 79 deletions(-)
 delete mode 100755 example/single-file/single-file-compile.sh
 create mode 100755 scripts/create-single-source-file-programs.sh

diff --git a/example/single-file/single-file-compile.sh b/example/single-file/single-file-compile.sh
deleted file mode 100755
index 71f610caa..000000000
--- a/example/single-file/single-file-compile.sh
+++ /dev/null
@@ -1,79 +0,0 @@
-#!/bin/bash
-
-cat \
-../../build/dependencies/assert/src/assert/characterizable_m.f90 \
-../../build/dependencies/assert/src/assert/intrinsic_array_m.F90 \
-../../build/dependencies/assert/src/assert/assert_subroutine_m.F90 \
-../../build/dependencies/assert/src/assert/intrinsic_array_s.F90 \
-../../build/dependencies/assert/src/assert/assert_subroutine_s.F90 \
-../../build/dependencies/assert/src/assert_m.f90 \
-> single-file.F90
-
-cat \
-../../build/dependencies/julienne/src/julienne/julienne_bin_m.f90 \
-../../build/dependencies/julienne/src/julienne/julienne_command_line_m.f90 \
-../../build/dependencies/julienne/src/julienne/julienne_formats_m.F90 \
-../../build/dependencies/julienne/src/julienne/julienne_user_defined_collectives_m.f90 \
-../../build/dependencies/julienne/src/julienne/julienne_string_m.f90 \
-../../build/dependencies/julienne/src/julienne/julienne_file_m.f90 \
-../../build/dependencies/julienne/src/julienne/julienne_test_description_m.f90 \
-../../build/dependencies/julienne/src/julienne/julienne_test_result_m.f90 \
-../../build/dependencies/julienne/src/julienne/julienne_test_m.f90 \
-../../build/dependencies/julienne/src/julienne/julienne_vector_test_description_m.f90 \
-../../build/dependencies/julienne/src/julienne_m.f90 \
-../../build/dependencies/julienne/src/julienne/julienne_string_s.f90 \
-../../build/dependencies/julienne/src/julienne/julienne_bin_s.f90 \
-../../build/dependencies/julienne/src/julienne/julienne_command_line_s.f90 \
-../../build/dependencies/julienne/src/julienne/julienne_file_s.f90 \
-../../build/dependencies/julienne/src/julienne/julienne_formats_s.F90 \
-../../build/dependencies/julienne/src/julienne/julienne_test_description_s.f90 \
-../../build/dependencies/julienne/src/julienne/julienne_test_result_s.F90 \
-../../build/dependencies/julienne/src/julienne/julienne_test_s.F90 \
-../../build/dependencies/julienne/src/julienne/julienne_user_defined_collectives_s.F90 \
-../../build/dependencies/julienne/src/julienne/julienne_vector_test_description_s.f90 \
->> single-file.F90
-
-cat \
-../../src/inference_engine/kind_parameters_m.f90 \
-../../src/inference_engine/activation_strategy_m.f90 \
-../../src/inference_engine/differentiable_activation_strategy_m.f90 \
-../../src/inference_engine/gelu_m.f90 \
-../../src/inference_engine/relu_m.f90 \
-../../src/inference_engine/sigmoid_m.f90 \
-../../src/inference_engine/step_m.f90 \
-../../src/inference_engine/swish_m.f90 \
-../../src/inference_engine/training_configuration_m.f90 \
-../../src/inference_engine/network_configuration_m.f90 \
-../../src/inference_engine/hyperparameters_m.f90 \
-../../src/inference_engine/input_output_pair_m.f90 \
-../../src/inference_engine/metadata_s.f90 \
-../../src/inference_engine/neuron_m.f90 \
-../../src/inference_engine/layer_m.f90 \
-../../src/inference_engine/metadata_m.f90 \
-../../src/inference_engine/mini_batch_m.f90 \
-../../src/inference_engine/tensor_m.f90 \
-../../src/inference_engine/tensor_range_m.f90 \
-../../src/inference_engine/ubounds_m.f90 \
-../../src/inference_engine/inference_engine_m_.f90 \
-../../src/inference_engine/trainable_engine_m.F90 \
-../../src/inference_engine/gelu_s.f90 \
-../../src/inference_engine/hyperparameters_s.f90 \
-../../src/inference_engine/inference_engine_s.F90 \
-../../src/inference_engine/input_output_pair_s.f90 \
-../../src/inference_engine/layer_s.f90 \
-../../src/inference_engine/mini_batch_s.f90 \
-../../src/inference_engine/network_configuration_s.F90 \
-../../src/inference_engine/neuron_s.f90 \
-../../src/inference_engine/relu_s.f90 \
-../../src/inference_engine/sigmoid_s.f90 \
-../../src/inference_engine/step_s.f90 \
-../../src/inference_engine/swish_s.f90 \
-../../src/inference_engine/tensor_range_s.f90 \
-../../src/inference_engine/tensor_s.f90 \
-../../src/inference_engine/trainable_engine_s.F90 \
-../../src/inference_engine/training_configuration_s.F90 \
-../../src/inference_engine_m.f90 \
->> single-file.F90
-
-cat ../concurrent-inferences.f90 >> single-file.F90
-flang-new -mmlir -allow-assumed-rank single-file.F90 
diff --git a/scripts/create-single-source-file-programs.sh b/scripts/create-single-source-file-programs.sh
new file mode 100755
index 000000000..2505e65fe
--- /dev/null
+++ b/scripts/create-single-source-file-programs.sh
@@ -0,0 +1,128 @@
+#!/bin/bash
+# Copyright (c), The Regents of the University of California
+# Terms of use are as specified in LICENSE.txt
+# ----
+# This script concatenates the Inference-Engine software stack into
+# single-source-file programs.
+
+if [ -d ../build/dependencies/assert ] || [ -d ../build/dependencies/julienne ]; then
+  echo "Dependencies assert and julienne were found in ../build/dependencies as expected." 
+else
+  echo ""
+  echo ""
+  echo "-------------------- create-single-source-file.sh -----------------------"
+  echo "Dependencies assert and julienne were not found in ../build/dependencies." 
+  echo "Running fpm build to download the dependencies." 
+  echo "This unavoidably builds inference-engine too." 
+  echo "-------------------------------------------------------------------------"
+  echo ""
+  echo ""
+  fpm build
+fi
+
+echo "Concatenating assert, julienne, and inference-engine." 
+
+cat \
+  ../build/dependencies/assert/src/assert/characterizable_m.f90 \
+  ../build/dependencies/assert/src/assert/intrinsic_array_m.F90 \
+  ../build/dependencies/assert/src/assert/assert_subroutine_m.F90 \
+  ../build/dependencies/assert/src/assert/intrinsic_array_s.F90 \
+  ../build/dependencies/assert/src/assert/assert_subroutine_s.F90 \
+  ../build/dependencies/assert/src/assert_m.f90 \
+> single-file.F90
+
+cat \
+  ../build/dependencies/julienne/src/julienne/julienne_bin_m.f90 \
+  ../build/dependencies/julienne/src/julienne/julienne_command_line_m.f90 \
+  ../build/dependencies/julienne/src/julienne/julienne_formats_m.F90 \
+  ../build/dependencies/julienne/src/julienne/julienne_user_defined_collectives_m.f90 \
+  ../build/dependencies/julienne/src/julienne/julienne_string_m.f90 \
+  ../build/dependencies/julienne/src/julienne/julienne_file_m.f90 \
+  ../build/dependencies/julienne/src/julienne/julienne_test_result_m.f90 \
+  ../build/dependencies/julienne/src/julienne/julienne_test_description_m.f90 \
+  ../build/dependencies/julienne/src/julienne/julienne_test_m.f90 \
+  ../build/dependencies/julienne/src/julienne/julienne_vector_test_description_m.f90 \
+  ../build/dependencies/julienne/src/julienne/julienne_bin_s.f90 \
+  ../build/dependencies/julienne/src/julienne/julienne_command_line_s.f90 \
+  ../build/dependencies/julienne/src/julienne/julienne_formats_s.F90 \
+  ../build/dependencies/julienne/src/julienne/julienne_user_defined_collectives_s.F90 \
+  ../build/dependencies/julienne/src/julienne/julienne_string_s.f90 \
+  ../build/dependencies/julienne/src/julienne/julienne_file_s.f90 \
+  ../build/dependencies/julienne/src/julienne/julienne_test_result_s.F90 \
+  ../build/dependencies/julienne/src/julienne/julienne_test_description_s.f90 \
+  ../build/dependencies/julienne/src/julienne/julienne_test_s.F90 \
+  ../build/dependencies/julienne/src/julienne/julienne_vector_test_description_s.f90 \
+  ../build/dependencies/julienne/src/julienne_m.f90 \
+>> single-file.F90
+  
+cat \
+  ../src/inference_engine/kind_parameters_m.f90 \
+  ../src/inference_engine/activation_strategy_m.f90 \
+  ../src/inference_engine/differentiable_activation_strategy_m.f90 \
+  ../src/inference_engine/gelu_m.f90 \
+  ../src/inference_engine/relu_m.f90 \
+  ../src/inference_engine/sigmoid_m.f90 \
+  ../src/inference_engine/step_m.f90 \
+  ../src/inference_engine/swish_m.f90 \
+  ../src/inference_engine/hyperparameters_m.f90 \
+  ../src/inference_engine/network_configuration_m.f90 \
+  ../src/inference_engine/training_configuration_m.f90 \
+  ../src/inference_engine/neuron_m.f90 \
+  ../src/inference_engine/metadata_m.f90 \
+  ../src/inference_engine/tensor_m.f90 \
+  ../src/inference_engine/input_output_pair_m.f90 \
+  ../src/inference_engine/mini_batch_m.f90 \
+  ../src/inference_engine/tensor_range_m.f90 \
+  ../src/inference_engine/ubounds_m.f90 \
+  ../src/inference_engine/inference_engine_m_.f90 \
+  ../src/inference_engine/layer_m.f90 \
+  ../src/inference_engine/trainable_engine_m.F90 \
+  ../src/inference_engine_m.f90 \
+  ../src/inference_engine/gelu_s.f90 \
+  ../src/inference_engine/relu_s.f90 \
+  ../src/inference_engine/step_s.f90 \
+  ../src/inference_engine/sigmoid_s.f90 \
+  ../src/inference_engine/swish_s.f90 \
+  ../src/inference_engine/training_configuration_s.F90 \
+  ../src/inference_engine/network_configuration_s.F90 \
+  ../src/inference_engine/hyperparameters_s.f90 \
+  ../src/inference_engine/input_output_pair_s.f90 \
+  ../src/inference_engine/neuron_s.f90 \
+  ../src/inference_engine/layer_s.f90 \
+  ../src/inference_engine/metadata_s.f90 \
+  ../src/inference_engine/mini_batch_s.f90 \
+  ../src/inference_engine/tensor_s.f90 \
+  ../src/inference_engine/tensor_range_s.f90 \
+  ../src/inference_engine/inference_engine_s.F90 \
+  ../src/inference_engine/trainable_engine_s.F90 \
+>> single-file.F90
+
+echo ""
+echo ""
+echo "-------------------- create-single-source-file.sh -----------------------"
+
+echo "Creating concurrent-inferences.F90"
+cat single-file.F90 \
+  ../example/concurrent-inferences.f90 \
+> concurrent-inferences.F90
+
+if [ -f concurrent-inferences.F90 ]; then
+  echo "concurrent-inferences.F90 created."
+else
+  echo "concurrent-inferences.F90 wasn't created -- something went wrong"
+fi
+
+echo "Creating saturated-mixing-ratio.F90"
+cat single-file.F90 \
+  ../example/supporting-modules/saturated_mixing_ratio_m.f90 \
+  ../example/learn-saturated-mixing-ratio.f90 \
+> saturated-mixing-ratio.F90
+
+if [ -f saturated-mixing-ratio.F90 ]; then
+  echo "saturated-mixing-ratio.F90 created."
+else
+  echo "saturated-mixing-ratio.F90 wasn't created -- something went wrong"
+fi
+
+rm single-file.F90
+echo "-------------------------------------------------------------------------"

From 26f60821163d9f44cc26fb98f5e3d21e6e514c19 Mon Sep 17 00:00:00 2001
From: Damian Rouson <rouson@lbl.gov>
Date: Sat, 20 Jul 2024 19:11:08 -0700
Subject: [PATCH 2/3] feat(single-source): add example compile commands

---
 scripts/create-single-source-file-programs.sh | 8 ++++++++
 1 file changed, 8 insertions(+)

diff --git a/scripts/create-single-source-file-programs.sh b/scripts/create-single-source-file-programs.sh
index 2505e65fe..1da659e26 100755
--- a/scripts/create-single-source-file-programs.sh
+++ b/scripts/create-single-source-file-programs.sh
@@ -124,5 +124,13 @@ else
   echo "saturated-mixing-ratio.F90 wasn't created -- something went wrong"
 fi
 
+echo "Example compile commands:"
+echo ""
+echo 'gfortran -fcoarray=single -O3 -o saturated-mixing-ratio saturated-mixing-ratio.F90'
+echo 'flang-new -O3 -mmlir -allow-assumed-rank -o saturated-mixing-ratio saturated-mixing-ratio.F90'
+echo 'nagfor -fpp -O4 -o saturated-mixing-ratio saturated-mixing-ratio.F90'
+echo 'ifx -O3 -o saturated-mixing-ratio saturated-mixing-ratio.F90'
+
 rm single-file.F90
+
 echo "-------------------------------------------------------------------------"

From 33625f7a29c49528f1e6fb23f82fc3459f59ff32 Mon Sep 17 00:00:00 2001
From: Damian Rouson <rouson@lbl.gov>
Date: Sat, 20 Jul 2024 19:36:42 -0700
Subject: [PATCH 3/3] fix(single-source): improve diagnostic output

---
 scripts/create-single-source-file-programs.sh | 33 +++++++++----------
 1 file changed, 16 insertions(+), 17 deletions(-)

diff --git a/scripts/create-single-source-file-programs.sh b/scripts/create-single-source-file-programs.sh
index 1da659e26..67418fcad 100755
--- a/scripts/create-single-source-file-programs.sh
+++ b/scripts/create-single-source-file-programs.sh
@@ -5,23 +5,27 @@
 # This script concatenates the Inference-Engine software stack into
 # single-source-file programs.
 
-if [ -d ../build/dependencies/assert ] || [ -d ../build/dependencies/julienne ]; then
-  echo "Dependencies assert and julienne were found in ../build/dependencies as expected." 
-else
+echo ""
+echo "---------------------- create-single-source-file.sh ----------------------------"
+if [ ! -d ../build/dependencies/assert ] || [ ! -d ../build/dependencies/julienne ]; then
   echo ""
   echo ""
-  echo "-------------------- create-single-source-file.sh -----------------------"
   echo "Dependencies assert and julienne were not found in ../build/dependencies." 
   echo "Running fpm build to download the dependencies." 
   echo "This unavoidably builds inference-engine too." 
-  echo "-------------------------------------------------------------------------"
   echo ""
   echo ""
   fpm build
 fi
 
-echo "Concatenating assert, julienne, and inference-engine." 
+if [ -d ../build/dependencies/assert ] && [ -d ../build/dependencies/julienne ]; then
+  echo "------------- Dependencies assert and julienne are in ../build/dependencies ------------------"
+else
+  echo "Dependencies assert and julienne are not in ../build/dependencies. Something went wrong."
+  exit 1
+fi
 
+echo "Concatenating assert, julienne, and inference-engine." 
 cat \
   ../build/dependencies/assert/src/assert/characterizable_m.f90 \
   ../build/dependencies/assert/src/assert/intrinsic_array_m.F90 \
@@ -97,19 +101,14 @@ cat \
   ../src/inference_engine/trainable_engine_s.F90 \
 >> single-file.F90
 
-echo ""
-echo ""
-echo "-------------------- create-single-source-file.sh -----------------------"
-
 echo "Creating concurrent-inferences.F90"
 cat single-file.F90 \
   ../example/concurrent-inferences.f90 \
 > concurrent-inferences.F90
 
-if [ -f concurrent-inferences.F90 ]; then
-  echo "concurrent-inferences.F90 created."
-else
+if [ ! -f concurrent-inferences.F90 ]; then
   echo "concurrent-inferences.F90 wasn't created -- something went wrong"
+  exit 1
 fi
 
 echo "Creating saturated-mixing-ratio.F90"
@@ -118,14 +117,14 @@ cat single-file.F90 \
   ../example/learn-saturated-mixing-ratio.f90 \
 > saturated-mixing-ratio.F90
 
-if [ -f saturated-mixing-ratio.F90 ]; then
-  echo "saturated-mixing-ratio.F90 created."
-else
+if [ ! -f saturated-mixing-ratio.F90 ]; then
   echo "saturated-mixing-ratio.F90 wasn't created -- something went wrong"
+  exit 1
 fi
 
-echo "Example compile commands:"
+echo "saturated-mixing-ratio.F90 and concurrent-inferences.F90 created."
 echo ""
+echo "Example compile commands:"
 echo 'gfortran -fcoarray=single -O3 -o saturated-mixing-ratio saturated-mixing-ratio.F90'
 echo 'flang-new -O3 -mmlir -allow-assumed-rank -o saturated-mixing-ratio saturated-mixing-ratio.F90'
 echo 'nagfor -fpp -O4 -o saturated-mixing-ratio saturated-mixing-ratio.F90'
