Skip to content

Commit

Permalink
Windows compatibility fixes
Browse files Browse the repository at this point in the history
Changed block size from 24x24x1 to 32x16x1 to work on GTX 260
Add '.yml' to file name if not specified, for convenience
  • Loading branch information
Wainberg committed May 7, 2014
1 parent a971e91 commit d510fa4
Show file tree
Hide file tree
Showing 8 changed files with 248 additions and 368 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ Hebel implements stochastic gradient descent (SGD) with regular and Nesterov mom

## Compatibility

Currently, Hebel will only run on Linux and probably Mac OS X (not tested). Hebel currently won't run in Windows.
Currently, Hebel will run on Linux and Windows, and probably Mac OS X (not tested).

## Dependencies
- PyCUDA
Expand Down
6 changes: 3 additions & 3 deletions hebel/monitors.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ def __init__(self, experiment_name=None, save_model_path=None,
self.train_error = []
self.validation_error = []
self.avg_epoch_t = None
self._time = datetime.now().strftime('%Y-%m-%dT%H:%M:%S')
self._time = datetime.now().strftime('%Y-%m-%dT%H-%M-%S')

self.epochs = 0

Expand Down Expand Up @@ -77,7 +77,7 @@ def test_error(self, test_error):
def makedir(self):
experiment_dir_name = '_'.join((
self.experiment_name,
datetime.now().strftime('%Y-%m-%dT%H:%M:%S')))
datetime.now().strftime('%Y-%m-%dT%H-%M-%S')))

path = os.path.join(self.save_model_path,
experiment_dir_name)
Expand Down Expand Up @@ -168,7 +168,7 @@ def __init__(self, model=None):
self.train_error = []
self.validation_error = []
self.avg_epoch_t = None
self._time = datetime.now().strftime('%Y-%m-%dT%H:%M:%S')
self._time = datetime.now().strftime('%Y-%m-%dT%H-%M-%S')

def start_training(self):
self.start_time = datetime.now()
Expand Down
559 changes: 231 additions & 328 deletions hebel/pycuda_ops/cublas.py

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions hebel/pycuda_ops/cudadrv.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,8 @@
_libcuda_libname_list = ['libcuda.so', 'libcuda.so.3', 'libcuda.so.4']
elif sys.platform == 'darwin':
_libcuda_libname_list = ['libcuda.dylib']
elif sys.platform == 'Windows':
_libcuda_libname_list = ['cuda.lib']
elif sys.platform == 'win32':
_libcuda_libname_list = ['nvcuda.dll']
else:
raise RuntimeError('unsupported platform')

Expand Down
6 changes: 4 additions & 2 deletions hebel/pycuda_ops/cudart.py
Original file line number Diff line number Diff line change
Expand Up @@ -40,8 +40,10 @@
_libcudart_libname_list = ['libcudart.so', 'libcudart.so.3', 'libcudart.so.4']
elif sys.platform == 'darwin':
_libcudart_libname_list = ['libcudart.dylib']
elif sys.platform == 'Windows':
_libcudart_libname_list = ['cudart.lib']
elif sys.platform == 'win32':
_libcudart_libname_list = ['cudart64_60.dll', 'cudart32_60.dll',
'cudart64_55.dll', 'cudart32_55.dll',
'cudart64_50.dll', 'cudart32_50.dll']
else:
raise RuntimeError('unsupported platform')

Expand Down
3 changes: 2 additions & 1 deletion hebel/pycuda_ops/matrix.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ def init():
global vector_normalize_kernel

code = """
#include <stdint.h>
__global__ void addRowVecToMat(const float *mat,
const float *vec,
float *target,
Expand Down Expand Up @@ -139,7 +140,7 @@ def add_vec_to_mat(mat, vec, axis=None, inplace=False,

n, m = mat.shape

block = (24, 24, 1)
block = (32, 16, 1)
gridx = n // block[0] + 1 * (n % block[0] != 0)
gridy = m // block[1] + 1 * (m % block[1] != 0)
grid = (gridx, gridy, 1)
Expand Down
30 changes: 0 additions & 30 deletions hebel/pycuda_ops/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,33 +133,3 @@ def get_soname(filename):

# No SONAME found:
return ''

class DL_info(ctypes.Structure):
_fields_ = [('dli_fname', ctypes.c_char_p),
('dli_fbase', ctypes.c_void_p),
('dli_sname', ctypes.c_char_p),
('dli_saddr', ctypes.c_void_p)]
libdl = ctypes.cdll.LoadLibrary('libdl.so')
libdl.dladdr.restype = int
libdl.dladdr.argtypes = [ctypes.c_void_p,
ctypes.c_void_p]

def find_lib_path(func):
"""
Find full path of a shared library containing some function.
Parameter
---------
func : ctypes function pointer
Pointer to function to search for.
Returns
-------
path : str
Full path to library.
"""

dl_info = DL_info()
libdl.dladdr(func, ctypes.byref(dl_info))
return dl_info.dli_fname
6 changes: 5 additions & 1 deletion train_model.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@

# Copyright (C) 2013 Hannes Bretschneider

# This program is free software; you can redistribute it and/or modify
Expand All @@ -19,7 +20,7 @@
description = """ Run this script with a yaml configuration file as input.
E.g.:
python train_model.py examples/mnist_neural_net_deep.yaml
python train_model.py examples/mnist_neural_net_deep.yml
"""

Expand All @@ -30,6 +31,9 @@
parser.add_argument('config_file')
args = parser.parse_args()

if not args.config_file.endswith('.yml') and not args.config_file.endswith('.yaml'):
args.config_file = args.config_file + '.yml'

yaml_src = ''.join(open(args.config_file).readlines())

run_from_config(yaml_src)

0 comments on commit d510fa4

Please sign in to comment.