user3285014
user3285014

Reputation: 319

Unable to import python module (riesling)

I am trying to run the SAM (SPARC Architecture Modeling tool) and after compilation, when I use the "run_sam.sh" script, it calls for python interface and gives an error:

starting py interface...
UI: start py thread, tid = 5
stop: Traceback (most recent call last):
  File "lib/frontend/sam_n1.py", line 26, in ?
    import riesling_n1
  File "/scratch/sam-t1/lib/frontend/riesling_n1.py", line 4, in ?
    import _riesling_n1
ImportError: dynamic module does not define init function (init_riesling_n1)

Attaching the Makefile.swig:

 # ========== Copyright Header Begin ==========================================
     2  #
     3  # OpenSPARC T1 Processor File: Makefile.swig
     4  # Copyright (c) 2006 Sun Microsystems, Inc.  All Rights Reserved.
     5  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
     6  #
     7  # The above named program is free software; you can redistribute it and/or
     8  # modify it under the terms of the GNU General Public
     9  # License version 2 as published by the Free Software Foundation.
    10  #
    11  # The above named program is distributed in the hope that it will be
    12  # useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    14  # General Public License for more details.
    15  #
    16  # You should have received a copy of the GNU General Public
    17  # License along with this work; if not, write to the Free Software
    18  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
    19  #
    20  # ========== Copyright Header End ============================================
    21  RIESLING_ROOT           = ../..
    22
    23  include $(RIESLING_ROOT)/src/Makefile.moddefs
    24
    25  MODULE                  = swig
    26  DEPENDENT_MODULES       = $(MODULE) fw mmu asi strand core cpu system trap blaze register
    27
    28  NAMESPACE               = ""
    29
    30  CPPFLAGS                += -I$(DEVTOOLS)/shade/inc -I$(PYTHONINC)
    31
    32  include Makefile.$(PRODUCT)
    33  include $(RIESLING_ROOT)/src/Makefile.modrules
    34
    35  autoregs.i: AutoRegs.xml
    36          PYTHONPATH=$(PYTHONPATH) $(PYTHON) genregs ../../src AutoRegs.xml autoregs.i
    37
    38  riesling_$(PRODUCT)_wrap.cc: riesling_$(PRODUCT).i autoregs.i strand.i system.i fw.i conv.i
    39          $(SWIG) $(SWIG_FLAGS) -o $@ riesling_$(PRODUCT).i
    40
    41  riesling_$(PRODUCT)_blaze_wrap.cc: riesling_$(PRODUCT)_blaze.i riesling_$(PRODUCT).i autoregs.i strand.i system.i fw.i conv.i
    42          $(SWIG) $(SWIG_FLAGS) -o $@ riesling_$(PRODUCT)_blaze.i

I am very new to this and apologize in advance if not being able to ask the question properly. Please help.

I see the following files: "riesling_n1.i", "riesling_n1_wrap.cc" and "riesling_n1.py". I think the last one is the python file created after running the Makefile.swig.

April 10,2014:

Schollii, here is the Makefile.n1:

    1  # ========== Copyright Header Begin ==========================================
     2  #
     3  # OpenSPARC T1 Processor File: Makefile.n1
     4  # Copyright (c) 2006 Sun Microsystems, Inc.  All Rights Reserved.
     5  # DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
     6  #
     7  # The above named program is free software; you can redistribute it and/or
     8  # modify it under the terms of the GNU General Public
     9  # License version 2 as published by the Free Software Foundation.
    10  #
    11  # The above named program is distributed in the hope that it will be
    12  # useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
    13  # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    14  # General Public License for more details.
    15  #
    16  # You should have received a copy of the GNU General Public
    17  # License along with this work; if not, write to the Free Software
    18  # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
    19  #
    20  # ========== Copyright Header End ============================================
    21
    22  REGISTERED_XML_FILES.n1 =
    23
    24  XML_FILES.n1 =
    25
    26  REGISTERED_CCFILES.n1 =
    27
    28  CCFILES.n1 =\
    29                  riesling_$(PRODUCT)_wrap.cc
    30
