Skip to content

Commit

Permalink
Ethash PoC9
Browse files Browse the repository at this point in the history
- Various changes to travis
  • Loading branch information
xcthulhu committed Mar 5, 2015
1 parent 4bc310e commit cf183ec
Show file tree
Hide file tree
Showing 5 changed files with 155 additions and 10 deletions.
1 change: 1 addition & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ before_install:
- sudo apt-get update -qq
- sudo apt-get install -qq wget cmake gcc bash libboost-test-dev nodejs python-pip
# Make sure we use the latest cmake
- sudo pip install virtualenv -q
- (cd /tmp && wget http://www.cmake.org/files/v3.1/cmake-3.1.3.tar.gz && tar zxf cmake-3.1.3.tar.gz)
- (cd /tmp/cmake-3.1.3 && cmake . && make && sudo make install) > /dev/null 2>&1

Expand Down
7 changes: 7 additions & 0 deletions Vagrantfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# -*- mode: ruby -*-
# vi: set ft=ruby :

Vagrant.configure(2) do |config|
config.vm.box = "Ubuntu 12.04"
config.vm.box_url = "https://cloud-images.ubuntu.com/vagrant/precise/current/precise-server-cloudimg-amd64-vagrant-disk1.box"
end
136 changes: 136 additions & 0 deletions cmake/modules/FindOpenCL.cmake
Original file line number Diff line number Diff line change
@@ -0,0 +1,136 @@
#.rst:
# FindOpenCL
# ----------
#
# Try to find OpenCL
#
# Once done this will define::
#
# OpenCL_FOUND - True if OpenCL was found
# OpenCL_INCLUDE_DIRS - include directories for OpenCL
# OpenCL_LIBRARIES - link against this library to use OpenCL
# OpenCL_VERSION_STRING - Highest supported OpenCL version (eg. 1.2)
# OpenCL_VERSION_MAJOR - The major version of the OpenCL implementation
# OpenCL_VERSION_MINOR - The minor version of the OpenCL implementation
#
# The module will also define two cache variables::
#
# OpenCL_INCLUDE_DIR - the OpenCL include directory
# OpenCL_LIBRARY - the path to the OpenCL library
#

#=============================================================================
# Copyright 2014 Matthaeus G. Chajdas
#
# Distributed under the OSI-approved BSD License (the "License");
# see accompanying file Copyright.txt for details.
#
# This software is distributed WITHOUT ANY WARRANTY; without even the
# implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
# See the License for more information.
#=============================================================================
# (To distribute this file outside of CMake, substitute the full
# License text for the above reference.)

function(_FIND_OPENCL_VERSION)
include(CheckSymbolExists)
include(CMakePushCheckState)
set(CMAKE_REQUIRED_QUIET ${OpenCL_FIND_QUIETLY})

CMAKE_PUSH_CHECK_STATE()
foreach(VERSION "2_0" "1_2" "1_1" "1_0")
set(CMAKE_REQUIRED_INCLUDES "${OpenCL_INCLUDE_DIR}")

if(APPLE)
CHECK_SYMBOL_EXISTS(
CL_VERSION_${VERSION}
"${OpenCL_INCLUDE_DIR}/OpenCL/cl.h"
OPENCL_VERSION_${VERSION})
else()
CHECK_SYMBOL_EXISTS(
CL_VERSION_${VERSION}
"${OpenCL_INCLUDE_DIR}/CL/cl.h"
OPENCL_VERSION_${VERSION})
endif()

if(OPENCL_VERSION_${VERSION})
string(REPLACE "_" "." VERSION "${VERSION}")
set(OpenCL_VERSION_STRING ${VERSION} PARENT_SCOPE)
string(REGEX MATCHALL "[0-9]+" version_components "${VERSION}")
list(GET version_components 0 major_version)
list(GET version_components 1 minor_version)
set(OpenCL_VERSION_MAJOR ${major_version} PARENT_SCOPE)
set(OpenCL_VERSION_MINOR ${minor_version} PARENT_SCOPE)
break()
endif()
endforeach()
CMAKE_POP_CHECK_STATE()
endfunction()

find_path(OpenCL_INCLUDE_DIR
NAMES
CL/cl.h OpenCL/cl.h
PATHS
ENV "PROGRAMFILES(X86)"
ENV AMDAPPSDKROOT
ENV INTELOCLSDKROOT
ENV NVSDKCOMPUTE_ROOT
ENV CUDA_PATH
ENV ATISTREAMSDKROOT
PATH_SUFFIXES
include
OpenCL/common/inc
"AMD APP/include")

_FIND_OPENCL_VERSION()

if(WIN32)
if(CMAKE_SIZEOF_VOID_P EQUAL 4)
find_library(OpenCL_LIBRARY
NAMES OpenCL
PATHS
ENV "PROGRAMFILES(X86)"
ENV AMDAPPSDKROOT
ENV INTELOCLSDKROOT
ENV CUDA_PATH
ENV NVSDKCOMPUTE_ROOT
ENV ATISTREAMSDKROOT
PATH_SUFFIXES
"AMD APP/lib/x86"
lib/x86
lib/Win32
OpenCL/common/lib/Win32)
elseif(CMAKE_SIZEOF_VOID_P EQUAL 8)
find_library(OpenCL_LIBRARY
NAMES OpenCL
PATHS
ENV "PROGRAMFILES(X86)"
ENV AMDAPPSDKROOT
ENV INTELOCLSDKROOT
ENV CUDA_PATH
ENV NVSDKCOMPUTE_ROOT
ENV ATISTREAMSDKROOT
PATH_SUFFIXES
"AMD APP/lib/x86_64"
lib/x86_64
lib/x64
OpenCL/common/lib/x64)
endif()
else()
find_library(OpenCL_LIBRARY
NAMES OpenCL)
endif()

set(OpenCL_LIBRARIES ${OpenCL_LIBRARY})
set(OpenCL_INCLUDE_DIRS ${OpenCL_INCLUDE_DIR})

include(${CMAKE_CURRENT_LIST_DIR}/FindPackageHandleStandardArgs.cmake)
find_package_handle_standard_args(
OpenCL
FOUND_VAR OpenCL_FOUND
REQUIRED_VARS OpenCL_LIBRARY OpenCL_INCLUDE_DIR
VERSION_VAR OpenCL_VERSION_STRING)

mark_as_advanced(
OpenCL_INCLUDE_DIR
OpenCL_LIBRARY)
15 changes: 8 additions & 7 deletions ethash.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package ethash

/*
#cgo CFLAGS: -std=gnu99 -Wall
#include "src/libethash/ethash.h"
#include "src/libethash/util.c"
#include "src/libethash/internal.c"
#include "src/libethash/sha3.c"
Expand All @@ -12,7 +11,6 @@ import "C"
import (
"bytes"
"encoding/binary"
"fmt"
"io/ioutil"
"log"
"math/big"
Expand Down Expand Up @@ -67,11 +65,15 @@ func parseNonce(nonce []byte) (uint64, error) {
const epochLength uint64 = 3000

func GetSeedBlockNum(blockNum uint64) uint64 {
var seedBlockNum uint64 = 0
if blockNum > epochLength {
seedBlockNum = ((blockNum - 1) / epochLength) * epochLength
// Seed Blocks update every 30000 blocks,
// but really we look at the block 60000 back.
// That way, we can have a back buffer of the DAG ready to go
// (if we want).
blockEpoch := blockNum/epochLength - 1
if blockEpoch <= 0 {
return 0
}
return seedBlockNum
return blockEpoch * epochLength
}

func makeParamsAndCache(chainManager pow.ChainManager, blockNum uint64) *ParamsAndCache {
Expand Down Expand Up @@ -277,7 +279,6 @@ func (pow *Ethash) Verify(block pow.Block) bool {
}

func (pow *Ethash) verify(hash []byte, mixDigest []byte, difficulty *big.Int, blockNum uint64, nonce uint64) bool {
fmt.Printf("%x\n%d\n%x\n%x\n", hash, nonce, mixDigest, difficulty.Bytes())
// First check: make sure header, mixDigest, nonce are correct without hitting the DAG
// This is to prevent DOS attacks
chash := (*C.uint8_t)(unsafe.Pointer(&hash[0]))
Expand Down
6 changes: 3 additions & 3 deletions test/python/test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@ while [ -h "$SOURCE" ]; do
done
TEST_DIR="$( cd -P "$( dirname "$SOURCE" )" && pwd )"

#rm -rf $TEST_DIR/python-virtual-env
#virtualenv --system-site-packages $TEST_DIR/python-virtual-env > /dev/null
rm -rf $TEST_DIR/python-virtual-env
virtualenv --system-site-packages $TEST_DIR/python-virtual-env > /dev/null
source $TEST_DIR/python-virtual-env/bin/activate
#pip install -r $TEST_DIR/requirements.txt > /dev/null
pip install -r $TEST_DIR/requirements.txt > /dev/null
pip install -e $TEST_DIR/../..
cd $TEST_DIR
nosetests --with-doctest -v

0 comments on commit cf183ec

Please sign in to comment.