Browse Source

Miner fix.

Possible fix for VM (and remove gas from the interface).
cl-refactor
Gav Wood 10 years ago
parent
commit
cbdb46ea43
  1. 15
      libethash-cl/ethash_cl_miner.cpp
  2. 4
      libethcore/Ethash.cpp
  3. 4
      libethereum/KeyManager.cpp
  4. 6
      libevm/SmartVM.h
  5. 14
      libevm/VM.cpp
  6. 8
      libevm/VM.h
  7. 9
      libevm/VMFace.h

15
libethash-cl/ethash_cl_miner.cpp

@ -206,14 +206,15 @@ bool ethash_cl_miner::init(uint8_t const* _dag, uint64_t _dagSize, unsigned work
m_header = cl::Buffer(m_context, CL_MEM_READ_ONLY, 32);
// compute dag on CPU
{
try {
m_queue.enqueueWriteBuffer(m_dag, CL_TRUE, 0, _dagSize, _dag);
// if this throws then it's because we probably need to subdivide the dag uploads for compatibility
// void* dag_ptr = m_queue.enqueueMapBuffer(m_dag, true, m_opencl_1_1 ? CL_MAP_WRITE : CL_MAP_WRITE_INVALIDATE_REGION, 0, _dagSize);
// memcpying 1GB: horrible... really. horrible. but necessary since we can't mmap *and* gpumap.
// _fillDAG(dag_ptr);
// m_queue.enqueueUnmapMemObject(m_dag, dag_ptr);
}
catch (...)
{
// didn't work. shitty driver. try allocating in CPU RAM and manually memcpying it.
void* dag_ptr = m_queue.enqueueMapBuffer(m_dag, true, m_opencl_1_1 ? CL_MAP_WRITE : CL_MAP_WRITE_INVALIDATE_REGION, 0, _dagSize);
memcpy(dag_ptr, _dag, _dagSize);
m_queue.enqueueUnmapMemObject(m_dag, dag_ptr);
}
// create mining buffers

4
libethcore/Ethash.cpp

@ -333,9 +333,9 @@ void Ethash::GPUMiner::workLoop()
uint64_t upper64OfBoundary = (uint64_t)(u64)((u256)w.boundary >> 192);
m_miner->search(w.headerHash.data(), upper64OfBoundary, *m_hook);
}
catch (...)
catch (cl::Error const& _e)
{
cwarn << "Error GPU mining. GPU memory fragmentation?";
cwarn << "Error GPU mining: " << _e.what() << "(" << _e.err() << ")";
}
}

4
libethereum/KeyManager.cpp

@ -61,7 +61,11 @@ bool KeyManager::load(std::string const& _pass)
if (version == 1)
{
for (auto const& i: s[1])
{
m_keyInfo[m_addrLookup[(Address)i[0]] = (h128)i[1]] = KeyInfo((h256)i[2], (std::string)i[3]);
cdebug << toString((Address)i[0]) << toString((h128)i[1]) << toString((h256)i[2]) << (std::string)i[3];
}
for (auto const& i: s[2])
m_passwordInfo[(h256)i[0]] = (std::string)i[1];
m_password = (string)s[3];

6
libevm/SmartVM.h

@ -31,12 +31,16 @@ namespace eth
class SmartVM: public VMFace
{
public:
SmartVM(u256 _gas): VMFace(_gas) {}
SmartVM(u256 const& _gas): m_gas(_gas) {}
virtual bytesConstRef go(ExtVMFace& _ext, OnOpFunc const& _onOp = {}, uint64_t _steps = (uint64_t)-1) override final;
void reset(u256 const& _gas = 0) noexcept override { m_gas = _gas; }
u256 gas() const noexcept override { return (u256)m_gas; }
private:
std::unique_ptr<VMFace> m_selectedVM;
bigint m_gas;
};
}

14
libevm/VM.cpp

