Skip to content

Commit

Permalink
enable cpu adam op on powerpc architectures (#1213)
Browse files Browse the repository at this point in the history
* enable cpu adam operation on powerpc

* fix formatting

Co-authored-by: Olatunji Ruwase <olruwase@microsoft.com>
Co-authored-by: Jeff Rasley <jerasley@microsoft.com>
  • Loading branch information
3 people authored Jul 12, 2021
1 parent 5652072 commit f65ff90
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
5 changes: 4 additions & 1 deletion csrc/includes/cpu_adam.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,13 @@
#pragma once

#if (__x86_64__ || __i386__)
#include <cpuid.h>
#include <x86intrin.h>
#endif

#include <cuda_fp16.h>
#include <cuda_runtime_api.h>
#include <stdio.h>
#include <x86intrin.h>
#include <cassert>
#include "context.h"
#include "cublas_v2.h"
Expand Down
18 changes: 17 additions & 1 deletion op_builder/cpu_adam.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,21 @@ def include_paths(self):
CUDA_INCLUDE = os.path.join(torch.utils.cpp_extension.CUDA_HOME, "include")
return ['csrc/includes', CUDA_INCLUDE]

def cpu_arch(self):
if not self.command_exists('lscpu'):
self.warning(
"CPUAdam attempted to query 'lscpu' to detect the CPU architecture. "
"However, 'lscpu' does not appear to exist on "
"your system, will fall back to use -march=native.")
return ''

result = subprocess.check_output('lscpu', shell=True)
result = result.decode('utf-8').strip().lower()
if 'ppc64le' in result:
# gcc does not provide -march on PowerPC, use -mcpu instead
return '-mcpu=native'
return '-march=native'

def simd_width(self):
if not self.command_exists('lscpu'):
self.warning(
Expand All @@ -49,6 +64,7 @@ def simd_width(self):
def cxx_args(self):
import torch
CUDA_LIB64 = os.path.join(torch.utils.cpp_extension.CUDA_HOME, "lib64")
CPU_ARCH = self.cpu_arch()
SIMD_WIDTH = self.simd_width()

return [
Expand All @@ -59,7 +75,7 @@ def cxx_args(self):
'-lcublas',
'-g',
'-Wno-reorder',
'-march=native',
CPU_ARCH,
'-fopenmp',
SIMD_WIDTH
]

0 comments on commit f65ff90

Please sign in to comment.