~

Also, riesling_n1.i code is here:

/*
    * ========== Copyright Header Begin ==========================================
    * 
    * OpenSPARC T1 Processor File: riesling_n1.i
    * Copyright (c) 2006 Sun Microsystems, Inc.  All Rights Reserved.
    * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES.
    * 
    * The above named program is free software; you can redistribute it and/or
    * modify it under the terms of the GNU General Public
    * License version 2 as published by the Free Software Foundation.
    * 
    * The above named program is distributed in the hope that it will be 
    * useful, but WITHOUT ANY WARRANTY; without even the implied warranty of
    * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
    * General Public License for more details.
    * 
    * You should have received a copy of the GNU General Public
    * License along with this work; if not, write to the Free Software
    * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301, USA.
    * 
* ========== Copyright Header End ============================================
*/
%module riesling_n1

/*==========================================================================*\
 * NOTE: Some method signatures use uint64_t even though the
 * actual riesling method defines the type as uint32_t.  The
 * 8-byte type is used to keep python from sign extending unsigned
 * 4-byte values when they are converted to a python long types.  
 *==========================================================================*/

%{
typedef uint64_t VaddrT;
typedef uint64_t PaddrT;
typedef uint16_t ContextT;

#include "Ni/Ni_System.h"
//#include "Ni/Ni_CBInterface.h"
#include "Ni/Ni_ArchStateConf.h"
#include "Ni/Ni_Tlb.h"
#include "Ni/Ni_Tte.h"
%}

%ignore operator=;
%ignore operator<<;
/* print is a Python keyword, so we rename it here */
%rename (rsPrint) print;

#define RIESLING_REGISTER_CONSTRUCTOR( class_name, ...  ) class_name ( __VA_ARGS__ )
#define RIESLING_REGISTER_METHOD( handle, return_type, method_name, ...  ) return_type method_name ( __VA_ARGS__ )
#define RIESLING_REGISTER_CHILD( handle, type, var_name )\ type var_name
#define RIESLING_REGISTER_CHILD_PTR( handle, type, var_name )\ type var_name
#define RIESLING_CACHE_RV( handle, cacheName, size )

%include "fw.i"
%include "strand.i"
%include "cpu.i"
%include "system.i"
#include "autoregs.i"
%include "std_string.i"
%include "conv.i"

%inline %{
//   n1_system_base() is used when we already have created a N1_Cpu elsewhere
//   and we have a long value representing its pointer. n1_system_base() casts
//   it to a proper SWIG pointer 

Riesling::Ni_SystemBase* n1_system_base( uint64_t p )
{
  union { Riesling::Ni_SystemBase* sys; uint64_t ptr; } u;
  u.ptr = p;
  return u.sys;
}
%}


namespace Riesling {

/*--------------------------------------------------------------------------*/

/*-------------------------------------
class Ni_PerfCtlReg
{
  public:
    std::string toString();
    uint64_t    getNative();
    void        setNative(uint64_t);
};
-------------------------------------*/

/*-------------------------------------
class Ni_PicReg
{
  public:
    std::string toString();
    uint64_t    getNative();
    void        setNative(uint64_t);
};
-------------------------------------*/

/*-------------------------------------
class Ni_IsfsrReg
{
  public:
    std::string toString();
    uint64_t    getNative();
    void        setNative(uint64_t);
};
-------------------------------------*/

/*-------------------------------------
class Ni_DsfsrReg
{
  public:
    std::string toString();
    uint64_t    getNative();
    void        setNative(uint64_t);
};
-------------------------------------*/

/*-------------------------------------
class Ni_DsfarReg
{
  public:
    std::string toString();
    uint64_t    getNative();
    void        setNative(uint64_t);
};
-------------------------------------*/

/*--------------------------------------------------------------------------*/

class Ni_Tlb
{
  public:
    std::string toString();
    Riesling::TtePos insert(const Riesling::Ni_Tte &tte);
    Riesling::Ni_Tte* at(int);
    uint32_t getNLines();
    int next_valid_index(int i);
};

class Ni_Tte
{
public:
    Ni_Tte();
    std::string toString() const;
    Riesling::Ni_TteDataSun4u& data4u();
    void      context( uint16_t c );
    uint16_t  context() const;  
    void   pid( uint32_t p );
    uint32_t  pid() const;
    uint64_t vaddr() const;
    void   vaddr( uint64_t vaddr );
    uint32_t  r() const;
    void   r( uint32_t _r );
    uint64_t translate( VaddrT vaddr ) const;
    bool  tagMatch (  uint64_t va, uint16_t context ) const;
        bool  tagMatch (  uint64_t va, uint16_t context, uint32_t pid, uint32_t r ) const;
};

class Ni_TteDataSun4u
{
public:
    Ni_TteDataSun4u();

