Commit a41070a2 authored by Alessandro Mirone's avatar Alessandro Mirone

test python3 OK

added requirements

compila quasi su python3. Verificare python2

Cspace.c compila con python3

compila ancora su python2

compilazione OK

compila OK

adapted to nslino

testing nslinogpu

restrainint testnslinogpu

fixed again for nslinogpu

restrained to nslingpu for a first test with python3

adapted __future__ for python3

adattando a python3

fissato un paio di / per python3

ancora modifiche per python3

agginto fabio come requirement

ancora modif per python3

rimosso tabs

corretto per python3

ancora per python3

ancora per python3

ancora python3

ancora python3!

ancora python3

accorciato una stringa

ancora python3

problema con stringa

debug

debug

ancora!!

ancora

ancora!!!

ancora

ancora

ancora

ancora

ancora

bah

ancora

ancora??

ancora

ancora

ancora

ancora

OK

ancora

ouff

ouff

ouff

ouff

straouff

ouff

ouff

sembra funzionare

correzione per python2
parent 46b60426
test:
testnslino3:
stage: test
only:
- testnslino3
tags:
- nslino
script:
- echo 'current dir is '
- pwd
- unset PYTHONPATH
- export PATH=/usr/local/bin:/usr/bin:/bin:/opt/oar/utilities:/sbin:/usr/bin/X11:.::.
- unset LDFLAGS
- unset CPPFLAGS
- unset LD_LIBRARY_PATH
- rm -rf ~/software/virtualenv_chst_python3/
- virtualenv --python=python3 ~/software/virtualenv_chst_python3/
- source ~/software/virtualenv_chst_python3/bin/activate
- pip install setuptools --upgrade
- pip install pip --upgrade
- pip install numpy
- pip install -r requirements.txt
- python setup.py install
# - python run_tests.py -v --testcase nslino
- python run_tests.py -v --testcase nslinogpu
- deactivate
after_script:
- pwd
testnslino:
stage: test
only:
- testnslino
......@@ -19,7 +54,7 @@ test:
- python setup.py install --prefix=/tmp/chst_test
- export PYTHONPATH=/tmp/chst_test/lib/python2.7/site-packages
- export PATH=/tmp/chst_test/bin:$PATH
- python run_tests.py -v --testcase nslino
# - python run_tests.py -v --testcase nslino
- python run_tests.py -v --testcase nslinogpu
after_script:
......
This diff is collapsed.
......@@ -53,6 +53,8 @@
#include <dlfcn.h>
#include<emmintrin.h>
#include <dirent.h>
#include <sys/types.h>
#include <unistd.h>
......@@ -125,6 +127,34 @@ int nextpow2_padded(int v) {
}
void * getLibNameHandle( const char *dirname, const char *prefix) {
DIR *d;
struct dirent *dir;
void *lib_handle;
d = opendir(dirname);
char fname[2000];
char fname2[4000];
if (d) {
while ((dir = readdir(d)) != NULL) {
printf(" spulciando %s , %s \n",dir->d_name , prefix);
if( strstr( dir->d_name, prefix )!=NULL ) {
if( strncmp( dir->d_name, prefix, strlen( prefix) )==0 ) {
closedir(d);
memcpy( fname , dir->d_name, strlen( dir->d_name)+1 );
sprintf(fname2,"%s/%s" , dirname , fname );
lib_handle = dlopen(fname2, RTLD_LAZY);
return lib_handle;
}
}
}
closedir(d);
}
return NULL;
}
/**
* @brief gaussian_2d : compute a two dimensional (square) Gaussian kernel
* @param ksize : size : number of rows and columns of the kernel
......@@ -2139,13 +2169,16 @@ void CCspace_precalculations( CCspace * self, int ncpus ) {
if( self->gpu_is_apriori_usable) {
if(self->gpu_context==NULL && self->params.TRYGPU){
if (self->params.verbosity>0) printf(" MO SETTO PER GPU %d\n",self->params.TRYGPU);
void *lib_handle;
void *lib_handle=NULL;
// void* libw_handle;
{
char fname[2000];
sprintf(fname,"%s/%s" , self->params.nome_directory_distribution, "libgputomo.so");
lib_handle = dlopen(fname, RTLD_LAZY);
lib_handle = getLibNameHandle(self->params.nome_directory_distribution , "libgputomo" ) ;
// wavelets
// sprintf(fname,"%s/%s" , self->params.nome_directory_distribution, "libwavelets.so");
// printf(">>> %s\n", fname);
......@@ -2234,9 +2267,8 @@ void CCspace_precalculations( CCspace * self, int ncpus ) {
fnFreePinned = (FreePinned_Symbol) dlsym(lib_handle, "FreePinned");
{
char fname[2000];
sprintf(fname,"%s/%s" , self->params.nome_directory_distribution,"libprojection.so");
lib_handle = dlopen(fname, RTLD_LAZY);
lib_handle = getLibNameHandle( self->params.nome_directory_distribution , "libprojection" ) ;
}
if (lib_handle) {
......@@ -7010,9 +7042,9 @@ void Paganin(CCspace * self, float *buffer, float * RawptrA,
if(selfP->gpu_pag_context==NULL && self->params.TRYGPU){
void *lib_handle;
{
char fname[2000];
sprintf(fname,"%s/%s" , self->params.nome_directory_distribution,"libgputomo.so");
lib_handle = dlopen(fname, RTLD_LAZY);
lib_handle = getLibNameHandle( self->params.nome_directory_distribution , "libgputomo" ) ;
}
if (lib_handle) {
char *error;
......@@ -7418,9 +7450,10 @@ void Filter_CCD(CCspace * self, float * buffer, float * Rawptr,
if(selfP->gpu_med_context==NULL && self->params.TRYGPU){
void *lib_handle;
{
char fname[2000];
sprintf(fname,"%s/%s" , self->params.nome_directory_distribution,"libgputomo.so");
lib_handle = dlopen(fname, RTLD_LAZY);
lib_handle = getLibNameHandle( self->params.nome_directory_distribution , "libgputomo" ) ;
}
if (lib_handle) {
char *error;
......
......@@ -31,6 +31,11 @@
#############################################################################*/
#undef NDEBUG
#include"Python.h"
#include "py3c.h"
#include <stdlib.h>
#include <stdio.h>
#include <math.h>
......@@ -369,9 +374,15 @@ void initialize_LT_sparse_infos(PyObject * Oinfos, LT_infos* lt_infos
}
#if PY_MAJOR_VERSION >= 3
static PyObject *
Cspace_new( PyObject *self, PyObject *args, PyObject *kwds)
#else
static PyObject *
Cspace_new( PyObject *self, PyObject *args)
#endif
{
printf(" entered in Cspace_new \n");
......@@ -849,8 +860,8 @@ Cspace_new( PyObject *self, PyObject *args)
exit(1);
}
res->myCCspace->params.DOUBLEFFCORRECTION = NULL ;
} else if (PyString_Check(Otmp)) {
res->myCCspace->params.DOUBLEFFCORRECTION = PyString_AsString(Otmp);
} else if (PyStr_Check(Otmp)) {
res->myCCspace->params.DOUBLEFFCORRECTION = (char*) PyStr_AsString(Otmp);
} else {
printf("input error : DOUBLEFFCORRECTION must be zero ( no double ff ) or a string(filename) \n" );
exit(1);
......@@ -946,14 +957,14 @@ Cspace_configure_readings(PyObject *self_a, PyObject *args)
Otmp = cpyutils_get_pydic_Oval(Odic , "proj_reading_type") ;
assert(PyString_Check(Otmp));
if (strcmp( PyString_AsString(Otmp), "edf")==0) {
assert(PyStr_Check(Otmp));
if (strcmp( PyStr_AsString(Otmp), "edf")==0) {
self->myCCspace->reading_infos.proj_reading_type = (char*) "edf";
} else if (strcmp( PyString_AsString(Otmp), "h5")==0){
} else if (strcmp( PyStr_AsString(Otmp), "h5")==0){
self->myCCspace->reading_infos.proj_reading_type = (char*) "h5";
Otmp = cpyutils_get_pydic_Oval(Odic , "proj_h5_dsname") ;
assert(PyString_Check(Otmp));
self->myCCspace->reading_infos.proj_h5_dsname=PyString_AsString(Otmp) ;
assert(PyStr_Check(Otmp));
self->myCCspace->reading_infos.proj_h5_dsname= (char*) PyStr_AsString(Otmp) ;
} else {
onError("proj_reading_type not .h5 not edf" );
}
......@@ -963,14 +974,14 @@ Cspace_configure_readings(PyObject *self_a, PyObject *args)
if(self->myCCspace->params.CORRECT_FLATFIELD) {
Otmp = cpyutils_get_pydic_Oval(Odic , "ff_reading_type") ;
assert(PyString_Check(Otmp));
if (strcmp( PyString_AsString(Otmp), "edf")==0) {
assert(PyStr_Check(Otmp));
if (strcmp( PyStr_AsString(Otmp), "edf")==0) {
self->myCCspace->reading_infos.ff_reading_type = (char*) "edf";
} else if (strcmp( PyString_AsString(Otmp), "h5")==0){
} else if (strcmp( PyStr_AsString(Otmp), "h5")==0){
self->myCCspace->reading_infos.ff_reading_type = (char*) "h5";
Otmp = cpyutils_get_pydic_Oval(Odic , "ff_h5_dsname") ;
assert(PyString_Check(Otmp));
self->myCCspace->reading_infos.ff_h5_dsname=PyString_AsString(Otmp) ;
assert(PyStr_Check(Otmp));
self->myCCspace->reading_infos.ff_h5_dsname= (char*) PyStr_AsString(Otmp) ;
} else {
onError("ff_reading_type not .h5 not edf" );
}
......@@ -1215,9 +1226,9 @@ static PyMethodDef Cspace_methods[]={
/* {"close", (PyCFunction) Cspace_close, METH_VARARGS, NULL }, */
};
static struct memberlist Cspace_memberlist[]={
{ NULL }
};
/* static struct memberlist Cspace_memberlist[]={ */
/* { NULL } */
/* }; */
static PyMethodDef Cspace_functions[] = {
{"Cspace", Cspace_new, METH_VARARGS, NULL },
......@@ -1229,15 +1240,53 @@ Cspace_getattr(Cspace *self, char *attr)
{
PyObject *res;
#if PY_MAJOR_VERSION >= 3
res = PyObject_GenericGetAttr( (PyObject *) self, PyUnicode_FromString(attr)) ;
#else
res= Py_FindMethod(Cspace_methods, (PyObject*) self, attr);
#endif
if(NULL !=res)
return res;
else {
PyErr_Clear();
return PyMember_Get((char*) self,Cspace_memberlist, attr);
return Py_None;
/* PyErr_Clear(); */
/* return PyMember_Get((char*) self,Cspace_memberlist, attr); */
}
}
#if PY_MAJOR_VERSION >= 3
/* static PyTypeObject MyCspacetype = { */
/* PyObject_HEAD_INIT(NULL) */
/* "Cspace", */
/* sizeof(Cspace), */
/* 0, */
/* (destructor) Cspace_dealloc, */
/* 0, */
/* (getattrfunc) Cspace_getattr, */
/* }; */
static PyTypeObject MyCspacetype = {
PyVarObject_HEAD_INIT(NULL,0)
.tp_name = "Cspace.Cspace",
.tp_doc = "Cspace",
.tp_basicsize = sizeof(Cspace),
.tp_flags = Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE,
.tp_new = Cspace_new,
.tp_dealloc = (destructor) Cspace_dealloc,
.tp_methods = Cspace_methods
};
static struct PyModuleDef moduledef = {
PyModuleDef_HEAD_INIT, /* m_base */
"Cspace", /* m_name */
NULL, /* m_doc */
-1 // , /* m_size */
// Cspace_functions /* m_methods */
};
#else
static PyTypeObject MyCspacetype = {
PyObject_HEAD_INIT(&PyType_Type)
0,
......@@ -1250,25 +1299,54 @@ static PyTypeObject MyCspacetype = {
};
#endif
void initCspace(void)
#if PY_MAJOR_VERSION >= 3
#define INITERROR return NULL
PyObject * PyInit_Cspace(void)
#else
#define INITERROR return
void initCspace(void)
#endif
{
Cspacetype = MyCspacetype;
PyObject *m, *d;
#if PY_MAJOR_VERSION >= 3
if (PyType_Ready(&Cspacetype) < 0)
return NULL;
m = PyModule_Create(&moduledef);
Py_INCREF(&Cspacetype);
PyModule_AddObject(m, "Cspace", (PyObject *) &Cspacetype);
#else
m = Py_InitModule("Cspace", Cspace_functions);
if (m == NULL)
INITERROR;
d = PyModule_GetDict(m);
ErrorObject = Py_BuildValue("s","Cspace.error");
PyDict_SetItemString(d,"error", ErrorObject);
if(PyErr_Occurred())
Py_FatalError("can't initialize module Cspace");
#endif
#ifdef import_array
import_array();
#endif
#if PY_MAJOR_VERSION >= 3
return m;
#endif
}
......@@ -32,6 +32,9 @@
#undef NDEBUG
#include"Python.h"
#include <stdlib.h>
#include "py3c.h"
#define PY_ARRAY_UNIQUE_SYMBOL chst_ARRAY_API
#define NO_IMPORT_ARRAY
......@@ -50,7 +53,7 @@ PyObject * cpyutils_get_pydic_Oval(PyObject *Odict, const char *key ) {
exit(1);
}
dic_key = PyString_FromString(key);
dic_key = PyStr_FromString(key);
Oval = PyDict_GetItem(Odict, dic_key);
if( Oval ) {
Py_DECREF(dic_key);
......@@ -108,15 +111,16 @@ PyObject *cpyutils_getattribute(PyObject * obj ,const char * string ) {
char** cpyutils_getstringlist_from_list(PyObject *Otmp,int *listlenght) {
int i;
char ** stringlist,* strptr;
const char * strptr ;
char ** stringlist;
assert(PyList_Check(Otmp));
*listlenght = PyList_Size(Otmp);
stringlist = (char **) malloc( (*listlenght)*sizeof(char *));
stringlist = ( char **) malloc( (*listlenght)*sizeof(char *));
for(i=0; i<(*listlenght); i++) {
assert(PyString_Check(PyList_GetItem(Otmp,i) ));
strptr = PyString_AsString(PyList_GetItem(Otmp,i));
assert(PyStr_Check(PyList_GetItem(Otmp,i) ));
strptr = PyStr_AsString(PyList_GetItem(Otmp,i));
stringlist[i] = (char *) malloc( sizeof(char)*strlen(strptr )+1 );
memcpy( stringlist[i], strptr , strlen(strptr )+1);
}
......@@ -125,10 +129,11 @@ char** cpyutils_getstringlist_from_list(PyObject *Otmp,int *listlenght) {
char* cpyutils_getstring(PyObject *Otmp) {
char * string, *strptr;
char * string;
const char *strptr;
assert(PyString_Check(Otmp ));
strptr = PyString_AsString(Otmp);
assert(PyStr_Check(Otmp ));
strptr = PyStr_AsString(Otmp);
string= (char *) malloc( sizeof(char)*strlen(strptr )+1 );
memcpy( string, strptr , strlen(strptr )+1);
......
/*
The MIT License (MIT)
Copyright (c) 2015, Red Hat, Inc. and/or its affiliates
Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
*/
#ifndef _PY3COMPAT_H_
#define _PY3COMPAT_H_
#include <Python.h>
#include "py3c/comparison.h"
#include "py3c/compat.h"
#include "py3c/py3shims.h"
#endif
/* Copyright (c) 2011, Larry Hastings
* Copyright (c) 2015, py3c contributors
* Licensed under the MIT license; see py3c.h
*
* (Note: Relicensed from PSF: http://bugs.python.org/issue24937#msg250191 )
*/
#ifndef __CAPSULETHUNK_H
#define __CAPSULETHUNK_H
#if ( (PY_VERSION_HEX < 0x02070000) \
|| ((PY_VERSION_HEX >= 0x03000000) \
&& (PY_VERSION_HEX < 0x03010000)) )
#define __PyCapsule_GetField(capsule, field, error_value) \
( PyCapsule_CheckExact(capsule) \
? (((PyCObject *)capsule)->field) \
: (PyErr_SetString(PyExc_TypeError, "CObject required"), (error_value)) \
) \
#define __PyCapsule_SetField(capsule, field, value) \
( PyCapsule_CheckExact(capsule) \
? (((PyCObject *)capsule)->field = value), 0 \
: (PyErr_SetString(PyExc_TypeError, "CObject required"), 1) \
) \
#define PyCapsule_Type PyCObject_Type
#define PyCapsule_CheckExact(capsule) (PyCObject_Check(capsule))
#define PyCapsule_IsValid(capsule, name) (PyCObject_Check(capsule))
#define PyCapsule_New(pointer, name, destructor) \
(PyCObject_FromVoidPtr(pointer, (void (*)(void*)) (destructor)))
#define PyCapsule_GetPointer(capsule, name) \
(PyCObject_AsVoidPtr(capsule))
/* Don't call PyCObject_SetPointer here, it fails if there's a destructor */
#define PyCapsule_SetPointer(capsule, pointer) \
__PyCapsule_SetField(capsule, cobject, pointer)
#define PyCapsule_GetDestructor(capsule) \
__PyCapsule_GetField(capsule, destructor, (void (*)(void*)) NULL)
#define PyCapsule_SetDestructor(capsule, dtor) \
__PyCapsule_SetField(capsule, destructor, (void (*)(void*)) dtor)
/*
* Sorry, there's simply no place
* to store a Capsule "name" in a CObject.
*/
#define PyCapsule_GetName(capsule) NULL
static int
PyCapsule_SetName(PyObject *capsule, const char *unused)
{
unused = unused;
PyErr_SetString(PyExc_NotImplementedError,
"can't use PyCapsule_SetName with CObjects");
return 1;
}
#define PyCapsule_GetContext(capsule) \
__PyCapsule_GetField(capsule, desc, (void*) NULL)
#define PyCapsule_SetContext(capsule, context) \
__PyCapsule_SetField(capsule, desc, context)
static void *
PyCapsule_Import(const char *name, int no_block)
{
PyObject *object = NULL;
void *return_value = NULL;
char *trace;
size_t name_length = (strlen(name) + 1) * sizeof(char);
char *name_dup = (char *)PyMem_MALLOC(name_length);
if (!name_dup) {
return NULL;
}
memcpy(name_dup, name, name_length);
trace = name_dup;
while (trace) {
char *dot = strchr(trace, '.');
if (dot) {
*dot++ = '\0';
}
if (object == NULL) {
if (no_block) {
object = PyImport_ImportModuleNoBlock(trace);
} else {
object = PyImport_ImportModule(trace);
if (!object) {
PyErr_Format(PyExc_ImportError,
"PyCapsule_Import could not "
"import module \"%s\"", trace);
}
}
} else {
PyObject *object2 = PyObject_GetAttrString(object, trace);
Py_DECREF(object);
object = object2;
}
if (!object) {
goto EXIT;
}
trace = dot;
}
if (PyCObject_Check(object)) {
PyCObject *cobject = (PyCObject *)object;
return_value = cobject->cobject;
} else {
PyErr_Format(PyExc_AttributeError,
"PyCapsule_Import \"%s\" is not valid",
name);
}
EXIT:
Py_XDECREF(object);
if (name_dup) {
PyMem_FREE(name_dup);
}
return return_value;
}
#endif /* #if PY_VERSION_HEX < 0x02070000 */
#endif /* __CAPSULETHUNK_H */
/* Copyright (c) 2015, Red Hat, Inc. and/or its affiliates
* Licensed under the MIT license; see py3c.h
*/
#ifndef _PY3C_COMPARISON_H_
#define _PY3C_COMPARISON_H_
#include <Python.h>
/* Rich comparisons */
#ifndef Py_RETURN_NOTIMPLEMENTED
#define Py_RETURN_NOTIMPLEMENTED \
return Py_INCREF(Py_NotImplemented), Py_NotImplemented
#endif
#ifndef Py_UNREACHABLE
#define Py_UNREACHABLE() abort()
#endif
#ifndef Py_RETURN_RICHCOMPARE
#define Py_RETURN_RICHCOMPARE(val1, val2, op) \
do { \
switch (op) { \
case Py_EQ: if ((val1) == (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE; \
case Py_NE: if ((val1) != (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE; \
case Py_LT: if ((val1) < (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE; \
case Py_GT: if ((val1) > (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE; \
case Py_LE: if ((val1) <= (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE; \
case Py_GE: if ((val1) >= (val2)) Py_RETURN_TRUE; Py_RETURN_FALSE; \
default: \
Py_UNREACHABLE(); \
} \
} while (0)
#endif
#define PY3C_RICHCMP(val1, val2, op) \
((op) == Py_EQ) ? PyBool_FromLong((val1) == (val2)) : \
((op) == Py_NE) ? PyBool_FromLong((val1) != (val2)) : \
((op) == Py_LT) ? PyBool_FromLong((val1) < (val2)) : \
((op) == Py_GT) ? PyBool_FromLong((val1) > (val2)) : \
((op) == Py_LE) ? PyBool_FromLong((val1) <= (val2)) : \
((op) == Py_GE) ? PyBool_FromLong((val1) >= (val2)) : \
(Py_INCREF(Py_NotImplemented), Py_NotImplemented)
#endif
/* Copyright (c) 2015, Red Hat, Inc. and/or its affiliates
* Licensed under the MIT license; see py3c.h
*/
#ifndef _PY3C_COMPAT_H_
#define _PY3C_COMPAT_H_
#include <Python.h>