[英]Unable to import python module (riesling)
我正在嘗試運行SAM(SPARC體系結構建模工具),並且在編譯后,當我使用“ run_sam.sh”腳本時,它需要python接口並給出錯誤:
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)
附加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
我對此很陌生,如果無法正確提出問題,請提前道歉。 請幫忙。
我看到以下文件:“ riesling_n1.i”,“ riesling_n1_wrap.cc”和“ riesling_n1.py”。 我認為最后一個是運行Makefile.swig之后創建的python文件。
2014年4月10日:
肖利,這是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
~
另外,riesling_n1.i代碼在這里:
/*
* ========== 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 */
我在Makefile中找到了以下幾行代碼以及其他代碼:
@/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)/.
而且,一旦我編譯Swig並獲得原始錯誤,_riesling_n1.so就會損壞。 當我用原始的(軟件包隨附的)替換_riesling_n1.so時,SAM起作用了。 這意味着在編譯過程中,它以某種方式弄亂了共享庫文件。
請建議(如果可能)找出導致此問題的原因。
根據SWIG 2.0文檔:
共享對象文件的名稱錯誤時,幾乎總是會導致此錯誤。 例如,如果您創建文件example.so而不是_example.so,則會出現此錯誤。 或者,如果模塊的名稱與%module指令提供的模塊名稱不一致,則可能會出現此錯誤。 仔細檢查接口以確保模塊名稱和共享庫文件名匹配。 造成此錯誤的另一個可能原因是,在創建擴展模塊時,忘記將SWIG生成的包裝器代碼與應用程序的其余部分鏈接。
因此,請檢查_riesling_n1.so
存在並可以由動態加載程序找到(即,它位於啟動py接口的文件夾中或LD_LIBRARY_PATH中)。 我在您發布的代碼中沒有看到任何.so Make規則,因此.so甚至都沒有建立( .py
文件的存在與此並不矛盾;該文件是由SWIG創建的)。 還要確保riesling_n1.i
中的%module
是riesling_n1
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.