@ -25,9 +25,9 @@ using namespace std;
using namespace dev;
using namespace dev::eth;
void VM::reset(u256 _gas) noexcept
void VM::reset(u256 const& _gas) noexcept
{
VMFace::reset(_gas);
m_gas = _gas;
m_curPC = 0;
m_jumpDests.clear();
}
@ -206,7 +206,7 @@ bytesConstRef VM::go(ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _steps)
BOOST_THROW_EXCEPTION(OutOfGas());
}
m_gas = (u256)((bigint)m_gas - runGas);
m_gas -= runGas;
if (newTempSize > m_temp.size())
m_temp.resize((size_t)newTempSize);
@ -565,7 +565,7 @@ bytesConstRef VM::go(ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _steps)
m_stack.push_back(m_temp.size());
break;
case Instruction::GAS:
m_stack.push_back(m_gas);
m_stack.push_back((u256)m_gas);
break;
case Instruction::JUMPDEST:
break;
@ -614,7 +614,11 @@ bytesConstRef VM::go(ExtVMFace& _ext, OnOpFunc const& _onOp, uint64_t _steps)
m_stack.pop_back();
if (_ext.balance(_ext.myAddress) >= endowment && _ext.depth < 1024)
m_stack.push_back((u160)_ext.create(endowment, m_gas, bytesConstRef(m_temp.data() + initOff, initSize), _onOp));
{
u256 g(m_gas);
m_stack.push_back((u160)_ext.create(endowment, g, bytesConstRef(m_temp.data() + initOff, initSize), _onOp));
m_gas = g;
}
else
m_stack.push_back(0);
break;

8
libevm/VM.h

@ -52,8 +52,6 @@ inline u256 fromAddress(Address _a)
class VM: public VMFace
{
public:
virtual void reset(u256 _gas = 0) noexcept override final;
virtual bytesConstRef go(ExtVMFace& _ext, OnOpFunc const& _onOp = {}, uint64_t _steps = (uint64_t)-1) override final;
void require(u256 _n, u256 _d) { if (m_stack.size() < _n) { if (m_onFail) m_onFail(); BOOST_THROW_EXCEPTION(StackUnderflow() << RequirementError((bigint)_n, (bigint)m_stack.size())); } if (m_stack.size() - _n + _d > c_stackLimit) { if (m_onFail) m_onFail(); BOOST_THROW_EXCEPTION(OutOfStack() << RequirementError((bigint)(_d - _n), (bigint)m_stack.size())); } }
@ -64,17 +62,21 @@ public:
bytes const& memory() const { return m_temp; }
u256s const& stack() const { return m_stack; }
void reset(u256 const& _gas = 0) noexcept override;
u256 gas() const noexcept override { return (u256)m_gas; }
private:
friend class VMFactory;
/// Construct VM object.
explicit VM(u256 _gas): VMFace(_gas) {}
explicit VM(u256 _gas): m_gas(_gas) {}
u256 m_curPC = 0;
bytes m_temp;
u256s m_stack;
std::set<u256> m_jumpDests;
std::function<void()> m_onFail;
bigint m_gas = 0;
};
}

9
libevm/VMFace.h

@ -38,18 +38,15 @@ struct StackUnderflow: virtual VMException {};
class VMFace
{
public:
explicit VMFace(u256 _gas): m_gas(_gas) {}
VMFace() = default;
virtual ~VMFace() = default;
VMFace(VMFace const&) = delete;
VMFace& operator=(VMFace const&) = delete;
virtual void reset(u256 _gas = 0) noexcept { m_gas = _gas; }
u256 gas() const noexcept { return m_gas; }
virtual void reset(u256 const& _gas = 0) noexcept = 0;
virtual u256 gas() const noexcept = 0;
virtual bytesConstRef go(ExtVMFace& _ext, OnOpFunc const& _onOp = {}, uint64_t _steps = (uint64_t)-1) = 0;
protected:
u256 m_gas = 0;
};
}

Loading…
Cancel
Save