|
|
|
@ -17,6 +17,7 @@ The context of mindspore, used to configure the current execution environment,
|
|
|
|
|
including execution mode, execution backend and other feature switches.
|
|
|
|
|
"""
|
|
|
|
|
import os
|
|
|
|
|
import time
|
|
|
|
|
import threading
|
|
|
|
|
from collections import namedtuple
|
|
|
|
|
from types import FunctionType
|
|
|
|
@ -55,12 +56,20 @@ def _make_directory(path):
|
|
|
|
|
os.makedirs(path)
|
|
|
|
|
real_path = path
|
|
|
|
|
except PermissionError as e:
|
|
|
|
|
logger.error(
|
|
|
|
|
f"No write permission on the directory `{path}, error = {e}")
|
|
|
|
|
logger.error(f"No write permission on the directory `{path}, error = {e}")
|
|
|
|
|
raise ValueError(f"No write permission on the directory `{path}`.")
|
|
|
|
|
return real_path
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def _get_print_file_name(file_name):
|
|
|
|
|
"""Add timestamp suffix to file name. Rename the file name: file_name + "." + time(seconds)."""
|
|
|
|
|
time_second = str(int(time.time()))
|
|
|
|
|
file_name = file_name + "." + time_second
|
|
|
|
|
if os.path.exists(file_name):
|
|
|
|
|
ValueError("This file {} already exists.".format(file_name))
|
|
|
|
|
return file_name
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class _ThreadLocalInfo(threading.local):
|
|
|
|
|
"""
|
|
|
|
|
Thread local Info used for store thread local attributes.
|
|
|
|
@ -381,8 +390,20 @@ class _Context:
|
|
|
|
|
return None
|
|
|
|
|
|
|
|
|
|
@print_file_path.setter
|
|
|
|
|
def print_file_path(self, file):
|
|
|
|
|
self._context_handle.set_print_file_path(file)
|
|
|
|
|
def print_file_path(self, file_path):
|
|
|
|
|
"""Add timestamp suffix to file name. Sets print file path."""
|
|
|
|
|
print_file_path = os.path.realpath(file_path)
|
|
|
|
|
if os.path.isdir(print_file_path):
|
|
|
|
|
raise IOError("Print_file_path should be file path, but got {}.".format(file_path))
|
|
|
|
|
|
|
|
|
|
if os.path.exists(print_file_path):
|
|
|
|
|
_path, _file_name = os.path.split(print_file_path)
|
|
|
|
|
path = _make_directory(_path)
|
|
|
|
|
file_name = _get_print_file_name(_file_name)
|
|
|
|
|
full_file_name = os.path.join(path, file_name)
|
|
|
|
|
else:
|
|
|
|
|
full_file_name = print_file_path
|
|
|
|
|
self._context_handle.set_print_file_path(full_file_name)
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
def check_input_format(x):
|
|
|
|
@ -575,7 +596,8 @@ def set_context(**kwargs):
|
|
|
|
|
max_device_memory (str): Sets the maximum memory available for device, currently only supported on GPU.
|
|
|
|
|
The format is "xxGB". Default: "1024GB".
|
|
|
|
|
print_file_path (str): The path of print data to save. If this parameter is set, print data is saved to
|
|
|
|
|
a file by default, and turn off printing to the screen.
|
|
|
|
|
a file by default, and turn off printing to the screen. If the file already exists, add a timestamp
|
|
|
|
|
suffix to the file.
|
|
|
|
|
enable_sparse (bool): Whether to enable sparse feature. Default: False.
|
|
|
|
|
|
|
|
|
|
Raises:
|
|
|
|
|