    uint64_t getNative() const;
    void setNative( uint64_t value );

    uint64_t getV( ) const;
    uint64_t getSZL( ) const;
    uint64_t getNFO( ) const;
    uint64_t getIE( ) const;
    uint64_t getSZH( ) const;
    uint64_t getDIAG7_3( ) const;
    uint64_t getPA( ) const;
    uint64_t getL( ) const;
    uint64_t getCP( ) const;
    uint64_t getCV( ) const;
    uint64_t getE( ) const;
    uint64_t getP( ) const;
    uint64_t getW( ) const;

    void setV( uint64_t value );
    void setSZL( uint64_t value );
    void setNFO( uint64_t value );
    void setIE( uint64_t value );
    void setSZH( uint64_t value );
    void setDIAG7_3( uint64_t value );
    void setPA( uint64_t value );
    void setL( uint64_t value );
    void setCP( uint64_t value );
    void setCV( uint64_t value );
    void setE( uint64_t value );
    void setP( uint64_t value );
    void setW( uint64_t value );        
};





class Ni_IDPartitionIdReg
{
  public:
    std::string toString();
    uint64_t    getNative();
    void        setNative(uint64_t);
};

class Sf_ContextReg
{
  public:
    std::string toString();
    uint64_t    getNative();
    void        setNative(uint64_t);
};

/*-------------------------------------
class Ni_TlbDataIn
{
  public:
    std::string toString();
    uint64_t    getNative();
    void        setNative(uint64_t);
};
-------------------------------------*/

/*-------------------------------------
class Ni_TlbDataAccess
{
  public:
    std::string toString();
    uint64_t    getNative();
    void        setNative(uint64_t);
};
-------------------------------------*/

class Sf_TagTargetReg
{
  public:
    std::string toString();
    uint64_t    getNative();
    void        setNative(uint64_t);
};

class Sf_TagAccessReg
{
  public:
    std::string toString();
    uint64_t    getNative();
    void        setNative(uint64_t);
};

/*-------------------------------------
class Ni_TsbSearch
{
  public:
    std::string toString();
    uint64_t    getNative();
    void        setNative(uint64_t);
};
-------------------------------------*/

/*-------------------------------------
class Ni_RealRange
{
  public:
    std::string toString();
    uint64_t    getNative();
    void        setNative(uint64_t);
};
-------------------------------------*/

/*-------------------------------------
class Ni_PhysOffset
{
  public:
    std::string toString();
    uint64_t    getNative();
    void        setNative(uint64_t);
};
-------------------------------------*/

/*-------------------------------------
class Ni_TsbConfig
{
  public:
    std::string toString();
    uint64_t    getNative();
    void        setNative(uint64_t);
};
-------------------------------------*/

/*-------------------------------------
class Ni_TsbPointer
{
  public:
    std::string toString();
    uint64_t    getNative();
    void        setNative(uint64_t);
};
-------------------------------------*/

/*-------------------------------------
class Ni_TimedTlb
{
  public:
    std::string toString();
};
-------------------------------------*/

class Ni_Mmu
{
  public:
    std::string toString();
    //int getContextSize();
    //int getTsbConfigSize();
    //Ni_IDPartitionIdReg* getPartitionIdPtr();
    //Sf_ContextReg* getPrimaryContextPtr(int i);
    //Sf_ContextReg* getSecondaryContextPtr(int i);
    //Ni_TlbDataIn* getItlbDataInPtr();
    //Ni_TlbDataAccess* getItlbDataAccessPtr();
    //Sf_TagTargetReg* getItagTargetPtr();
    //Sf_TagAccessReg* getItagAccessPtr();
    //Ni_IsfsrReg* getIsfsrPtr();
    //Ni_TlbDataIn* getDtlbDataInPtr();
    //Ni_TlbDataAccess* getDtlbDataAccessPtr();
    //Sf_TagTargetReg* getDtagTargetPtr();
    //Sf_TagAccessReg* getDtagAccessPtr();
    //Ni_DsfsrReg* getDsfsrPtr();
    //Ni_DsfarReg* getDsfarPtr();
    //Ni_TsbSearch* getTsbSearchPtr();
    //Ni_RealRange* getRealRangePtr(int i);
    //Ni_PhysOffset* getPhysOffsetPtr(int i);
    //Ni_TsbConfig* getZeroContextTsbConfigPtr(int i);
    //Ni_TsbConfig* getNonzeroContextTsbConfigPtr(int i);
    //Ni_TsbPointer* getItsbPointerPtr(int i);
    //Ni_TsbPointer* getDtsbPointerPtr(int i);
};

/*--------------------------------------------------------------------------*/

/*-------------------------------------
class CMP_CoreIdReg
{
  public:
    std::string toString();
    uint64_t    getNative();
    void        setNative(uint64_t);
};    
-------------------------------------*/

/*-------------------------------------
class CMP_CoreInterruptIdReg
{
  public:
    std::string toString();
    uint64_t    getNative();
    void        setNative(uint64_t);
};
-------------------------------------*/

/*--------------------------------------------------------------------------*/

class Hv_InstructionWord
{
  public:
    std::string toString() const;
    uint32_t getNative() const;
    uint64_t getPc() const;
    uint64_t getPpc() const;
};
class Ni_InstructionWord
{
  public:
    std::string toString() const;
    uint32_t getNative() const;
    uint64_t getPc() const;
    uint64_t getPpc() const;
};

class Ni_TstateEntry
{
  public:
    Ni_TstateEntry();
    std::string toString();
    uint64_t    getNative();
    void        setNative(uint64_t);
};

class Ni_Tstate
{
  public:
    std::string toString();
    Ni_TstateEntry getTstateEntry(uint32_t);
    void           setTstateEntry(uint32_t, const Ni_TstateEntry&);
};

class Ni_PstateReg
{
  public:
    std::string toString();
    uint64_t    getNative();
    void        setNative(uint64_t);
};

class Hv_HtstateEntry 
{
  public:
    Hv_HtstateEntry();
    std::string toString();
    uint64_t    getNative();
    void        setNative(uint64_t);
};

class Hv_Htstate
{
  public:
    std::string     toString();
    Hv_HtstateEntry getHtstateEntry(uint32_t);
    void            setHtstateEntry(uint32_t, const Hv_HtstateEntry&);
    int         getMaxTl();
};

class Vis2_GsrReg
{
  public:
    std::string toString();
    uint64_t    getNative();
    void        setNative(uint64_t);
};

class Hv_HpstateReg
{
  public:
    std::string toString();
    uint64_t    getNative();
    void        setNative(uint64_t);
};

class Hv_HtbaReg
{
  public:
    std::string toString();
    uint64_t    getNative();
    void        setNative(uint64_t);
};

class Ni_HverReg
{
  public:
    std::string toString();
    uint64_t    getNative();
    void        setNative(uint64_t);
};

class Hv_HintpReg
{
  public:
    std::string toString();
    uint64_t    getNative();
    void        setNative(uint64_t);
};

class Hv_HstickCompareReg
{
  public:
    std::string toString();
    uint64_t    getNative();
    void        setNative(uint64_t);
};

class Hv_GlobalLevelReg
{
  public:
    std::string toString();
    uint64_t    getNative();
    void        setNative(uint64_t);
};

class Hv_ScratchPad
{
  public:
    std::string toString();
    uint64_t    getNative();
    void        setNative(uint64_t);
};

class Ni_ArchState 
{
  public:

