def install_cutt(root_folder): # Modified from: https://github.com/ap-hynninen/cutt url = "https://github.com/Jittor/cutt/archive/master.zip" filename = "cutt-master.zip" fullname = os.path.join(root_folder, filename) dirname = os.path.join(root_folder, filename.replace(".zip", "")) true_md5 = "a6f4f7f75310a69b131e21f1ebec768a" if os.path.exists(fullname): md5 = run_cmd('md5sum ' + fullname).split()[0] if md5 != true_md5: os.remove(fullname) shutil.rmtree(dirname) if not os.path.isfile(os.path.join(dirname, "bin", "cutt_test")): LOG.i("Downloading cutt...") download_url_to_local(url, filename, root_folder, true_md5) import zipfile zf = zipfile.ZipFile(fullname) try: zf.extractall(path=root_folder) except RuntimeError as e: print(e) raise zf.close() LOG.i("installing cutt...") run_cmd(f"make", cwd=dirname) return dirname
def safeunpickle(path): if path.startswith("jittorhub://"): path = path.replace( "jittorhub://", "https://cg.cs.tsinghua.edu.cn/jittor/assets/build/checkpoints/") if path.startswith("https:") or path.startswith("http:"): base = path.split("/")[-1] fname = os.path.join(compiler.ck_path, base) from jittor.utils.misc import download_url_to_local download_url_to_local(path, base, compiler.ck_path, None) path = fname if path.endswith(".pth"): try: dirty_fix_pytorch_runtime_error() import torch except: raise RuntimeError( "pytorch need to be installed when load pth format.") model_dict = torch.load(path, map_location=torch.device('cpu')) return model_dict with open(path, "rb") as f: s = f.read() if not s.endswith(b"HCAJSLHD"): return pickle.loads(s) checksum = s[-28:-8] s = s[:-28] if hashlib.sha1(s).digest() != checksum: raise ValueError("Pickle checksum does not match! path: " + path) return pickle.loads(s)
def install_nccl(root_folder): url = "https://github.com/NVIDIA/nccl/archive/v2.6.4-1.tar.gz" filename = "nccl.tgz" fullname = os.path.join(root_folder, filename) dirname = os.path.join(root_folder, "nccl-2.6.4-1") true_md5 = "38d7a9e98d95a99df0a4f1ad6fb50fa7" if os.path.exists(fullname): md5 = run_cmd('md5sum '+fullname).split()[0] if md5 != true_md5: os.remove(fullname) if os.path.isdir(dirname): shutil.rmtree(dirname) if not os.path.isfile(os.path.join(dirname, "build", "lib", "libnccl.so")): LOG.i("Downloading nccl...") download_url_to_local(url, filename, root_folder, true_md5) if core.get_device_count() == 0: return if not inside_mpi(): return import tarfile with tarfile.open(fullname, "r") as tar: tar.extractall(root_folder) LOG.i("installing nccl...") arch_flag = f" -arch={','.join(map(lambda x:'sm_'+str(x),flags.cuda_archs))} " run_cmd(f"make -j8 src.build CUDA_HOME='{cuda_home}' NVCC_GENCODE='{arch_flag}' ", cwd=dirname) return dirname
def install_nccl(root_folder): url = "https://github.com/NVIDIA/nccl/archive/v2.8.4-1.tar.gz" url = "https://codeload.github.com/NVIDIA/nccl/tar.gz/v2.8.4-1" filename = "nccl.tgz" fullname = os.path.join(root_folder, filename) dirname = os.path.join(root_folder, "nccl-2.8.4-1") true_md5 = "900666558c5bc43e0a5e84045b88a06f" if os.path.exists(fullname): md5 = run_cmd('md5sum '+fullname).split()[0] if md5 != true_md5: os.remove(fullname) if os.path.isdir(dirname): shutil.rmtree(dirname) if not os.path.isfile(os.path.join(dirname, "build", "lib", "libnccl.so")): LOG.i("Downloading nccl...") download_url_to_local(url, filename, root_folder, true_md5) if core.get_device_count() == 0: return if not inside_mpi(): return import tarfile with tarfile.open(fullname, "r") as tar: tar.extractall(root_folder) LOG.i("installing nccl...") arch_flag = "" if len(flags.cuda_archs): arch_flag = f" -arch=compute_{min(flags.cuda_archs)} " arch_flag += ''.join(map(lambda x:f' -code=sm_{x} ', flags.cuda_archs)) run_cmd(f"make -j8 src.build CUDA_HOME='{cuda_home}' NVCC_GENCODE='{arch_flag}' ", cwd=dirname) return dirname
def install_cutt(root_folder): # Modified from: https://github.com/ap-hynninen/cutt url = "https://codeload.github.com/Jittor/cutt/zip/v1.1" filename = "cutt-1.1.zip" fullname = os.path.join(root_folder, filename) dirname = os.path.join(root_folder, filename.replace(".zip","")) true_md5 = "7bb71cf7c49dbe57772539bf043778f7" if os.path.exists(fullname): md5 = run_cmd('md5sum '+fullname).split()[0] if md5 != true_md5: os.remove(fullname) shutil.rmtree(dirname) if not os.path.isfile(os.path.join(dirname, "bin", "cutt_test")): LOG.i("Downloading cutt...") download_url_to_local(url, filename, root_folder, true_md5) import zipfile zf = zipfile.ZipFile(fullname) try: zf.extractall(path=root_folder) except RuntimeError as e: print(e) raise zf.close() LOG.i("installing cutt...") arch_flag = "" if len(flags.cuda_archs): arch_flag = f" -arch=compute_{min(flags.cuda_archs)} " arch_flag += ''.join(map(lambda x:f' -code=sm_{x} ', flags.cuda_archs)) run_cmd(f"make NVCC_GENCODE='{arch_flag}' nvcc_path='{nvcc_path}'", cwd=dirname) return dirname
def download(self): import tarfile download_url_to_local(self.url, self.filename, self.root, self.tgz_md5) # extract file cwd = os.getcwd() tar = tarfile.open(os.path.join(self.root, self.filename), "r:gz") os.chdir(self.root) tar.extractall() tar.close() os.chdir(cwd)
def download_url(self): resources = [ ("http://yann.lecun.com/exdb/mnist/train-images-idx3-ubyte.gz", "f68b3c2dcbeaaa9fbdd348bbdeb94873"), ("http://yann.lecun.com/exdb/mnist/train-labels-idx1-ubyte.gz", "d53e105ee54ea40749a09fcbcd1e9432"), ("http://yann.lecun.com/exdb/mnist/t10k-images-idx3-ubyte.gz", "9fb629c4189551a2d022fa330f9573f3"), ("http://yann.lecun.com/exdb/mnist/t10k-labels-idx1-ubyte.gz", "ec29112dd5afa0611ce80d1b7f02629c") ] for url, md5 in resources: filename = url.rpartition('/')[2] download_url_to_local(url, filename, self.data_root, md5)
def install_mkl(root_folder): url = "https://github.com/intel/mkl-dnn/releases/download/v1.0.2/mkldnn_lnx_1.0.2_cpu_gomp.tgz" filename = "mkldnn_lnx_1.0.2_cpu_gomp.tgz" fullname = os.path.join(root_folder, filename) dirname = os.path.join(root_folder, filename.replace(".tgz","")) if not os.path.isfile(os.path.join(dirname, "examples", "test")): LOG.i("Downloading mkl...") download_url_to_local(url, filename, root_folder, "47187284ede27ad3bd64b5f0e7d5e730") import tarfile with tarfile.open(fullname, "r") as tar: tar.extractall(root_folder) assert 0 == os.system(f"cd {dirname}/examples && " f"{cc_path} -std=c++14 cpu_cnn_inference_f32.cpp -Ofast -lmkldnn -I ../include -L ../lib -o test && LD_LIBRARY_PATH=../lib/ ./test")
def install_cub(root_folder): url = "https://github.com/NVlabs/cub/archive/v1.8.0.tar.gz" filename = "cub-1.8.0.tgz" fullname = os.path.join(root_folder, filename) dirname = os.path.join(root_folder, filename.replace(".tgz","")) if not os.path.isfile(os.path.join(dirname, "examples", "test")): LOG.i("Downloading cub...") download_url_to_local(url, filename, root_folder, "9203ea2499b56782601fddf8a12e9b08") import tarfile with tarfile.open(fullname, "r") as tar: tar.extractall(root_folder) assert 0 == os.system(f"cd {dirname}/examples && " f"{nvcc_path} device/example_device_radix_sort.cu -O2 -I.. -o test") if core.get_device_count(): assert 0 == os.system(f"cd {dirname}/examples && ./test") return dirname
def download_url(self): ''' Download mnist data set function, this function will be called when download is True. ''' resources = [ ("https://storage.googleapis.com/cvdf-datasets/mnist/train-images-idx3-ubyte.gz", "f68b3c2dcbeaaa9fbdd348bbdeb94873"), ("https://storage.googleapis.com/cvdf-datasets/mnist/train-labels-idx1-ubyte.gz", "d53e105ee54ea40749a09fcbcd1e9432"), ("https://storage.googleapis.com/cvdf-datasets/mnist/t10k-images-idx3-ubyte.gz", "9fb629c4189551a2d022fa330f9573f3"), ("https://storage.googleapis.com/cvdf-datasets/mnist/t10k-labels-idx1-ubyte.gz", "ec29112dd5afa0611ce80d1b7f02629c") ] for url, md5 in resources: filename = url.rpartition('/')[2] download_url_to_local(url, filename, self.data_root, md5)
def safeunpickle(path): if path.startswith("jittorhub://"): path = path.replace( "jittorhub://", "https://cg.cs.tsinghua.edu.cn/jittor/assets/build/checkpoints/") if path.startswith("https:") or path.startswith("http:"): base = path.split("/")[-1] fname = os.path.join(compiler.ck_path, base) from jittor.utils.misc import download_url_to_local download_url_to_local(path, base, compiler.ck_path, None) path = fname with open(path, "rb") as f: s = f.read() if not s.endswith(b"HCAJSLHD"): return pickle.loads(s) checksum = s[-28:-8] s = s[:-28] if hashlib.sha1(s).digest() != checksum: raise ValueError("Pickle checksum does not match! path: " + path) return pickle.loads(s)
def install_cub(root_folder): url = "https://github.com/NVIDIA/cub/archive/1.11.0.tar.gz" url = "https://codeload.github.com/NVIDIA/cub/tar.gz/1.11.0" filename = "cub-1.11.0.tgz" md5 = "97196a885598e40592100e1caaf3d5ea" fullname = os.path.join(root_folder, filename) dirname = os.path.join(root_folder, filename.replace(".tgz","")) if not os.path.isfile(os.path.join(dirname, "examples", "test")): LOG.i("Downloading cub...") download_url_to_local(url, filename, root_folder, md5) import tarfile with tarfile.open(fullname, "r") as tar: tar.extractall(root_folder) assert 0 == os.system(f"cd {dirname}/examples && " f"{nvcc_path} device/example_device_radix_sort.cu -O2 -I.. -std=c++14 -o test") if core.get_device_count(): assert 0 == os.system(f"cd {dirname}/examples && ./test") return dirname
def install_mkl(root_folder): # origin url is # url = "https://github.com/intel/mkl-dnn/releases/download/v1.0.2/mkldnn_lnx_1.0.2_cpu_gomp.tgz" url = "https://cloud.tsinghua.edu.cn/f/da02bf62b55b4aa3b8ee/?dl=1" filename = "mkldnn_lnx_1.0.2_cpu_gomp.tgz" # newest version for oneDNN # url = "https://github.com/oneapi-src/oneDNN/releases/download/v2.2/dnnl_lnx_2.2.0_cpu_gomp.tgz" # filename = "dnnl_lnx_2.2.0_cpu_gomp.tgz" fullname = os.path.join(root_folder, filename) dirname = os.path.join(root_folder, filename.replace(".tgz","")) if not os.path.isfile(os.path.join(dirname, "examples", "test")): LOG.i("Downloading mkl...") download_url_to_local(url, filename, root_folder, "47187284ede27ad3bd64b5f0e7d5e730") # newest version for oneDNN # download_url_to_local(url, filename, root_folder, "35bbbdf550a9d8ad54db798e372000f6") import tarfile with tarfile.open(fullname, "r") as tar: tar.extractall(root_folder) assert 0 == os.system(f"cd {dirname}/examples && " f"{cc_path} -std=c++14 cpu_cnn_inference_f32.cpp -Ofast -lmkldnn -I ../include -L ../lib -o test && LD_LIBRARY_PATH=../lib/ ./test")