Showing posts with label python. Show all posts
Showing posts with label python. Show all posts

2020-05-27

Tensorflow Error : Failed to get convolution algorithm

Tensorflow Error
tensorflow.python.framework.errors_impl.UnknownError: Failed to get convolution algorithm. This is probably because cuDNN failed to initialize, so try looking to see if a warning log message was printed above.
Solution
  • shell
    export CUDA_VISIBLE_DEVICES=0
  • for tf 2
    import os
    
    os.environ['TF_FORCE_GPU_ALLOW_GROWTH'] = 'true'
  • for tensorflow-gpu v1.8
    from tensorflow.compat.v1 import ConfigProto
    from tensorflow.compat.v1 import InteractiveSession
    
    config = ConfigProto()
    config.gpu_options.allow_growth = True
    session = InteractiveSession(config=config)

2019-06-27

Language performance test

Lower value shows better performance

  • C
    #include <stdio.h>
    
    int fib(int n) {
        if(n == 1) return 0;
        if(n == 2) return 1;
        return fib(n - 2) + fib(n - 1);
    }
    
    int main() {
        int i = 0;
        for(i = 1; i <= 40; i++) {
            printf("%d %d\n", i, fib(i));
        }
        printf("\nC\n");
        return 0;
    }
    
  • Java
    public class Fib {
     
        public static int calc(int n) {
            if(n <= 1) return 0;
            if(n == 2) return 1;
            return Fib.calc(n - 2) + Fib.calc(n - 1);
        }
        public static void main(String[] args) {
            for(int i = 1; i <= 40; i++) {
                System.out.println(i + " " + Fib.calc(i));
            }
            System.out.println("\nJAVA");
        }
     
    }
    
  • JavaScript
    #!/usr/bin/env node
    
    let range = Array.from({length: 40}, (x, i) => i+1);
    let fib = n => n === 1 ? 0 : n === 2 ? 1 : fib(n - 2) + fib(n - 1);
    
    range.forEach( i => console.log(i, fib(i)) );
    console.log("\nJavaScript");
    
  • PHP
    #!/usr/bin/env php
    <?php
    function fib(int $n) {
        if ($n === 1) return 0;
        if ($n === 2) return 1;
        return fib($n - 2) + fib($n - 1);
    }
    
    foreach (range(1, 40) as $i) {
        echo $i, ' ', fib($i), PHP_EOL;
    }
    echo "\nPHP\n";
    
  • Python
    #!/usr/bin/env python
    
    def fib(n):
      if n == 1:
        return 0
      elif n == 2:
        return 1
      return fib(n - 2) + fib(n - 1)
    
    if __name__ == "__main__":
      for i in range(1, 40 + 1):
        print(i, fib(i))
      print("\nPYTHON")
    
  • Ruby
    #!/usr/bin/env ruby
    
    def fib(n)
      return 0 if n == 1
      return 1 if n == 2
      return fib(n - 2) + fib(n - 1)
    end
    
    (1..40).each do |i|
      puts "#{i.to_s} #{fib(i).to_s}"
    end
    puts "\nRUBY"
    

2019-06-26

PIP upgrade all, python package

$ for package in `pip list --outdated | cut -d ' ' -f 1`
> do
> pip install --upgrade $package
> done