    std::string toString();

    uint64_t getPc();
    void     setPc(uint64_t);
    uint64_t getNpc();
    void     setNpc(uint64_t);

    RegisterFile*        getRegisterFilePtr();
    FloatRegisterFile*   getFloatRegisterFilePtr();
    Ni_Tstate*           getTstateRegPtr();
    Ni_PstateReg*    getPstateRegPtr();
    Hv_Htstate*      getHtstateRegPtr();
    Vis2_GsrReg*         getGsrRegPtr();
    Hv_HpstateReg*   getHpstateRegPtr();
    Hv_HtbaReg*      getHtbaRegPtr();
    Ni_HverReg*      getHverRegPtr();
    //Ni_PerfCtlReg*       getNiPcrRegPtr();
    //Ni_PicReg*           getNiPicRegPtr();
    Hv_HintpReg*     getHintpRegPtr();
    Hv_HstickCompareReg* getHstickCompareRegPtr();
    Hv_GlobalLevelReg*   getGlobalLevelRegPtr();
    Hv_ScratchPad*       getScratchPadPtr(int);
    V9_TickReg*          getStickRegPtr();
    Sf_SoftIntReg*       getSoftIntRegPtr();
    V9_TickCompareReg*   getTickCmprRegPtr();
    V9_TickCompareReg*   getStickCmprRegPtr();
    V9_CcrReg*           getCcrRegPtr();
    V9_YReg*             getYRegPtr();
    V9_FprsReg*          getFprsRegPtr();
    V9_FsrReg*           getFsrRegPtr();
    V9_TickReg*          getTickRegPtr();
    V9_TbaReg*           getTbaRegPtr();
    V9_PilReg*           getPilRegPtr();
    V9_AsiReg*           getAsiRegPtr();
    V9_Tpc*              getTpcRegPtr();
    V9_Tnpc*             getTnpcRegPtr();
    V9_WstateReg*        getWstateRegPtr();
    V9_TrapLevelReg*     getTrapLevelRegPtr();
    V9_VerReg*           getVerRegPtr();
    V9_TrapType*         getTrapTypeRegPtr();
    //CMP_CoreIdReg* getCmpCoreIdRegPtr();
    //CMP_CoreInterruptIdReg* getCmpCoreIntrIdRegPtr();
};

/*-------------------------------------
class Ni_WatchPointReg
{
  public:
    std::string toString();
    uint64_t    getNative();
    void        setNative(uint64_t);
};
-------------------------------------*/

/*-------------------------------------
class Ni_LsuControlReg
{
  public:
    std::string toString();
    uint64_t    getNative();
    void        setNative(uint64_t);
};
-------------------------------------*/

class Ni_Strand 
{
  public:
    %extend {
    uint_t get_max_tl()     { return Riesling::Ni_ArchStateConf::MAXTL; }
    uint_t get_max_ptl()    { return Riesling::Ni_ArchStateConf::MAXPTL; }
    uint_t get_max_gl()     { return Riesling::Ni_ArchStateConf::MAXGL; }
    uint_t get_max_pgl()    { return Riesling::Ni_ArchStateConf::MAXGL; } // used in done/retry instruction ... 
    }
    int         step();
    Ni_ArchState*   getArchStatePtr();
    Ni_InstructionWord* getLastInstrPtr();
    Ni_Mmu*         getMmuPtr();
    //Ni_WatchPointReg*     getWatchpointPtr();
    //Ni_LsuControlReg*     getLsuControlPtr();
    uint32_t        lastInstr();
    std::string     lastInstrToString();

