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

Removing legacy python integration #473

Merged
merged 10 commits into from
Jan 3, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
18 changes: 12 additions & 6 deletions .github/actions/install/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -130,20 +130,26 @@ runs:
shell: bash
name: "Installing CUDA"
run: |
GPU="${{ inputs.cuda }}"
if test "$GPU" == "true"
VER="${{ inputs.cuda }}"
if test "$VER" == "true"
then
GPU="11.7"
VER="11.7"
fi
tools/install.sh ${{inputs.options}} cuda $GPU
CUDA_PATH=/usr/local/cuda-$GPU
tools/install.sh ${{inputs.options}} cuda $VER
CUDA_PATH=/usr/local/cuda-$VER
echo "$CUDA_PATH/bin" >>$GITHUB_PATH
echo "LD_LIBRARY_PATH=$CUDA_PATH/lib64:$LD_LIBRARY_PATH" >>$GITHUB_ENV
echo "CUDA_PATH=$CUDA_PATH" >>$GITHUB_OUTPUT
- if: inputs.hip != 'false'
name: "Installing ROCm/HIP"
shell: bash
run: tools/install.sh ${{inputs.options}} hip ${{ inputs.hip }}
run: |
VER="${{ inputs.hip }}"
if test "$VER" == "true"
then
VER="5.4.1"
fi
tools/install.sh ${{inputs.options}} hip $VER
- if: inputs.openmpi != 'false'
name: "Installing OpenMPI"
shell: bash
Expand Down
6 changes: 5 additions & 1 deletion .github/actions/test/action.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,13 @@ inputs:
model:
description: model to compile
default: 'd2q9'
tests:
description: what tests to run
default: ''

runs:
using: 'composite'
steps:
- shell: bash
name: Run tests
run: tools/tests.sh ${{ inputs.model }}
run: tools/tests.sh ${{ inputs.model }} ${{ inputs.tests }}
57 changes: 57 additions & 0 deletions .github/workflows/rinside.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
name: RInside

on: [ push, pull_request ]

jobs:
test:
runs-on: ubuntu-latest
strategy:
fail-fast: false
matrix:
model:
- d2q9
precision:
- float
- double
arch:
- cpu
- cuda
- hip
include:
- precision: "double"
arch: "cpu"
test: true
steps:
- name: Git checkout
uses: actions/checkout@v3
with:
submodules: ${{ matrix.test }}
- name: Install dependencies
uses: ./.github/actions/install
with:
r: true
rdep: true
openmpi: true
rinside: true
reticulate: ${{ matrix.test }}
cuda: ${{ matrix.arch == 'cuda' }}
hip: ${{ matrix.arch == 'hip' }}
- name: Configure
uses: ./.github/actions/configure
with:
gpu: ${{ matrix.arch == 'cuda' }}
hip: ${{ matrix.arch == 'hip' }}
cuda_arch: sm_60
rinside: true
paranoid: true
precision: ${{ matrix.precision }}
- name: Compile
uses: ./.github/actions/compile
with:
model: ${{ matrix.model }}
- if: matrix.test
name: Run tests
uses: ./.github/actions/test
with:
model: ${{ matrix.model }}
tests: rinside
76 changes: 1 addition & 75 deletions src/Geometry.cpp.Rt
Original file line number Diff line number Diff line change
@@ -1,8 +1,4 @@
#include "Consts.h"
#ifdef EMBEDED_PYTHON
#include <Python.h>
#define NPY_NO_DEPRECATED_API NPY_1_7_API_VERSION
#endif

<?R
library(gvector,quiet=TRUE,warn.conflicts=FALSE)
Expand Down Expand Up @@ -1065,77 +1061,7 @@ int Geometry::Draw(pugi::xml_node & node)
Dot(x, y, z);
}
}
} else if (strcmp(n.name(), "PythonInline") == 0) {
#ifdef EMBEDED_PYTHON

if (!Py_IsInitialized()) {
notice("Python Init");
Py_Initialize();
}
// Make sure the GIL has been created since we need to acquire it in our
// callback to safely call into the python application.

PyObject *pGlobal;
PyObject* pyModule, *pLocal, *pValue;

PyGILState_STATE state;
state = PyGILState_Ensure();

pyModule = PyImport_AddModule("__main__");
pLocal = PyModule_GetDict(pyModule);
pGlobal = PyModule_GetDict(pyModule);



pValue = PyRun_String( n.child_value(), Py_file_input, pGlobal, pLocal );
if (pValue == NULL){
error("Provided Python code is not executable or does not contain 'test' function");
}

PyObject* pFunc = PyObject_GetAttrString(pyModule, "test"); ;
// Py_INCREF(pFunc);
Py_DECREF(pValue);


if (pFunc && PyCallable_Check(pFunc)) {
PyObject* pArgs;
pArgs = PyTuple_New(3);

for (int x = reg.dx; x < reg.dx + reg.nx; x++)
for (int y = reg.dy; y < reg.dy + reg.ny; y++)
for (int z = reg.dz; z < reg.dz + reg.nz; z++) {

PyTuple_SetItem( pArgs, 0, PyFloat_FromDouble((x-reg.dx)/(real_t)reg.nx));
PyTuple_SetItem( pArgs, 1, PyFloat_FromDouble((y-reg.dy)/(real_t)reg.ny));
PyTuple_SetItem( pArgs, 2, PyFloat_FromDouble((z-reg.dz)/(real_t)reg.nz));

//Call my function, passing it the number four
pValue = PyObject_CallObject(pFunc, pArgs);

if ( PyLong_AsLong(pValue) == 1 ) {
Dot(x, y, z);
}

}
Py_DECREF(pArgs);
} else {
error("Provided Python code is not executable or does not contain 'test' function");
}


Py_DECREF(pValue);
// Py_XDECREF(pFunc);
// Py_DECREF(pGlobal);
// Py_DECREF(pLocal);
PyGILState_Release(state);
// Py_Finalize();

#else
error("You need to compile PYTHON support for this geometry element");
return -1;
#endif

} else if (strcmp(n.name(), "STL") == 0) {
} else if (strcmp(n.name(), "STL") == 0) {
debug1("Filling stl geometry with flag %d (%d)\n", fg, fg_mask);
DEBUG1(reg.print();)
if (loadSTL(reg, n))
Expand Down
Loading