    /* when a (uint32_t)iw has bit31=1, the python->C++ conversion complains,
       so have to use uint64_t here to fool it, what a pain */
    Ni_InstructionWord* RS_getInstrPtr(uint64_t);
    uint64_t        RS_translate(int, uint64_t);
    uint64_t        RS_access(uint64_t, uint64_t, int, int);
    uint64_t            RS_asiRead (int asi, uint64_t va, bool nse);
    void                RS_asiWrite(int asi, uint64_t va, uint64_t value, bool nse);
    std::string         RS_dumpTlb(int itlb, int valid);
};

/*--------------------------------------------------------------------------*/

class Ni_Core
{
  public:
    std::string        toString();
    uint_t             getNStrands() const;
    Ni_Strand*         getStrandPtr(uint_t);
    Ni_Tlb*     getdTlbPtr();
    Ni_Tlb*        getiTlbPtr();
};

/*--------------------------------------------------------------------------*/

class Ni_Cpu 
{
  public:
    std::string          toString();
    uint_t               getNCores() const;
    Ni_Core*             getCorePtr(uint_t);
    //CMP_CpuLevelCmpRegs* getCpuLevelCmpRegsPtr();
};



/*--------------------------------------------------------------------------*/

class Ni_System 
{
  public:
    Ni_System();
    std::string   toString();
    uint_t        getNCpus() const;
    Ni_Cpu*       getCpuPtr(uint_t);
    void          loadMemdatImage(const std::string&);
    SparseMemory* getRam();
    uint64_t      getThisPtr();
    BreakpointTable*    getBreakpointTablePtr();
};

/*--------------------------------------------------------------------------*/

class Ni_SystemBase 
{
  public:
    Ni_SystemBase();
    uint_t        getNCpus() const;
    Ni_Cpu*       getCpuPtr(uint_t);
    BreakpointTable*    getBreakpointTablePtr();
};

/*-------------------------------------
class Ni_CBInterface
{   
  public:   
    static void suspendCB();
    static void resumeCB();
};
-------------------------------------*/

}; /* namespace Riesling */

I figured in the Makefile, there are the following lines of code along with others:

@/bin/cp -fp ../$(LIB_PATH)/riesling_n1.py $(INSTALL)/frontend/.
    @/bin/cp -fp ../$(LIB_PATH)/libriesling_n1_vcpu.so $(INSTALL)/.
    @/bin/cp -fp ../$(LIB_PATH)/libriesling_n1_vcpu.so $(INSTALL)/libSUNW,UltraSPARC-T1.so
    @/bin/cp -fp ../$(LIB_PATH)/_riesling_n1.so $(INSTALL)/.

And, the _riesling_n1.so is getting corrupted once I compile the swig and thus getting the original error. When I replaced the _riesling_n1.so with the original one (the one which comes with the package), the SAM works. That means during compilation it is somehow messing up the Shared Object library files.

Please advise (if possible) to figure out what is causing this.

Upvotes: 0

Views: 104

Answers (1)

Oliver
Oliver

Reputation: 29581

According to the SWIG 2.0 docs:

This error is almost always caused when a bad name is given to the shared object file. For example, if you created a file example.so instead of _example.so you would get this error. Alternatively, this error could arise if the name of the module is inconsistent with the module name supplied with the %module directive. Double-check the interface to make sure the module name and the shared object filename match. Another possible cause of this error is forgetting to link the SWIG-generated wrapper code with the rest of your application when creating the extension module.

So check that _riesling_n1.so exists and is findable by the dynamic loader (i.e. it is in folder where you start py interface or in the LD_LIBRARY_PATH). I'm not seeing any .so Make rule in the code you posted so maybe the .so is not even getting built (the presence of .py file does not contradict this; that file is created by SWIG). Also ensure that the %module in riesling_n1.i is riesling_n1.

Upvotes: 1

Related Questions